-
Notifications
You must be signed in to change notification settings - Fork 0
/
DST.py
293 lines (224 loc) · 11.4 KB
/
DST.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import nflgame
# Stores all the information about the Defense and Special Teams Performance
class DST(object):
############################################################################################################################################
# Initialize the player object
def __init__(self, team):
self.team = team
############################################################################################################################################
#Get all sacks by the defense in week "w" of season "s"
def getDefSacks(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
sks = 0
# Bye Week ? If yes, get out of the function
if games is None:
return sks
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team):
if p.defense_sk > 0:
sks += 1
return sks
############################################################################################################################################
#Get all interceptions by the defense in week "w" of season "s"
def getDefInterceptions(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
interceptions = 0
# Bye Week ? If yes, get out of the function
if games is None:
return interceptions
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team, passing_int__gt=0):
interceptions += p.passing_int
return interceptions
############################################################################################################################################
# Get if the game was played at home or away for the defense in a given week+season
# Returns "HME" if the game was played at Home or "AWY" if the game was played away
# If the team had a bye-week , the method return "BYE"
def getHomeFldAdv(self,season,week):
# Get statistics for the current game
game = nflgame.one(season, week, self.team, self.team)
if game ==None:
return "BYE"
if game.away == self.team:
return "AWY"
elif game.home == self.team:
return "HME"
############################################################################################################################################
#Get the # of passing yards allowed by the defense in week "w" of season "s"
def getDefPassingYardsAllowed(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
passYards = 0
# Bye Week ? If yes, get out of the function
if games is None:
return passYards
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team, passing_att__ge=1):
passYards += p.passing_yds
return passYards
############################################################################################################################################
#Get the # of passing TDs allowed by the defense in week "w" of season "s"
def getDefPassingTDsAllowed(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
passTDs = 0
# Bye Week ? If yes, get out of the function
if games is None:
return passTDs
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team, passing_att__ge=1):
passTDs += p.passing_tds
return passTDs
############################################################################################################################################
#Get the # of receptions allowed by the defense in week "w" of season "s"
def getDefReceptionsAllowed(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
receptions = 0
# Bye Week ? If yes, get out of the function
if games is None:
return receptions
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team, passing_att__ge=1):
receptions += p.receiving_rec
return receptions
############################################################################################################################################
#Get the # of rushing yards allowed by the defense in week "w" of season "s"
def getDefRushingYardsAllowed(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
rushYards = 0
# Bye Week ? If yes, get out of the function
if games is None:
return rushYards
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team, rushing_att__ge=1):
rushYards += p.rushing_yds
return rushYards
############################################################################################################################################
#Get the # of rushing TDs allowed by the defense in week "w" of season "s"
def getDefRushingTDsAllowed(self,s, w):
games = nflgame.games_gen(s, w, self.team , self.team)
rushTDs = 0
# Bye Week ? If yes, get out of the function
if games is None:
return rushTDs
plays = nflgame.combine_plays(games)
for p in plays.filter(team__ne=self.team, rushing_att__ge=1):
rushTDs += p.rushing_tds
return rushTDs
############################################################################################################################################
#Get the # of points given up by the defense in week "w" of season "s"
def getPointsGivenUp(self,s, w):
game = nflgame.one(s,w,self.team, self.team)
ptsGVU = 0
# Bye Week ? If yes, get out of the function
if game is None:
return ptsGVU
if game.away == self.team:
ptsGVU = game.score_home
elif game.home == self.team:
ptsGVU = game.score_away
return ptsGVU
############################################################################################################################################
#Get the # of defensive TDs allowed by the defense in week "w" of season "s"
def getDefTDsScored(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
defTDs = 0
# Bye Week ? If yes, get out of the function
if games is None:
return defTDs
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.defense_tds>0:
defTDs = defTDs+1
return defTDs
############################################################################################################################################
#Get the # of defensive recoveries made by the defense in week "w" of season "s"
def getDefRecoveriesMade(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
defRecs = 0
# Bye Week ? If yes, get out of the function
if games is None:
return defRecs
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.defense_frec>0:
defRecs = defRecs+1
return defRecs
############################################################################################################################################
#Get the # of defensive recovery touchdowns made by the defense in week "w" of season "s"
def getDefRecoveryTDsScored(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
defRecTDs = 0
# Bye Week ? If yes, get out of the function
if games is None:
return defRecTDs
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.defense_frec_tds>0:
defRecTDs = defRecTDs+1
return defRecTDs
#defense_safe
############################################################################################################################################
#Get the # of defensive recovery touchdowns made by the defense in week "w" of season "s"
def getDefSafetysMade(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
sftys = 0
# Bye Week ? If yes, get out of the function
if games is None:
return sftys
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.defense_safe>0:
sftys = sftys+1
return sftys
############################################################################################################################################
#Get the # of Extra Points Blocked by the defense in week "w" of season "s"
def getDefXtraPtBlkMade(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
xpblk = 0
# Bye Week ? If yes, get out of the function
if games is None:
return xpblk
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.defense_xpblk>0:
xpblk = xpblk+1
return xpblk
############################################################################################################################################
#Get the # of Field Goals Blocked by the defense in week "w" of season "s"
def getDefFGBlkMade(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
fgblk = 0
# Bye Week ? If yes, get out of the function
if games is None:
return fgblk
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.defense_fgblk>0:
fgblk = fgblk+1
return fgblk
############################################################################################################################################
#Get the # of Punt Return Touch downs by the Special teams in week "w" of season "s"
def getPuntRetTDsMade(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
prtds = 0
# Bye Week ? If yes, get out of the function
if games is None:
return prtds
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.puntret_tds>0:
prtds = prtds+1
return prtds
#kickret_tds
############################################################################################################################################
#Get the # of Kick Return Touch downs by the Special teams in week "w" of season "s"
def getKickRetTDsMade(self,s, w):
games = nflgame.games_gen(s, w, self.team ,self.team)
krtds = 0
# Bye Week ? If yes, get out of the function
if games is None:
return krtds
plays = nflgame.combine_plays(games)
for play in plays.filter(team__ne=self.team):
if play.kickret_tds>0:
krtds = krtds+1
return krtds