-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamWatMu.py
252 lines (195 loc) · 8.85 KB
/
teamWatMu.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
## teamWatMu.py ################################################################
## object representing a team playing in waterloo ##############################
## intramural hockey ###########################################################
################################################################################
from team import *
from gameWatMu import *
from playerWatMu import *
import seasonParts
class watMuTeam(Team):
def __init__(self, leagueId, levelId, seasonId, teamId, debugInfo=False):
super(watMuTeam, self).__init__(leagueId, levelId, seasonId, teamId, debugInfo)
## call the super parent constructor, which does a few basic assignments
## of the IDs provided, then creates the Games list, and sets the load
## path for the csv. Finally, the base constructor kicks off
## loadTierI(...) automatically so the base data from the csv gets
## loaded
## Tier I load call ########################################################
def calculateTierIStats(self, debugInfo=False):
self.averageSOC = 0
for game in self.getSeasonGames():
self.averageSOC += game.getSOC()
if(debugInfo):
print "Total season games %i" % self.totalSeasonGames
self.averageSOC /= float(self.totalSeasonGames)
def loadSeasonGames(self, rows, debugInfo=False):
seasonGames = []
startOfSeasonRows = 2
endOfSeasonRows = startOfSeasonRows + self.totalSeasonGamesPlayed
seasonData = rows[startOfSeasonRows:(endOfSeasonRows)]
## slice out only the rows that contain games data and ignore games that
## have not yet been played
for game in seasonData:
seasonGames.append(watMuGame(str(game[0]), str(game[1]), str(game[2]), int(game[3]), int(game[4]), str(game[5]), str(game[6]), seasonParts.getGameSelectConditions("regularSeason"), self.getSeasonIndex()))
## set up each game as an object in memory
if(debugInfo):
print "seasonData: "
for row in seasonData:
print row
return seasonGames
def calculateSocValues(self, debugInfo=False):
self.averageSOC = 0.000
averageSOCGames = 0
for game in self.getSeasonGames():
try:
## try to add the SOC of a given game as a float
self.averageSOC += game.getSOC()
except ValueError:
## if this fails because game.getSOC() is actually a string
## (saying 'avg.') we tally one more SOC game in the schedule
averageSOCGames += 1
if(debugInfo):
print "Failed add due to ValueError"
print "Adding in an average SOC game due to actual value '%s'" % game.Layers[0][5]
SOC = float(self.averageSOC)/float(self.totalSeasonGamesPlayed-averageSOCGames)
## start off by getting our average for the games that had an SOC number
## available
if(averageSOCGames > 0):
## loop through the games again, if the value fails we overwrite it
## with the average of the games that were defined
for game in self.seasonGames:
if(debugInfo):
print game.Layers[0]
try:
game.getSOC()
except ValueError:
if(debugInfo):
print "Failed int() cast due to ValueError"
game.setSOC(SOC)
if(debugInfo):
print game.Layers[0]
def loadPlayoffGames(self, rows, debugInfo=False):
playoffGames = []
startOfPlayoffRows = 2+self.totalSeasonGames
endOfPlayoffRows = startOfPlayoffRows + self.totalPlayoffGamesPlayed
playoffData = rows[(startOfPlayoffRows):(endOfPlayoffRows)]
## slice out only the rows that contain games data and ignore games that
## have not yet been played
for game in playoffData:
playoffGames.append(watMuGame(str(game[0]), str(game[1]), str(game[2]), int(game[3]), int(game[4]), str(game[5]), str(game[6]), seasonParts.getGameSelectConditions("everything"), self.getSeasonIndex()))
## set up each game as an object in memory
if(debugInfo):
print "\nplayoffData: "
for row in playoffData:
print row
return playoffGames
def loadTierI(self, debugInfo=False):
##debugInfo = True
rows = self.getCsvRowsList()
self.teamName = rows[0][0]
self.seasonId = rows[0][1]
if(debugInfo):
print "Load call watMuTeam Tier I, team %s %s, Id %s" % (self.getTeamName(), self.seasonId, self.teamId)
self.seasonLength = int(rows[1][0])
## everything in the schedule, including playoff games
self.totalSeasonGames = int(rows[1][1])
## this is going to be the total length of the season schedule,
## including games that have not yet been played
self.totalSeasonGamesPlayed = int(rows[1][2])
## only the total of games in the season schedule that have been played
self.totalPlayoffGames = int(rows[1][3])
## total playoff games listed, including the TBDs
self.totalPlayoffGamesPlayed = int(rows[1][4])
## total playoff games actually played
if(debugInfo):
print "total season length %i games" % self.seasonLength
print "total season games in schedule %i" % self.totalSeasonGames
print "total season games played so far %i games" % self.totalSeasonGamesPlayed
print "total playoff games scheduled %i games" % self.totalPlayoffGames
print "total playoff games played so far %i games" % self.totalPlayoffGamesPlayed
self.seasonGames = self.loadSeasonGames(rows, debugInfo)
self.calculateSocValues(debugInfo)
self.playoffGames = self.loadPlayoffGames(rows, debugInfo)
## rosters...
self.Roster = rows[ (self.seasonLength + 3) ]
if(debugInfo):
print "\nRoster:"
for r in self.Roster:
print r
self.calculateTierIStats(debugInfo)
## Tier IV load call ######################################################
def loadTierIV(self, teamsList, seasonsList):
self.Players = []
## list containing player objects
for playerName in self.Roster:
self.Players.append(watMuPlayer(playerName, seasonsList))
## roll through the names of all the players on the roster and set
## up their player type object based on all of the season objects
## available in this dataset
def getSeasonAverageSOC(self):
return self.averageSOC
## the only value that needs to be defined here (instead of in the
## parent team type), since SOC only applies in waterloo intramurals
def getDescriptionHeader(self):
return "%s, %s (season %i) (%s)\nMade real playoffs = %r, Average SOC of %.3f" % (self.getTeamName(), self.getSeasonId(), self.getSeasonIndex(), self.levelId, self.realPlayoffs, self.getSeasonAverageSOC())
def getSeasonIndex(self):
return getSeasonIndexById(self.getSeasonId(), getSeasonIndexList('watMu'))
## given that we know this team is a watMu team, we can retrieve a list
## of season indexes, which allow us to pin down the correct order that
## seasons should go in by assigning an integer to each season
## its just a really complicated way of placing things in order right
def __repr__(self):
return "<%s>" % (self.getDescriptionString())
## this actually isnt a great choice for this, the desc string is super
## long
def qualifiedForPlayoffs(self):
## note that this specifically refers to whether the team played any
## playoff games, not whether they made the top "real" playoff bracket
## the only team thats going to miss on this one is a team that got
## DQed from the playoffs
if(self.totalPlayoffGames > 0):
return True
else:
return False
def getPlayoffOpponentTeamNames(self):
## helper function for the code that retrieves playoff brackets
output = []
for playoffGame in self.getPlayoffGames():
output.append(playoffGame.getOpponentName())
return output
def getPlayoffOpponentTeamSeeds(self, season):
## helper function for the code that retrieves playoff brackets
output = []
for playoffGame in self.getPlayoffGames():
opponentTeam = season.getTeamByTeamName(playoffGame.getOpponentName())
output.append(opponentTeam.getSeasonRank())
return output
def getFranchise(self, franchiseList):
output = 'None'
for franchise in franchiseList:
## loop through the list of franchises that are available, ie
## ['Seekers', 'SEEKZERS']
if(self.getTeamName().decode('utf-8') in franchise):
output = franchise[0].decode('utf-8')
## if the name of this current team was found in the possible
## names for the team as listed in the franchises csv
## set the franchise name for this team as the first
## (most appropriate) name for this teams franchise, ie
## SEEKZERS.getFranchise(franchiseList) -> 'Seekers'
break
return output
def getRecordString(self):
return "(%s-%s-%s)" % (self.getSeasonWinsTotal(), self.getSeasonLossTotal(), self.getSeasonTiesTotal())
## typical hockey stat used for decades
def calculatePlayoffSuccessRating(self):
if(self.realPlayoffs):
return self.getPlayoffWinPercentage()
else:
return 0.000
## if its not the top playoff bracket, it doesnt count as the 'real'
## playoffs
def madeRealPlayoffs(self):
return self.realPlayoffs
if(__name__ == "__main__"):
daDads = watMuTeam('watMu', 'beginner', 'fall2015', 12348, True)
## quick test using the one and only Mighty Dads fall 2015