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

Better way to find successful 2-point returns? #368

Open benlindsay opened 5 years ago

benlindsay commented 5 years ago

I'm still learning how to use this tool, and I'm trying to find the (very rare) cases of 2-point conversions or extra points where a turnover occurred and the defense returned the ball to their end zone. I can't find any combinations of stats to search for these, but I found a very clunky way to get at this that looks like this:

year = 2016
week = None
team = None
games = nflgame.games_gen(year, week, team, team)
plays = nflgame.combine_plays(games)
for p in plays:
    if ('DEFENSIVE TWO-POINT ATTEMPT' in str(p) and
        'ATTEMPT SUCCEEDS' in str(p)):
        print p

Looks like this only happened 4 times in 2016 (results look like this:)

(CLE, BAL 15, Q1) P.Murray extra point is Blocked (L.Guy), Center-C.Hughlett, Holder-B.Colquitt. DEFENSIVE TWO-POINT ATTEMPT. T.Young recovered the blocked kick. ATTEMPT SUCCEEDS.
(NO, DEN 15, Q4) W.Lutz extra point is Blocked (J.Simmons), Center-J.Drescher, Holder-T.Morstead. DEFENSIVE TWO-POINT ATTEMPT. W.Parks recovered the blocked kick. ATTEMPT SUCCEEDS. The Replay Official reviewed the runner was in bounds ruling, and the play was Upheld. The ruling on the field stands.
(ATL, KC 2, Q4) (Pass formation) TWO-POINT CONVERSION ATTEMPT. M.Ryan pass to A.Hooper is incomplete. ATTEMPT FAILS. DEFENSIVE TWO-POINT ATTEMPT. E.Berry intercepted the try attempt. ATTEMPT SUCCEEDS.
(ARI, MIA 15, Q4) C.Catanzaro extra point is Blocked (J.Phillips), Center-A.Brewer, Holder-D.Butler. DEFENSIVE TWO-POINT ATTEMPT. W.Aikens recovered the blocked kick. ATTEMPT SUCCEEDS.

and 0 in 2017, but it would still be nice to have a better way of doing this.

With this method, I also don't know how to reliably attribute the 2 point return to the right player. For example, printing p.events and p._stats for the first play looks like this:

"[{'kicking_xpmissed': 1, 'playerid': u'00-0030626', 'playername': u'P.Murray', 'team': u'CLE', 'kicking_xpa': 1, 'kicking_xpb': 1}, {'playerid': u'00-0028171', 'defense_xpblk': 1, 'playername': u'L.Guy', 'team': u'BAL'}]"
"{'defense_xpblk': 1, 'kicking_xpa': 1, 'kicking_xpb': 1, 'kicking_xpmissed': 1}"

which gives no hint about any defensive scoring happening, just a blocked extra point attempt.