/
team_scripts.py
207 lines (170 loc) · 6.55 KB
/
team_scripts.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
import nflgame
isDebug = False
# FOR A TEAM
def get_receiving_yds(seas, week, team):
'''
This will return a teams receiving yards for a specific season and week.
'''
games = nflgame.games_gen(seas, week, team, team)
if games == None:
# Catch all for teams that have moved or joined the league.
return team, 0
plays = nflgame.combine_plays(games)
yds = 0
for p in plays.filter(team=team,receiving_yds__ge=1):
if isDebug:
print p
yds += p.receiving_yds
return team, yds
def get_rec_yds_per_team(season=None, weeks=None):
'''
This returns all teams receiving yards for a season and week(s)
'''
if season == None and weeks == None:
season, current_week = nflgame.live.current_year_and_week()
weeks = [x for x in range(1, current_week+1)]
nfl_teams = nflgame.teams
team_rec_yds = []
for team in nfl_teams:
team_abbrev = nflgame.standard_team(team[0])
result = get_receiving_yds(season, weeks, team_abbrev)
if (result[1] > 0):
# Only teams with receiving yards
if isDebug:
print "%s had %s receiving yds" % (result[0], result[1])
team_rec_yds.append(result)
# Return list of teams and receiving yds
return team_rec_yds
def print_best_passing_off():
'''
Prints the 'best' passing offense by teams receiving yards.
'''
results = get_rec_yds_per_team()
results.sort(key = lambda x: (x[1]), reverse=True)
for x in results:
print "%s has %s receiving yds" % (x[0], x[1])
def get_rushing_yds(seas, week, team):
'''
This will return a teams rushing yards for a specific season and week.
'''
games = nflgame.games_gen(seas, week, team, team)
if games == None:
# Catch all for teams that have moved or joined the league.
return team, 0
plays = nflgame.combine_plays(games)
yds = 0
for p in plays.filter(team=team,rushing_yds__ge=1):
if isDebug:
print p
yds += p.rushing_yds
return team, yds
def get_rush_yds_per_team(season=None, weeks=None):
'''
This returns all teams rushing yards for a season and week(s)
'''
if season == None and weeks == None:
season, current_week = nflgame.live.current_year_and_week()
weeks = [x for x in range(1, current_week+1)]
nfl_teams = nflgame.teams
team_rec_yds = []
for team in nfl_teams:
team_abbrev = nflgame.standard_team(team[0])
result = get_rushing_yds(season, weeks, team_abbrev)
if (result[1] > 0):
# Only teams with rushing yards
if isDebug:
print "%s had %s rushing yds" % (result[0], result[1])
team_rec_yds.append(result)
# Return list of teams and rushing yds
return team_rec_yds
def print_best_rushing_off():
'''
Prints the 'best' rushing offense by teams rushing yards.
'''
results = get_rush_yds_per_team()
results.sort(key = lambda x: (x[1]), reverse=True)
for x in results:
print "%s has %s rushing yds" % (x[0], x[1])
# END FOR A TEAM
# AGAINST TEAM
def get_receiving_yds_against(seas, week, team):
'''
Returns a tuple containing a team and receiving yards against said team for season and week(s)
'''
games = nflgame.games_gen(seas, week, team, team)
if games == None:
# Catch all for teams that have moved or joined the league.
return team, 0
plays = nflgame.combine_plays(games)
yds = 0
for p in plays.filter(team__ne=team,receiving_yds__ge=1):
yds += p.receiving_yds
return team, yds
def get_rec_yds_against_per_team(season=None, weeks=None):
'''
Returns a list of all teams and receiving yards scored against them (with at least 1 yard)
'''
if season == None and weeks == None:
season, current_week = nflgame.live.current_year_and_week()
weeks = [x for x in range(1, current_week+1)]
nfl_teams = nflgame.teams
team_yds_against = []
for team in nfl_teams:
team_abbrev = nflgame.standard_team(team[0])
result = get_receiving_yds_against(season, weeks, team_abbrev)
if (result[1] > 0):
# Only teams with yards against
if isDebug:
print "%s gave up %s passing yds" % (result[0], result[1])
team_yds_against.append(result)
# Return list of receiving yds scored against this team
return team_yds_against
def print_worst_passing_def():
'''
Prints the team with most receiving yards scored against them.
'''
results = get_rec_yds_against_per_team()
results.sort(key = lambda x: (x[1]),reverse=True)
for x in results:
print "%s has allowed %s receiving yds" % (x[0], x[1])
def get_rushing_yds_against(seas, week, team):
'''
Returns a tuple containing a team and rushing yards against said team for season and week(s)
'''
games = nflgame.games_gen(seas, week, team, team)
if games == None:
# Catch all for teams that have moved or joined the league.
return team, 0
plays = nflgame.combine_plays(games)
yds = 0
for p in plays.filter(team__ne=team,rushing_yds__ge=1):
yds += p.rushing_yds
return team, yds
def get_rush_yds_against_per_team(season=None, weeks=None):
'''
Returns a list of all teams and rushing yards scored against them (with at least 1 yard)
'''
if season == None and weeks == None:
season, current_week = nflgame.live.current_year_and_week()
weeks = [x for x in range(1, current_week+1)]
nfl_teams = nflgame.teams
team_yds_against = []
for team in nfl_teams:
team_abbrev = nflgame.standard_team(team[0])
result = get_rushing_yds_against(season, weeks, team_abbrev)
if (result[1] > 0):
# Only teams with yards against
if isDebug:
print "%s gave up %s rushing yds" % (result[0], result[1])
team_yds_against.append(result)
# Return list of receiving yds scored against this team
return team_yds_against
def print_worst_rushing_def():
'''
Prints the team with most rushing yards scored against them.
'''
results = get_rush_yds_against_per_team()
results.sort(key = lambda x: (x[1]),reverse=True)
for x in results:
print "%s has allowed %s rushing yds" % (x[0], x[1])
# END AGAINST TEAM