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

a function to find score of game at a point in time #6

Closed
BurntSushi opened this issue Sep 19, 2013 · 16 comments
Closed

a function to find score of game at a point in time #6

BurntSushi opened this issue Sep 19, 2013 · 16 comments

Comments

@BurntSushi
Copy link
Owner

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.

@ersherr
Copy link
Contributor

ersherr commented Nov 29, 2013

(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!

@BurntSushi
Copy link
Owner Author

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 points method.

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.)

@BurntSushi
Copy link
Owner Author

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.

@ersherr
Copy link
Contributor

ersherr commented Dec 3, 2013

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!

@BurntSushi
Copy link
Owner Author

Awesome, thank you! I'm also on the #nflgame IRC channel at FreeNode if you're interested. (Although heading to sleep now.)

@ersherr
Copy link
Contributor

ersherr commented Jan 3, 2014

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
(17, 24) -- calculated score by summing scoring plays - they match! but check out the next game below
('NYG', 3)
('DAL', 6)
('DAL', 1)
('DAL', 6)
('DAL', 1)
('NYG', 6)
('NYG', 1)
('DAL', 3)
('DAL', 6)
('DAL', 1)
('NYG', 6)
('NYG', 1)

And one that looks wrong - many look similar to this:

(41, 21) -- correct game score - http:https://espn.go.com/nfl/boxscore?gameId=320909003
(47, 14) -- calculated by summing scoring plays - some missing (full list of all plays below)
('CHI', 6)
('CHI', 6)
('CHI', 1)
('CHI', 6)
('CHI', 1)
('CHI', 3)
('IND', 6)
('IND', 1)
('CHI', 6)
('CHI', 1)
('CHI', 6)
('CHI', 1)
('CHI', 3)
('IND', 6)
('IND', 1)
('CHI', 6)
('CHI', 1)

All plays w/ value for points:
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('CHI', 6)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('UNK', 0)
('CHI', 0)
('CHI', 0)
('CHI', 6)
('CHI', 1)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('UNK', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 6)
('CHI', 1)
('CHI', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 3)
('CHI', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 6)
('IND', 1)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('UNK', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 6)
('CHI', 1)
('CHI', 0)
('IND', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('UNK', 0)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('UNK', 0)
('CHI', 0)
('CHI', 0)
('CHI', 6)
('CHI', 1)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 3)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('UNK', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('IND', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 6)
('IND', 1)
('IND', 0)
('UNK', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 6)
('CHI', 1)
('CHI', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('UNK', 0)
('CHI', 0)
('IND', 0)
('IND', 0)
('IND', 0)
('UNK', 0)
('IND', 0)
('IND', 0)
('CHI', 0)
('CHI', 0)
('CHI', 0)
('UNK', 0)

@ochawkeye
Copy link
Contributor

You must have something wrong in the way you capture scores.
In the IND/CHI game:
Indianapolis's defense gave up 41 points: 2 passing touchdowns by Cutler (1 to Marshall, 1 to Jeffery), 3 rushing touchdowns (1 for Forte, 2 for Bush), 5 extra points, and 2 field goals.
Chicago's defense gave up 15 points: 1 passing touchdown by Luck (to Avery), 1 rushing touchdown (Brown), and 3 extra points.
Chicago's offense gave up 6 points: 1 interception return for a touchdown.

I'm guessing you are not capturing that pick-six on the IND side. (int_tds & fumble_tds)
I'm guessing you are double counting one of the scores on the CHI side?

Another possibility that you might be missing would be return touchdowns: kickret_tds & puntret_tds.

BurntSushi added a commit that referenced this issue Jan 3, 2014
In particular, scoring_team will always return the name of the team
responsible for scoring any points in a particular play.
@BurntSushi
Copy link
Owner Author

While #17 has been merged, I think that we still need to add score methods to the play and drive classes. Namely, it should return the score before (or after) the given play/drive.

@BurntSushi
Copy link
Owner Author

Okay, now that #18 has been merged, I'm marking this issue resolved. Thank you @ersherr! :-)

@szac
Copy link

szac commented Sep 4, 2014

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!

@BurntSushi
Copy link
Owner Author

@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 nfldb.Game.score_at_time? It tells you the type of the value it expects. Here are a couple examples from the season opener:

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)

@szac
Copy link

szac commented Sep 7, 2014

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).

@BurntSushi
Copy link
Owner Author

@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'))

@szac
Copy link

szac commented Sep 7, 2014

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.

@BurntSushi
Copy link
Owner Author

@szac Indeed! I strongly recommend that you check out the wiki. There are a gagillion examples.

@szac
Copy link

szac commented Sep 7, 2014

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!

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

4 participants