-
Notifications
You must be signed in to change notification settings - Fork 414
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
Calculate 3rd down conversion rate #36
Comments
I like the approach here. The only thing I would change is to make it a bit faster and have your Incidentally, this results in a nice clean contract for your import nflgame
year, week, season_type = 2013, 1, 'REG'
def third_down2(teamname, play_gen):
attempts = 0
conversions = 0
for p in play_gen.filter(team=teamname, third_down_att=1):
attempts += 1
conversions += p.third_down_conv
percentage = float(conversions)/float(attempts)*100
return '%s: %s of %s (%.2f%%)' % (
teamname, conversions, attempts, percentage)
games = nflgame.games(year, week, kind=season_type)
for game in games:
print third_down2(game.home, game.drives.plays())
print third_down2(game.away, game.drives.plays()) This approach also allows for computing third down conversion rates over multiple games by passing the result of Note that I also changed |
I like it. If there is one thing I am very guilty of, it is reliance upon global variables. I also do a poor job of scaling from simple tests to larger tests. Up until I posted it here, the body of the code had been simply @BurntSushi Thanks as always for your patient explanations. |
Thank you ochawkeye and BurntSushi. My problem is that I didn't even know that third_down_conv existed. I looked through the nflgame API and couldn't find anything. I found third_down_conv in the nfldb API in the Play class. Should I have known to look in the nfldb API? Sorry if this is a dumb question. |
@poppers112 That's not a dumb question at all! In fact, that's exactly why issues #11 and #12 exist. There's just no easy to consume documentation yet. nfldb's API is not a bad place to look. There is a ton of overlap, although there may be a couple small renamings. A more definitive but less convenient place to look is in nflgame/statmap.py. It includes descriptions of each. |
There is also an ER diagram for nfldb that might be a good way to get a bird's eyeview of the data available. |
@ochawkeye Just keep doing what your doing. Your code is definitely improving. :-) |
@poppers112 Asked about how one would go about calculating 3rd down conversion rates for the two different teams involved in a game. I was interested in that as well so attempted to do the same. This isn't an issue, and probably belongs in a cookbook that may one day exist, but I couldn't think of a better place to put this.
My attempt as follows:
This gets the job done.
How can I improve this method?
The text was updated successfully, but these errors were encountered: