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 413 forks source link

Play by play updates #160

Open ochawkeye opened 9 years ago

ochawkeye commented 9 years ago

Maybe this is more an FYI or serves as a jumping off point to discussion...

I have caught some cases where the NFL has gone in after the fact and updated/corrected play by play information. Since json data gets cached and then never looked at again once the game is final, this would lead to different game files for someone that collected in real time vs. someone that ran nflgame after the corrections were made.

import nflgame
games = nflgame.games(2015, 2, home='SF', away='SF')
plays = nflgame.combine_plays(games).filter(defense_frec__ge=1)
for play in plays:
    if play.has_player(nflgame.find('Carlos Hyde')[0].gsis_id):
        print play.drive.game.eid, play.playid, play

games = nflgame.games(2015, 4, home='OAK', away='OAK')
plays = nflgame.combine_plays(games).filter(defense_frec__ge=1)
for play in plays:
    if play.has_player(nflgame.find('Latavius Murray')[0].gsis_id):
        print play.drive.game.eid, play.playid, play
2015092009 1850 (SF, SF 45, Q2, 1 and 10) (4:47) (Shotgun) C.Hyde FUMBLES (Aborted) at SF 42, RECOVERED by PIT-R.Shazier at SF 42. R.Shazier to SF 42 for no gain (V.McDonald).
2015100401 3773 (OAK, CHI 49, Q4, 2 and 4) (9:45) L.Murray FUMBLES (Aborted) at CHI 44, RECOVERED by CHI-S.Acho at OAK 42. S.Acho to OAK 42 for no gain (J.Webb).

image --------------------------------------- image

I suspect if I delete those two games from nflgame and let them be pulled again they would fix themselves. I don't know if the NFL has a statute of limitations on how long after the play by play is posted that stat corrections can be changed, but I would imagine the window is pretty small. What are thoughts on doing a one-time drop & re-add for games after completion - say, one week after?

BurntSushi commented 9 years ago

That seems pretty reasonable to me. Not sure exactly how to implement it. I guess you'd have to carry download time as part of the game json blob or something.

I do also run across this occasionally. For nfldb it's a bit simpler because you can just wipe the entire last week and re-run nfldb-update. :-)

ochawkeye commented 9 years ago

Hmm - this nfldb sounds interesting to me. Why have you not pushed me to move over to that before?

BurntSushi commented 9 years ago

Haha :P

ochawkeye commented 9 years ago

In a play late in Giants/Eagles game Monday night nfl.com initially had ruled something like Eli Manning ran for -4 yards, fumbled, E.Flowers picked it up and lost another 7 yards. At some point later, they changed this to a -11 yard pass with an illegal touch. I deleted the game on Tuesday and saw the change reflected in nflgame. So far so good. For game = '2015101900', playid '4346' I now have:

(3:53) (Shotgun) E.Manning pass short middle to E.Flowers to NYG 39 for -11 yards (B.Graham) [B.Graham]. Penalty on NYG-M.Newhouse, Illegal Touch Pass, declined.'

I started to poke at the JSON looking for any clues and did notice right at the very end a tag nextupdate. Now, I have no idea what this is supposed to be, but sounded interesting. I hadn't yet deleted either of the games referenced above, but gave those a shot tonight, interested in a) whether the play-by-play would actually update and b) whether the nextupdate value would change.

import nflgame
plays = [('2015092009', 8, '1850'), ('2015100401', 20, '3773')] # game.eid, drive_num, playid

for play in plays:
    game = nflgame.game.Game(play[0])
    for d in game.drives:
        if d.drive_num == play[1]:
            print [p for p in d.plays if p.playid == play[2]][0]
            print nflgame.game._get_json_data(eid=play[0])[-17:]

Pre-delete:

(SF, SF 45, Q2, 1 and 10) (4:47) (Shotgun) C.Hyde FUMBLES (Aborted) at SF 42, RECOVERED by PIT-R.Shazier at SF 42. R.Shazier to SF 42 for no gain (V.McDonald).
"nextupdate":266}
(OAK, CHI 49, Q4, 2 and 4) (9:45) L.Murray FUMBLES (Aborted) at CHI 44, RECOVERED by CHI-S.Acho at OAK 42. S.Acho to OAK 42 for no gain (J.Webb).
"nextupdate":352}

Post-delete:

(SF, SF 45, Q2, 1 and 10) (4:47) (Shotgun) C.Hyde FUMBLES (Aborted) at SF 42, RECOVERED by PIT-R.Shazier at SF 42. R.Shazier to SF 42 for no gain (V.McDonald).
"nextupdate":269}
(OAK, CHI 49, Q4, 2 and 4) (9:45) L.Murray FUMBLES (Aborted) at CHI 44, RECOVERED by CHI-S.Acho at OAK 42. S.Acho to OAK 42 for no gain (J.Webb).
"nextupdate":357}

Neither of the play-by-plays updated to what is shown on nfl.com as I had hoped (bummer), but the nextupdate tag did change in both cases. What is that supposed to represent? Any ideas?