-
-
Save ochawkeye/687e9d6df777183d270c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output