-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemaUtils.py
More file actions
115 lines (84 loc) · 5.11 KB
/
schemaUtils.py
File metadata and controls
115 lines (84 loc) · 5.11 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#Last Updated: 10/12/17
import DataModel
import pdb
class SchemaUtils(object):
'''docstring for SchemaUtils'''
def __init__(self, comp, calc):
super(SchemaUtils, self).__init__()
self.comp = comp
self.calc = calc
#Team utility functions
def getTeamForNumber(self, teamNumber):
try:
return [team for team in self.comp.teams if team.number == teamNumber][0]
except:
print(str(teamNumber), 'does not exist.')
def getMatchesForTeam(self, team):
return [m for m in self.comp.matches if team.number in m.redAllianceTeamNumbers + m.blueAllianceTeamNumbers]
def teamsWithCalculatedData(self):
return filter(lambda t: self.teamCalculatedDataHasValues(t.calculatedData), self.comp.teams)
def getCompletedMatchesForTeam(self,team):
return filter(self.matchIsCompleted, self.getMatchesForTeam(team))
def findTeamsWithMatchesCompleted(self):
return filter(lambda team: len(self.getCompletedMatchesForTeam(team)) > 0, self.comp.teams)
def teamCalculatedDataHasValues(self, calculatedData):
return calculatedData.avgHighShotsTele != None
def replaceWithAverageIfNecessary(self, team):
return team if team and self.teamCalculatedDataHasValues(team.calculatedData) and len(self.getCompletedMatchesForTeam(team)) > 0 else self.calc.averageTeam
#Match utility functions
def getMatchForNumber(self, matchNumber):
if not len([match for match in self.comp.matches if match.number == matchNumber]): print('Match', str(matchNumber), 'does not exist.')
return [match for match in self.comp.matches if match.number == matchNumber][0]
def teamsInMatch(self, match):
return map(self.getTeamForNumber, match.redAllianceTeamNumbers + match.blueAllianceTeamNumbers)
def teamInMatch(self, team, match):
return team in self.teamsInMatch(match)
def matchIsCompleted(self, match):
return len(self.getCompletedTIMDsForMatch(match)) == 6 and self.matchHasValuesSet(match)
def getCompletedMatchesInCompetition(self):
return filter(self.matchIsCompleted, self.comp.matches)
def teamsAreOnSameAllianceInMatch(self, team1, team2, match):
return team2 in self.getAllianceForTeamInMatch(team1, match)
def teamsForTeamNumbersOnAlliance(self, alliance):
return map(self.getTeamForNumber, alliance)
def getAllianceForMatch(self, match, allianceIsRed):
return map(self.getTeamForNumber, match.redAllianceTeamNumbers) if allianceIsRed else map(self.getTeamForNumber, match.blueAllianceTeamNumbers)
def getAllianceForTeamInMatch(self, team, match):
return self.getAllianceForMatch(match, self.getTeamAllianceIsRedInMatch(team, match))
def getFieldsForAllianceForMatch(self, allianceIsRed, match):
return (match.redScore, match.redDidReachFortyKilopascals, match.numRotorsSpinningRedAuto, match.numRotorsSpinningRedTele, match.foulPointsGainedRed) if allianceIsRed else (
match.blueScore, match.blueDidReachFortyKilopascals, match.numRotorsSpinningBlueAuto, match.numRotorsSpinningBlueTele, match.foulPointsGainedBlue)
def getTeamAllianceIsRedInMatch(self, team, match):
if team.number == -1 or team.number in match.redAllianceTeamNumbers: return True
elif team.number in match.blueAllianceTeamNumbers: return False
else:
raise ValueError(str(team.number) not in 'Q' + str(match.number))
#TIMD utility function
def getTIMDsForTeam(self, team):
return filter(lambda t: t.teamNumber == team.number, self.comp.TIMDs)
def getTIMDsForMatch(self, match):
return filter(lambda t: t.matchNumber == match.number, self.comp.TIMDs)
def getCompletedTIMDsForTeam(self, team):
return filter(self.timdIsCompleted, self.getTIMDsForTeam(team))
def getTIMDsForMatchForAllianceIsRed(self, match, allianceIsRed):
if allianceIsRed:
return filter(lambda t: t.teamNumber in match.redAllianceTeamNumbers, self.getTIMDsForMatch(match))
else:
return filter(lambda t: t.teamNumber in match.blueAllianceTeamNumbers, self.getTIMDsForMatch(match))
def getCompletedTIMDsForMatchForAllianceIsRed(self, match, allianceIsRed):
return filter(self.timdIsCompleted, self.getTIMDsForMatchForAllianceIsRed(match, allianceIsRed))
def getCompletedTIMDsForMatch(self, match):
return filter(self.timdIsCompleted, self.getTIMDsForMatch(match))
def getCompletedTIMDsInCompetition(self):
return filter(self.timdIsCompleted, self.comp.TIMDs)
def TIMCalculatedDataHasValues(self, calculatedData):
return calculatedData.liftoffAbility != None
def timdIsCompleted(self, timd):
return timd.rankSpeed != None and timd.numGroundGearIntakesTele != None
def matchHasValuesSet(self, match):
return match.redScore != None and match.blueScore != None
def retrieveCompletedTIMDsForTeam(self, team):
return self.getCompletedTIMDsForTeam(team)
def isSurrogate(self, team, match):
timd = self.getTIMDForTeamNumberAndMatchNumber(team.number, match.number)
return timd in surrogateTIMDs