-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
103 lines (97 loc) · 3.68 KB
/
data.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import query
def getAverageScoreFromCode(team, year, code):
"""
Calculates a team's average score at event with code: <code> in <year>
"""
matches = query.getAllMatches(year,code)
teamkey = "frc"+str(team)
ans = 0
count = 0
for x in matches:
for y in x["alliances"]["blue"]["teams"]:
if y == teamkey:
ans+= x["alliances"]["blue"]["score"]
count+=1
for y in x["alliances"]["red"]["teams"]:
if y == teamkey:
ans+= x["alliances"]["red"]["score"]
count+=1
if count == 0:
return 0
return (0.0+ans)/(0.0+count)
def getAverageQualScoreFromCode(team, year, code):
"""
Calculates a team's qualification score at an event
"""
matches = query.getAllMatches(year,code)
teamkey = "frc"+str(team)
ans = 0
count = 0
for match in matches:
if match["comp_level"] == "qm" or match["comp_level"] == "ef":
for mteam in match["alliances"]["blue"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["blue"]["score"]
count += 1
for mteam in match["alliances"]["red"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["red"]["score"]
count += 1
if count == 0:
return 0
return float(ans)/float(count)
def getAverageQualScore(team, year):
teamkey = "frc"+str(team)
ans = 0
count = 0
for event in query.getTeamEventList(team, year):
matches = query.getAllMatches(year,event["event_code"])
for match in matches:
if match["comp_level"] == "qm" or match["comp_level"] == "ef":
for mteam in match["alliances"]["blue"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["blue"]["score"]
count += 1
for mteam in match["alliances"]["red"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["red"]["score"]
count += 1
return (float(ans))/(float(count))
def getAverageElimScoreFromCode(team, year, code):
"""
Calculates a team's average elimination score at an event
"""
matches = query.getAllMatches(year,code)
teamkey = "frc" + str(team)
ans = 0
count = 0
for match in matches:
if not (match["comp_level"] == "qm" or match["comp_level"] == "ef"):
for mteam in match["alliances"]["blue"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["blue"]["score"]
count += 1
for mteam in match["alliances"]["red"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["red"]["score"]
count+=1
if count==0:
return 0
return float(ans)/float(count)
def getAverageElimScore(team, year):
teamkey = "frc"+str(team)
ans = 0
count = 0
for event in query.getTeamEventList(team, year):
matches = query.getAllMatches(year,event["event_code"])
for match in matches:
if not (match["comp_level"] == "qm" or match["comp_level"] == "ef"):
for mteam in match["alliances"]["blue"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["blue"]["score"]
count += 1
for mteam in match["alliances"]["red"]["teams"]:
if mteam == teamkey:
ans += match["alliances"]["red"]["score"]
count += 1
return float(ans)/float(count)