Skip to content

Instantly share code, notes, and snippets.

@ochawkeye
Created January 3, 2014 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochawkeye/8244268 to your computer and use it in GitHub Desktop.
Save ochawkeye/8244268 to your computer and use it in GitHub Desktop.
PR, KR, and D
games = nflgame.games(year, week=week, kind=season_type)
kick_returns, punt_returns = [], []
plays = nflgame.combine_plays(games)
playsKR = plays.filter(kickret_ret__ge=1)
for player in playsKR.players():
kick_returns.append([
str(player)+', '+player.team,
player.kickret_ret,
player.kickret_yds,
player.kickret_tds])
plays = nflgame.combine_plays(games)
playsPR = plays.filter(puntret_tot__ge=1)
for player in playsPR.players():
punt_returns.append([
str(player)+', '+player.team,
player.puntret_yds,
player.puntret_tds])
for each in kick_returns:
if each[1] > 0 or each[2] > 0 or each[3] > 0:
if each[0] in result:
result[each[0]][12] = each[1]
result[each[0]][13] = each[2]
result[each[0]][14] = each[3]
else:
"""
# I've found that sometimes a player shows up in the
# play-by-play that has no game stats. These have been
# limited primarity to lesser known defensive players that
# return a kick. Pretty much ignoring these cases until the
# day that one of these lesser known players would actually
# be used in FF. This will write a warning to the terminal
# window, but nothing else
"""
print 'Failed to add %s %s and %s to %s' % (
each[1], each[2], each[3], each[0])
for each in punt_returns:
if each[1] > 0 or each[2] > 0:
if each[0] in result:
result[each[0]][15] = each[1]
result[each[0]][16] = each[2]
else:
#Same reason as the kick return above
print 'Failed to add %s and %s to %s' % (
each[1], each[2], each[0])
#Update points with newly added kick return and punt return statistics
for key, val in result.items():
val[25] += -10*val[12]+1*val[13]+60*val[14]+2*val[15]+60*val[16]
games = nflgame.games(year, week=week, kind=season_type)
#Find defensive interceptions and interceptions for touchdowns
plays = nflgame.combine_plays(games)
for p in plays.filter(defense_int=True).players().defense():
if p.defense_int > 0:
defense_results[p.team][4] += p.defense_int
defense_results[p.team][5] += p.defense_tds
#Find defensive fumble recoveries and defensive fumble recoveries
# for TD
plays = nflgame.combine_plays(games)
for p in plays.filter(defense_frec=True).players().defense():
if p.defense_frec > 0:
defense_results[p.team][6] += p.defense_frec
defense_results[p.team][7] += p.defense_frec_tds
#Find defensive sacks
plays = nflgame.combine_plays(games)
for p in players.filter(defense_sk=lambda x: x > 0).sort("defense_sk"):
defense_results[p.team][8] += p.defense_sk
#Find defensive safeties
plays = nflgame.combine_plays(games)
for p in plays.filter(defense_safe=True).players().defense():
if p.defense_safe > 0:
defense_results[p.team][9] += p.defense_safe
#Find kick return touchdowns
plays = nflgame.combine_plays(games)
for p in plays.filter(kickret_tds=True).players():
if p.kickret_tds > 0:
defense_results[p.team][11] += p.kickret_tds
#Find punt return touchdowns
plays = nflgame.combine_plays(games)
for p in plays.filter(puntret_tds=True).players():
if p.puntret_tds > 0:
defense_results[p.team][11] += p.puntret_tds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment