Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query player stats against opponent error #28

Closed
rakers07 opened this issue Jul 12, 2014 · 2 comments
Closed

Query player stats against opponent error #28

rakers07 opened this issue Jul 12, 2014 · 2 comments

Comments

@rakers07
Copy link

I finally got nfldb to work so I've been having fun learning the past month. But I have come across something I am not sure how to fix or why it's going wrong. Take the following code that gets all the stats for Jay Cutler vs Green Bay since 2009.

import nfldb

def stats_against(db, player_name, team):
    q = nfldb.Query(db)
    q.game(season_type='Regular', season_year=[2009, 2010, 2011, 2012, 2013], team=team)
    q.player(full_name=player_name)
    q.play(passing_att__ge=1, team__ne=team)
    return q.as_aggregate()[0]

db = nfldb.connect()
p = stats_against(db, 'Jay Cutler','GB')
print '%s, %d completions for %d yards, %d tds and %d ints' \
      % (p.player, p.passing_cmp, p.passing_yds, p.passing_tds, p.passing_int)

easy enough. But if you take a look at some of his stats, he also has some rushing yds, fumbles, sacks.. that I would like to account for as well. If I try to get those stats,

 print p.passing_sk, p.rushing_att, p.rushing_yds, p.fumbles_lost 

output is:

0 0 0 0

I know this isn't accurate. It should be more like:
29 sacks 14 rushing att 92 rushing yds 2 fumbles.

Is there some query method where I can get every possible stat from the given player in one query, rather then having to make a new query for each statistical category. If I change

q.play(passing_att__ge=1, team__ne=team)
in the above code to
 q.play(rushing_att__ge=1,team__ne=team)
I get the rushing stats, still no sacks, and now Im without passing yards as well. I could combine another query to get sacks but I feel like there has to be a better way??

Any suggestions?
Thanks,
Roger

@BurntSushi
Copy link
Owner

Your question is a little strange. :P Your query is q.play(passing_att__ge=1, ...), which is saying, "only return statistics for plays where there was a passing attempt." And yet, you want all plays. That's easy. Stop asking for a specific statistic! :-)

e.g., q.play(team__ne=team).

@BurntSushi
Copy link
Owner

Closing for now. Please re-open if I misunderstood your question!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants