Skip to content

Instantly share code, notes, and snippets.

@ochawkeye
Created October 15, 2014 03:57
Show Gist options
  • Save ochawkeye/687e9d6df777183d270c to your computer and use it in GitHub Desktop.
Save ochawkeye/687e9d6df777183d270c to your computer and use it in GitHub Desktop.
import time
from collections import defaultdict
import nfldb
START = time.time()
def tally_points(db, y, w, ph):
q = nfldb.Query(db)
player_score = defaultdict(int)
q.game(season_year=y, week=w, season_type=ph)
for pp in q.as_aggregate():
player_score[pp.player] += 1.0*pp.kicking_xpmade
q.play_player(kicking_fgm=1)
for pp in q.as_play_players():
fg_length = getattr(pp, 'kicking_fgm_yds')
if fg_length < 40:
player_score[pp.player] += 3.0
elif fg_length < 50:
player_score[pp.player] += 4.0
else:
player_score[pp.player] += 5.0
return player_score
if __name__ == '__main__':
db = nfldb.connect()
player_points = tally_points(db, 2014, 6, 'Regular')
for player in player_points:
if player.player_id == '00-0025565': # Nick Folk
print player, type(player), player_points[player]
END = time.time()
print('Run time = %s' % (END-START))
@ochawkeye
Copy link
Author

output

Nick Folk (NYJ, K) <class 'nfldb.types.Player'> 2.0
Nick Folk (NYJ, K) <class 'nfldb.types.Player'> 3.0
Run time = 4.02799987793

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment