-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
206 lines (160 loc) · 6.02 KB
/
game.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
## game.py #####################################################################
## object representing all of the data known about a given game ################
################################################################################
import seasonParts
from MJD import *
class Game(object):
def __init__(self, comparisonSelectConditions, seasonIndex):
self.Layers = []
## list of lists, with each list containing stats computed for that
## layer
self.layerCount = 0
self.comparisonSelectConditions = comparisonSelectConditions
self.seasonIndex = seasonIndex
def getOne(self):
## Just... dont worry about it ok?
return 1
def wasPlayedAtNeutralLocation(self):
if(self.wasHomeGame() == self.wasAwayGame()):
return True
else:
return False
def getComparisonConditions(self):
return self.comparisonSelectConditions
def addLayer(self, data):
self.Layers.append(data)
## tack on a new layer
self.layerCount += 1
## increment the counter so we know its there
def getDate(self):
return self.Layers[0][0]
## this should hopefully probably be a convention for all games levels
def getGameMJD(self):
return getMJDForDate(self.getDate())
## this does not take into account
def getLocation(self):
return self.Layers[0][1]
## same idea here
def getGameResult(self):
return self.Layers[0][2]
def getGoalsFor(self):
return int(self.Layers[0][3])
def getGoalsAgainst(self):
return int(self.Layers[0][4])
def getOpponentName(self):
return self.Layers[0][6]
def getGoalDifferential(self):
diff = self.getGoalsFor()-self.getGoalsAgainst()
return diff
## easy mode here
def Won(self):
if(self.getGameResult() in ['won', 'W']):
return True
else:
return False
def Tied(self):
if(self.getGameResult() in ['tie', 'T']):
return True
else:
return False
def Lost(self):
if(self.getGameResult() in ['lost', 'L']):
return True
else:
return False
def getGameClosenessIndex(self):
if(self.Tied() != True):
return 1.000/float(abs(self.getGoalDifferential()))
else:
return 1.000
## ie
##
## 1-1 -> 1.000
## 2-1 -> 1.000
## 3-1 -> 0.500
## 4-1 -> 0.333
## 5-1 -> 0.250
## 6-1 -> 0.200
## 7-1 -> 0.166
## its a quick way of measuring how close a game was with a single
## number
## although now that I take a look at it, the dropoff is a little bit
## too steep early on between a 1 to 2 to 3 goal differential
def getPointsPercentage(self):
return float(self.getPointsEarned())/self.getMaxPointsPossible()
## TierII statistics per game ##############################################
def loadTierII(self, teamsList, seasonIndex):
self.seasonIndex = seasonIndex
opponentFound = False
## start off by looking for our opponents object in the list of
## teams that we were given to search
for team in teamsList:
if(team.getTeamName() == self.getOpponentName()):
opponent = team
opponentFound = True
self.opponent = opponent
## once we find our team, assign it, and break outa here
## shouldnt ever be two teams with the same name... I hope
if(opponentFound == False):
## we wanna blow everything up here so that we can start
## debugging the problem
if(debugInfo):
print "Unable to find opponent '%s' in opposition teams," % game.getOpponentName()
for team in teamsList:
print team.getTeamName(),
print '\n'
raise NameError('Team %s Unable to find scheduled opponent %s as team object' % (self.getTeamName(), game.getOpponentName()))
##self.seasonRank = thisTeamRank+1
## team rank is the index of this team after sorting based on the watMu
## standings criteria
opponent = self.getOpponent()
def getOpponent(self):
return self.opponent
def getWinQualityIndex(self):
output = 0.000
opponentPointsPct = self.getOpponent().getSeasonPart(self.getComparisonConditions()).getAverageForStat(Game.getPointsPercentage)
if(self.Lost() != True):
## so long as we didnt lose the game, we will get a nonzero
## value for WQI and PQI, varying depending on the game stats
## and whether the game was a win or a tie
if(self.Won()):
output += (self.getGoalDifferential()*opponentPointsPct)
elif(self.Tied()):
output += (opponentPointsPct)
return output
def getPlayQualityIndex(self):
output = 0.000
opponentPointsPct = self.getOpponent().getSeasonPart(self.getComparisonConditions()).getAverageForStat(Game.getPointsPercentage)
if(self.Lost() != True):
## so long as we didnt lose the game, we will get a nonzero
## value for WQI and PQI, varying depending on the game stats
## and whether the game was a win or a tie
if(self.Won()):
output += (self.getGoalDifferential()*opponentPointsPct*self.getGameClosenessIndex())
elif(self.Tied()):
output += (opponentPointsPct*self.getGameClosenessIndex())
return output
def getDefenceQualityIndex(self):
output = 0.000
opponentOffence = self.getOpponent().getSeasonPart(self.getComparisonConditions()).getAverageForStat(Game.getGoalsFor)
output += (opponentOffence - self.getGoalsAgainst())
return output
def getOffenceQualityIndex(self):
output = 0.000
opponentDefence = self.getOpponent().getSeasonPart(self.getComparisonConditions()).getAverageForStat(Game.getGoalsAgainst)
output += (self.getGoalsFor() - opponentDefence)
return output
def getDiffQualityIndex(self):
output = 0.000
opponentGoalDiff = self.getOpponent().getSeasonPart(self.getComparisonConditions()).getAverageForStat(Game.getGoalDifferential)
output += (self.getGoalsFor() - (-opponentGoalDiff))
return output
def getOldDiffQualityIndex(self):
output = 0.000
opponentGoalDiff = self.getOpponent().getSeasonPart(self.getComparisonConditions()).getAverageForStat(Game.getGoalDifferential)
output += (self.getGoalsFor() - opponentGoalDiff)
return output
def getCPQI(self):
return (self.getOffenceQualityIndex() + self.getDefenceQualityIndex())
def getDiffQualMargin(self):
return (self.getCPQI()-self.getGoalDifferential())