BurntSushi / nfldb

A library to manage and update NFL data in a relational database.
The Unlicense
1.08k stars 263 forks source link

Targets and Receptions are the same for players. #217

Open theSanchize3 opened 7 years ago

theSanchize3 commented 7 years ago

I am looking at the targets and receptions for an upcoming game this weekend, but I am getting the same number for both stats. Here is the code:

for t in ['PHI','WAS']:
    q = nfldb.Query(db)
    q.game(season_year=2016,season_type='Regular',team=t)
    q.play_player(receiving_rec__ge=1,team=t)
    for p in q.sort('receiving_yds').as_aggregate():
        print p.receiving_rec,p.receiving_tar,p.player

And here is the output:

57 57 Jordan Matthews (PHI, WR)
47 47 Zach Ertz (PHI, TE)
45 45 Darren Sproles (PHI, RB)
33 33 Dorial Green-Beckham (PHI, WR)
31 31 Nelson Agholor (PHI, WR)
22 22 Trey Burton (PHI, TE)
7 7 Brent Celek (PHI, TE)
11 11 Ryan Mathews (PHI, RB)
6 6 Paul Turner (PHI, WR)
3 3 Bryce Treggs (PHI, WR)
13 13 Josh Huff (TB, WR)
6 6 Wendell Smallwood (PHI, RB)
3 3 Kenjon Barner (PHI, RB)
1 1 Carson Wentz (PHI, QB)
58 58 Jamison Crowder (WAS, WR)
59 59 Pierre Garcon (WAS, WR)
39 39 DeSean Jackson (WAS, WR)
59 59 Jordan Reed (WAS, TE)
36 36 Vernon Davis (WAS, TE)
37 37 Chris Thompson (WAS, RB)
8 8 Matt Jones (WAS, RB)
2 2 Josh Doctson (WAS, WR)
6 6 Ryan Grant (WAS, WR)
7 7 Maurice Harris (WAS, WR)
1 1 Quinton Dunbar (WAS, CB)
2 2 Niles Paul (WAS, TE)
2 2 Derek Carrier (WAS, TE)
1 1 Rashad Ross (WAS, WR)
4 4 Rob Kelley (WAS, RB)

Is there an issue with my code or is the an issue with the database?

Thanks, Sanchez

ochawkeye commented 7 years ago

You're filtering on only plays where a reception was recorded.

On Dec 10, 2016 2:15 PM, "theSanchize3" notifications@github.com wrote:

I am looking at the targets and receptions for an upcoming game this weekend, but I am getting the same number for both stats. Here is the code:

for t in ['PHI','WAS']: q = nfldb.Query(db) q.game(season_year=2016,season_type='Regular',team=t) q.play_player(receiving_rec__ge=1,team=t) for p in q.sort('receiving_yds').as_aggregate(): print p.receiving_rec,p.receiving_tar,p.player

And here is the output:

57 57 Jordan Matthews (PHI, WR) 47 47 Zach Ertz (PHI, TE) 45 45 Darren Sproles (PHI, RB) 33 33 Dorial Green-Beckham (PHI, WR) 31 31 Nelson Agholor (PHI, WR) 22 22 Trey Burton (PHI, TE) 7 7 Brent Celek (PHI, TE) 11 11 Ryan Mathews (PHI, RB) 6 6 Paul Turner (PHI, WR) 3 3 Bryce Treggs (PHI, WR) 13 13 Josh Huff (TB, WR) 6 6 Wendell Smallwood (PHI, RB) 3 3 Kenjon Barner (PHI, RB) 1 1 Carson Wentz (PHI, QB) 58 58 Jamison Crowder (WAS, WR) 59 59 Pierre Garcon (WAS, WR) 39 39 DeSean Jackson (WAS, WR) 59 59 Jordan Reed (WAS, TE) 36 36 Vernon Davis (WAS, TE) 37 37 Chris Thompson (WAS, RB) 8 8 Matt Jones (WAS, RB) 2 2 Josh Doctson (WAS, WR) 6 6 Ryan Grant (WAS, WR) 7 7 Maurice Harris (WAS, WR) 1 1 Quinton Dunbar (WAS, CB) 2 2 Niles Paul (WAS, TE) 2 2 Derek Carrier (WAS, TE) 1 1 Rashad Ross (WAS, WR) 4 4 Rob Kelley (WAS, RB)

Is there an issue with my code or is the an issue with the database?

Thanks, Sanchez

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BurntSushi/nfldb/issues/217, or mute the thread https://github.com/notifications/unsubscribe-auth/AC237Rym0LPVN2p_Y2AyfzEQMAxdvUtuks5rGwh-gaJpZM4LJv3E .

theSanchize3 commented 7 years ago

Oh, I didn't realize that. How would I get the number of targets and receptions of all the players with at least one catch on the season?

ochawkeye commented 7 years ago

With the line q.play_player(receiving_rec__ge=1,team=t) you're throwing away all plays that didn't record a reception. Just don't do that if you want to get targets that didn't result in a reception.

import nfldb

db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2016, season_type='Regular')
# q.play_player(receiving_rec__ge=1)  # You are doing something like this and it is your problem
q.play_player(receiving_tar__ge=1)

for p in q.sort('receiving_tar').as_aggregate():
    if p.receiving_rec:
        print p.receiving_rec, p.receiving_tar, p.player
80 144 Mike Evans (TB, WR)
93 138 Antonio Brown (PIT, WR)
79 134 Odell Beckham (NYG, WR)
92 131 Larry Fitzgerald (ARI, WR)
75 128 Emmanuel Sanders (DEN, WR)
78 127 T.Y. Hilton (IND, WR)
75 125 Jordy Nelson (GB, WR)
76 119 Demaryius Thomas (DEN, WR)
71 119 Michael Crabtree (OAK, WR)
57 118 Allen Robinson (JAC, WR)
63 117 Terrelle Pryor (CLE, WR)
59 116 DeAndre Hopkins (HOU, WR)
57 114 Brandon Marshall (NYJ, WR)
73 114 Amari Cooper (OAK, WR)
72 113 Julio Jones (ATL, WR)
...