Skip to content

Instantly share code, notes, and snippets.

@ochawkeye
ochawkeye / gist:8244268
Created January 3, 2014 19:05
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])
@ochawkeye
ochawkeye / gist:8289332
Created January 6, 2014 20:29
nfldb-update error
c:\Python27\Scripts>python nfldb-update
-------------------------------------------------------------------------------
STARTING NFLDB UPDATE AT 2014-01-06 14:28:44.339000
Connecting to nfldb... done.
Setting timezone to UTC... done.
Updating player JSON database... (last update was 2014-01-04 03:55:54.395000+00:
00)
Loading games for POST 2013 week 19
Traceback (most recent call last):
File "c:\Python27\lib\runpy.py", line 162, in _run_module_as_main
@ochawkeye
ochawkeye / fuzzy_test.py
Last active August 29, 2015 14:06
Fuzzy matching
from __future__ import absolute_import, division, print_function
import nfldb
def nfldb_pp_func(db, nflgame_name):
"""
nflgame player name -> nfldb play player
P.Manning, DEN -> Peyton Manning (DEN, QB)
"""
@ochawkeye
ochawkeye / funny_gsis.py
Last active August 29, 2015 14:06
Where are those names coming from?
import nflgame
games = nflgame.games(2014, week=1, kind='REG')
players = nflgame.combine_game_stats(games)
meta = nflgame.players
for x in players:
if str(x) == 'M.Ryan':
print x.playerid, meta[x.playerid], meta[x.playerid].gsis_name, x
if '.' not in str(x):
@ochawkeye
ochawkeye / simple nfldb query
Created August 31, 2015 20:42
simple nfldb query
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, season_type='Preseason')
for game in q.as_games():
print game
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2012, season_type='Regular')
q.player(full_name='Julian Edelman').play_player(offense_tds=1)
for g in q.as_games():
print g
print '-'*79
@ochawkeye
ochawkeye / team_rosters.py
Last active November 24, 2015 21:50
Attempt at assembling rosters from past seasons
import nflgame
year = 2014
games = nflgame.games(year)
players = nflgame.combine(games)
positions = set([p.player.position for p in players if p.player.position])
# Sets up some empty dictionaries for each team to hold all of the positions
teams = nflgame.teams
@ochawkeye
ochawkeye / cooper_nfldb.py
Created September 23, 2015 17:01
Amari Cooper in NFLDB
import nfldb
name = 'Amari Cooper'
team = 'OAK'
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, season_type='Regular')
q.player(full_name=name, team=team)
@ochawkeye
ochawkeye / chp.py
Last active October 20, 2015 18:15
import nfldb
NYGmisc = {}
db = nfldb.connect()
qNYG = nfldb.Query(db)
for gp in qNYG.play_player(team='NYG').player(position='TE').as_aggregate():
# NYGmisc[gp.player] = gp <-- if you do like this, the values are class 'nfldb.query.AggPP'
NYGmisc[gp.player] = {field: getattr(gp, field) for field in gp.fields} # but if you do like this they are type 'dict'
for x in NYGmisc:
print type(x), type(NYGmisc[x])
import nflgame
year, week = 2015, 7
games = nflgame.games(year=year, week=week)
plays = nflgame.combine_plays(games).filter(fourth_down_att=True)
attempts = 0
att_converted = 0
att_failed = 0
for play in plays: