forked from rkrabek/ballroom-ycn-verifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
76 lines (73 loc) · 2.61 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import re
import comp_res_references
# finds level of event
def get_level(event):
level = ""
newcomer_try = re.findall("((Pre Bronze)|(Pre-Bronze))", event)
if len(newcomer_try) != 0:
level = "Newcomer"
else:
level_try = re.findall("((Newcomer)|(Bronze)|(Silver)|(Gold)|(Novice)|(Championship))", event)
if len(level_try) == 0:
level_try = re.findall("((Beginner)|(Intermediate)|(Advanced)|(Syllabus)|(Open)|(Pre-Champ))", event)
if len(level_try) == 0:
print "Level not found in" + event
level = event
else:
level = level_try[-1][0]
if level == "Pre-Champ":
level = "PreChamp"
elif level == "Beginner" or level == "Syllabus":
level = "Bronze"
elif level == "Intermediate":
level = "Silver"
elif level == "Advanced":
level = "Gold"
elif level == "Open":
level = "Championship"
else:
level = level_try[0][0]
return level
# finds dances of event
def get_dances_abbr(event):
start = event.rfind("(")
end = event.rfind(")")
dances_abbr = re.findall("([WTVFQCRSJPMB])", event[start:end])
return dances_abbr
# returns style and full name of dances
def get_style_dances(event):
dances_abbr = get_dances_abbr(event)
style = ""
style_try = re.findall("((Standard)|(Latin)|(Rhythm)|(Smooth))", event)
if len(style_try) == 0:
style_try = re.findall("((Intl\.|Intl|Am\.|Am|Ballroom|BALLROOM|LATIN))", event)
if len(style_try) == 0:
print "Style not found in" + event
style = event
else:
style = style_try[-1][0]
if style in ["Intl.", "Intl"]:
if any(x in dances_abbr for x in ['C','S','R','P','J']):
style = "Latin"
else:
style = "Standard"
elif style in ["Am.", "Am"]:
if any(x in dances_abbr for x in ['W','T','F','V']):
style = "Smooth"
else:
style = "Rhythm"
elif style in ["Ballroom", "BALLROOM"]:
style = "Standard"
elif style == "LATIN":
style = "Latin"
else:
style = style_try[0][0]
if style in comp_res_references.style_list:
try:
dances = [comp_res_references.dance_map[style][x] for x in dances_abbr]
except KeyError:
dances = []
print event + " has dances in it which do not match the detected style"
else:
dances = []
return (style, dances)