RLovelett / sports_data_api

A Ruby interface to the Sports Data API. API supports NFL, MLB, NHL, and NBA.
http://developer.sportsdatallc.com/api_gallery
Other
26 stars 28 forks source link

Implement NFL Play-By-Play #6

Open RLovelett opened 11 years ago

RLovelett commented 11 years ago

Play-By-Play

Schema

Syntax: http://api.sportsdatallc.org/nfl-[access_level][version]/schema/pbp-v1.0.xsd?api_key=[your_api_key]

Schema Example

Feed

Syntax: http://api.sportsdatallc.org/nfl-[access_level][version]/[year]/[nfl_season]/[nfl_season_week]/[away_team]/[home_team]/pbp.[format]?api_key=[your_api_key]

Parameter Format Notes

[access_level] = Real-Time (rt), Premium (p), Standard (s), Basic (b), Trial (t)

[version] = whole number (sequential, starting with the number 1)

[year] = yyyy

[nfl_season] = Preseason (PRE), Regular Season (REG), Postseason (PST)

[nfl_season_week] = 1 - 17 (Week 0 of Preseason is Hall of Fame game)

[format] = xml

[home_team], [away_team] = <see schedule feed>

Feed Example

janjiss commented 9 years ago

@RLovelett Hey, I am working on NFL Play by Play endpoint and wanted to get your opinion before I proceed. The problem with Play by Play is that it's collections are not homogenous, it means that there are "drive" type elements and "event" elements in the "pbp" array. They differ in their structure. I have three approaches in my mind that might work out, but they are all less than ideal. 1) To create a "generic" event class that might or might not contain certain values from play by play event. I can see this going all sorts of wrong since constant nil checks suck. 2) To map event by type to a certain class. This leaves us with the problem of type checking. 3) To have methods for quarter like - quarter.drive_events and collect them all that way. This would make the structure of the quarter class not map directly to API.

I am curious, maybe you had other ideas in mind?

TheKidCoder commented 9 years ago

+1 For mapping events to types. I think it's the best choice. We'll need to come up with a solid interface to extend from but I think duck typing from there would work well enough.

RLovelett commented 9 years ago

I'll be honest this is one that I didn't really look at in any detail. @janjis it's easier for me to speak in code regarding proposals. Can you show a snippet for any of the ones you like the most?

janjiss commented 9 years ago

@RLovelett Sure, here is the code that I am working one, please note that it is a "Work in progress": https://github.com/DiatomEnterprises/sports_data_api/blob/master/lib/sports_data_api/nfl/play_by_play.rb

RLovelett commented 9 years ago

Ok now that I've looked at some of the code. I think I'm starting to agree with @TheKidCoder. Making the events into types feels the cleanest to me. In my mind, the code I imagine writing with the type checking becomes the most readable.

Example

events = game.pbp # events/php is an Enumerable?
case events.first.class
when EventA
  # stuff
when EventB
  # stuff
...

or even

events = game.pbp # events/php is an Enumerable?
if events.first.is_a?(EventA)
  # do something great
end

@janjiss I tried looking over the specs to get a feel for how you expect the interface to be used but I'm not sure I can see it. Can you provide just some notional examples here in the discussion? Maybe that would help me make up my mind. @TheKidCoder could I impose on you to do the same.

I would like the implementation to support the usage and since I am not actually going to use it. I'm not sure I have a clear picture in my mind.