GithubHelp home page GithubHelp logo

Comments (16)

ersherr avatar ersherr commented on July 20, 2024

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

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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.

from nfldb.

ersherr avatar ersherr commented on July 20, 2024

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!

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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

from nfldb.

ersherr avatar ersherr commented on July 20, 2024

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://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)

from nfldb.

ochawkeye avatar ochawkeye commented on July 20, 2024

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.

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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.

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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

from nfldb.

szac avatar szac commented on July 20, 2024

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!

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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

from nfldb.

szac avatar szac commented on July 20, 2024

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

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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

from nfldb.

szac avatar szac commented on July 20, 2024

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.

from nfldb.

BurntSushi avatar BurntSushi commented on July 20, 2024

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

from nfldb.

szac avatar szac commented on July 20, 2024

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!

from nfldb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.