-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.py
More file actions
96 lines (92 loc) · 3.64 KB
/
Copy pathhelpers.py
File metadata and controls
96 lines (92 loc) · 3.64 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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)
# gets the points for a competitor and a style, adding in points from above levels
def get_points(competitors, name, level, style, dance):
level_index = comp_res_references.level_list.index(level)
counted_levels = comp_res_references.level_list[level_index:]
# Novice points don't count for lower levels
if counted_levels[0] != "Novice" and "Novice" in counted_levels:
counted_levels.remove("Novice")
points = 0
for i, currLevel in enumerate(counted_levels):
if i == 0:
# Points in this level count normal
points += competitors[name].levels.__dict__[currLevel].__dict__[style].__dict__[dance]
elif i == 1:
# Points in the level above count double
points += 2 * competitors[name].levels.__dict__[currLevel].__dict__[style].__dict__[dance]
else:
# Any placement in two levels above counts as 7 points
points += 7 if competitors[name].levels.__dict__[currLevel].__dict__[style].__dict__[dance] > 0 else 0
return points