BurntSushi / nflgame

An API to retrieve and read NFL Game Center JSON data. It can work with real-time data, which can be used for fantasy football.
http://pdoc.burntsushi.net/nflgame
The Unlicense
1.27k stars 414 forks source link

How to get each players plays of a certain yardage range in a game? #142

Closed tonycpsu closed 9 years ago

tonycpsu commented 9 years ago

I'm looking into the prospect of integrating nflgame and/or nfldb into a console application I've written to manage my fantasy teams. Right now it just handles baseball, but I'd like to add support for football. One thing I can't figure out is stats like "Field goals between 30-39 yards". I see the kicking_fgyds attribute, but it only seems to track the longest FG, not each field goal's yardage. Is there a way to get yardage data for each FGM?

ochawkeye commented 9 years ago

I suspect you are trying to look at plays in aggregate when trying to find your field goals (though I can't be certain...what does you code look like that you are trying to run?)

I would get the yardage of each made field goal like so:

import nflgame

games = nflgame.games(year=2015, week=1)
plays = nflgame.combine_plays(games).filter(kicking_fgm=True)

for play in plays:
    print play  # ie. (PIT, NE 26, Q2, 4 and 5) (:07) J.Scobee 44 yard field goal is GOOD, Center-G.Warren, Holder-J.Berry.
    for kicker in play.players.kicking():
        print kicker.player, play.kicking_fgm_yds # ie. Josh Scobee (K, PIT) 44
tonycpsu commented 9 years ago

Yeah, that works. I wanted it grouped by player so I can just store the number scored at each distance interval, but I can do that transformation myself. Thanks.

ochawkeye commented 9 years ago

I am curious what your code looked like.

Was it your expectation that each individual kick would be stored in the player object? I don't think it would be expected that every single play where Drew Brees completed a pass would have a separate passing yard included in his player object but if it can be better documented how the objects interact then I'd like to attempt to address that - whether it be in the wiki or elsewhere.

Without knowing what your goal was I was left to guess.

tonycpsu commented 9 years ago

At the time I posted, I think I was doing this:

games = nflgame.games(year=2015, week=1)
players = nflgame.combine_game_stats(games)
list(players.kicking())[0].stats

and noticed that in my fantasy league, we have separate point values for kicks of various distances, so I'd need to know how many were kicked at each interval. Your solution is fine, of course.

Sorry for not being clearer on that. I was basically just trying out some things to see if I can get by with just nflgame (using my existing database model with some updates to handle NFL stats), or if I'll need to interface with nfldb. It looks like nflgame might do everything I need, and will save me a lot of hassle writing the code to pull down all the stats the way I had to do with MLB.