-
Notifications
You must be signed in to change notification settings - Fork 263
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
a function to find score of game at a point in time #6
Comments
(Btw - this library is awesome - super useful!) Are you currently working on a function to return the score at given a point in time? If not, any thoughts on where / how to best implement such a function? Thanks! |
Thanks! It may actually be easier to write this function given the nfldb.PlayPlayer.points and nfldb.Play.points methods added in commit af62534. First, we need to think about the public interface for such a method. I can think of several reasonable choices. One of them is, "give me a play, and I'll tell you the score of the game up to and including the play given." Another is, "give me a game time and I'll tell you the score of the game at that time." This might also be done by quarter, drive, etc... There appears to be a lowest common denominator here: game time. This suggests that the actual implementation should collect all plays in a game up to a certain game time. Actually, that sounds like an interesting method in and of itself. Once you have the plays, it should be trivial to sum over them with the aforementioned Note that the nfldb.Clock type already defines an ordering for game times, so sorting should be easy. Also, the Clock.from_str method should come in handy. I think that's all of the pieces. They just need to be assembled. I would expect that such a method would be a part of the Game class. Pull requests are welcome. :-) (If you haven't done one before, I'd be happy to work with you on it.) |
Also, I think the Game.plays property should be used to access the plays for determining the score. There's more info on walking the hierarchy of data on the wiki. |
Excellent - thanks a lot for the note! I'll take a crack at implementing a method in the Game class to collect all the plays up to a given game time, and then use that to get the score at a given time via the points method. Will follow up soon with a pull request and/or additional questions! |
Awesome, thank you! I'm also on the |
Hope all's well! I wanted to ask a quick question about scoring play data. I'm seeing the correct final score for all the games I look at, but when I test the method I wrote to sum the scoring plays, it looks like some extra points and other things are missing. I was thinking maybe I am doing something wrong -- would love any advice and thanks for bearing with the long note. First, here's an example of one that looks right: (17, 24) -- correct game score And one that looks wrong - many look similar to this: (41, 21) -- correct game score - http://espn.go.com/nfl/boxscore?gameId=320909003 All plays w/ value for points: |
You must have something wrong in the way you capture scores. I'm guessing you are not capturing that pick-six on the IND side. ( Another possibility that you might be missing would be return touchdowns: |
In particular, scoring_team will always return the name of the team responsible for scoring any points in a particular play.
While #17 has been merged, I think that we still need to add |
score_at_time seems to be exactly what I'm looking for, but I don't understand how to use this method. Do you have an example of how to use it? My goal is a script that will return the score of a specified game at set interval from the beginning to the end of a game. Thanks! |
@szac In the future, please open new issues. Commenting on an issue that was closed a half-year ago is going to make it harder for us to notice your question. To answer your question, have you looked at the API documentation for import nfldb
db = nfldb.connect()
game = nfldb.Game.from_id(db, '2014090400')
print game.score_at_time(nfldb.Clock.from_str('Q2', '3:46'))
# Output: (10, 10)
print game.score_at_time(nfldb.Clock.from_str('Q2', '3:45'))
# Output: (17, 10) |
Thanks and 10-4. Yes, I was looking at the documentation and at all the examples in the wiki, but my terrible Python skills prevented me from understanding that I needed to create a Game object in this way. It seems more obvious now. Thanks again! (I'll post a new issue in the future). |
@szac You can create game objects however you want. For example, if you wanted to do this for every game in week 1: import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2014, season_type='Regular', week=1)
for game in q.as_games():
print game.score_at_time(nfldb.Clock.from_str('Q2', '3:45')) |
Nice! Ahh I see now providing the "as_*" context to build out the object from Query. I'll head back and read more about this. I see how that is huge feature to the software. Great work, man. Thank you. |
@szac Indeed! I strongly recommend that you check out the wiki. There are a gagillion examples. |
Will do. I think I went through every one, before tapping out and posting. It's my noobness, for sure. These last two examples you just provided really bring things in to focus for me. Go Lions! |
After filing issue #5, I think a somewhat appropriate response is to provide a function that takes a play in a game and returns the score of the game before the play given was snapped.
The score must be computed by looking at the scoring plays of all plays previous to the one given. This means that the score may be inaccurate in some circumstances. It could be inaccurate if the statistics are wrong/missing, or if the plays are out of their correct sequence.
The text was updated successfully, but these errors were encountered: