Skip to content

Commit

Permalink
Merge 5bf2f7f into 3b5a8dc
Browse files Browse the repository at this point in the history
  • Loading branch information
Timbinous committed Oct 25, 2016
2 parents 3b5a8dc + 5bf2f7f commit 3f07493
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
sportradar-api (0.9.8)
sportradar-api (0.9.9)
activesupport
httparty (>= 0.14.0)

Expand Down
1 change: 1 addition & 0 deletions lib/sportradar/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
require "sportradar/api/nfl/injury"
require "sportradar/api/nfl/league_depth_chart"
require "sportradar/api/nfl/play"
require "sportradar/api/nfl/play_statistics"
require "sportradar/api/nfl/player"
require "sportradar/api/nfl/position"
require "sportradar/api/nfl/quarter"
Expand Down
3 changes: 1 addition & 2 deletions lib/sportradar/api/football/stat_pack/passing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def set_stats
@attempts = response["attempts"]
@completions = response["completions"]
@cmp_pct = response["cmp_pct"]
# @yards = response["yards"] # 'yards' is air yards, which does not include sack yardage. air_yards is for college, net_yards for NFL
@yards = response["yards"] # 'yards' is air yards, which does not include sack yardage. air_yards is for college, net_yards for NFL
@avg_yards = response["avg_yards"]
@sacks = response["sacks"]
@sack_yards = response["sack_yards"]
Expand All @@ -18,7 +18,6 @@ def set_stats
@longest_touchdown = response["longest_touchdown"]
@air_yards = response["air_yards"]
@net_yards = response["net_yards"] # passing net_yards is the correct measure for team stats, as it includes sack yardage
@yards = response["net_yards"] # should look further into this, make sure this isn't a bad idea
@redzone_attempts = response["redzone_attempts"]
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sportradar/api/nfl/play.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(data)
@scoring_play = data["scoring_play"]
@sequence = data["sequence"]
@start_situation = Sportradar::Api::Nfl::Situation.new data["start_situation"] if data["start_situation"]
@statistics = OpenStruct.new data["statistics"] if data["statistics"] # TODO Implement statistics!
@statistics = Sportradar::Api::Nfl::PlayStatistics.new data["statistics"] if data["statistics"]
parse_player if @statistics
@type = data["type"]
@wall_clock = data["wall_clock"]
Expand All @@ -31,7 +31,7 @@ def parse_player
if play_stats.is_a?(Array)
play_stats = play_stats.first
end
@player_id = play_stats.dig('player', 'id') if play_stats
@player_id = play_stats&.player&.id if play_stats
end

end
Expand Down
246 changes: 246 additions & 0 deletions lib/sportradar/api/nfl/play_statistics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
module Sportradar
module Api
class Nfl::PlayStatistics < Data
attr_accessor :response, :kick, :return, :rush, :defense, :receive, :punt, :penalty, :pass, :first_down, :field_goal, :extra_point, :defense, :down_conversion
def initialize(data)
@response = data
@kick = Nfl::PlayKickStatistics.new(data['kick']) if data['kick']
@return = Nfl::PlayReturnStatistics.new(data['return']) if data['return']
@rush = parse_into_array(selector: data['rush'], klass: Nfl::PlayRushStatistics) if data['rush']
@defense = parse_into_array(selector: data['defense'], klass: Nfl::PlayDefenseStatistics) if data['defense']
@receive = Nfl::PlayReceiveStatistics.new(data['receive']) if data['receive']
@punt = Nfl::PlayPuntStatsitics.new(data['punt']) if data['punt']
@penalty = Nfl::PlayPenaltyStatistics.new(data['penalty']) if data['penalty']
@pass = Nfl::PlayPassingStatistics.new(data['pass']) if data['pass']
@first_down = parse_into_array(selector: data['first_down'], klass: Nfl::PlayFirstDownStatistics) if data['first_down']
@field_goal = Nfl::PlayFieldGoalStatistics.new(data['field_goal']) if data['field_goal']
@extra_point = Nfl::PlayExtraPointStatistics.new(data['extra_point']) if data['extra_point']
@down_conversion = Nfl::PlayDownConversionStatistics.new(data['down_conversion']) if data['down_conversion']
end
end

class Nfl::PlayDownConversionStatistics < Data
attr_accessor :attempt, :complete, :down, :nullified, :team
def initialize(data)
@attempt = data['attempt']
@complete = data['complete']
@down = data['down']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayDefenseStatistics < Data
attr_accessor :ast_tackle, :interception, :int_yards, :nullified, :pass_defended, :primary, :qb_hit, :sack, :sack_yards, :tlost, :tlost_yards, :team, :player, :tackle
def initialize(data)
@ast_tackle = data['ast_tackle']
@interception = data['interception']
@int_yards = data['int_yards']
@nullified = data['nullified']
@pass_defended = data['pass_defended']
@primary = data['primary']
@qb_hit = data['qb_hit']
@sack = data['sack']
@sack_yards = data['sack_yards']
@tlost = data['tlost']
@tlost_yards = data['tlost_yards']
@tackle = data['tackle']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayExtraPointStatistics < Data
attr_accessor :attempt, :nullified
def initialize(data)
@attempt = data['attempt']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayFieldGoalStatistics < Data
attr_accessor :attempt, :att_yards, :missed, :yards, :nullified, :blocked, :team, :player
def initialize(data)
@attempt = data['attempt']
@att_yards = data['att_yards']
@missed = data['missed']
@blocked = data['blocked']
@yards = data['yards']
@nullified = data['nullified']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayFirstDownStatistics < Data
attr_accessor :category, :nullified, :team
def initialize(data)
@category = data['category']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayPassingStatistics < Data
attr_accessor :attempt, :att_yards, :complete, :firstdown, :goaltogo, :inside_20, :interception, :sack, :sack_yards, :touchdown, :yards, :nullified, :team, :player
def initialize(data)
@attempt = data['attempt']
@att_yards = data['att_yards']
@complete = data['complete']
@firstdown = data['firstdown']
@goaltogo = data['goaltogo']
@inside_20 = data['inside_20']
@interception = data['interception']
@sack = data['sack']
@sack_yards = data['sack_yards']
@touchdown = data['touchdown']
@yards = data['yards']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayPenaltyStatistics < Data
attr_accessor :penalty, :yards, :nullified, :team, :player
def initialize(data)
@penalty = data['penalty'] if data['penalty']
@yards = data['yards'] if data['yards']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayPuntStatsitics < Data
attr_accessor :attempt, :downed, :faircatch, :inside_20, :out_of_bounds, :touchback, :yards, :nullified, :team, :player
def initialize(data)
@attempt = data['attempt']
@downed = data['downed']
@inside_20 = data['inside_20']
@out_of_bounds = data['out_of_bounds']
@touchback = data['touchback']
@yards = data['yards']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayReceiveStatistics < Data
attr_accessor :firstdown, :goaltogo, :inside_20, :reception, :target, :touchdown, :yards, :yards_after_catch, :nullified, :team, :player
def initialize(data)
@firstdown = data['firstdown']
@goaltogo = data['goaltogo']
@inside_20 = data['inside_20']
@reception = data['reception']
@target = data['target']
@touchdown = data['touchdown']
@yards = data['yards']
@yards_after_catch = data['yards_after_catch']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayRushStatistics < Data
attr_accessor :attempt, :firstdown, :tlost, :tlost_yards, :yards, :inside_20, :goal_to_go, :team, :player, :nullified, :touchdown
def initialize(data)
@attempt = data['attempt']
@firstdown = data['firstdown']
@goal_to_go = data['goal_to_go']
@inside_20 = data['inside_20']
@tlost = data['tlost']
@tlost_yards = data['tlost_yards']
@touchdown = data['touchdown']
@yards = data['yards']

@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end


class Nfl::PlayKickStatistics < Data
attr_accessor :attempt, :yards, :gross_yards, :touchback, :team, :player, :endzone, :inside_20, :nullified
def initialize(data)
@endzone = data['endzone']
@inside_20 = data['inside_20']
@attempt = data['attempt']
@yards = data['yards']
@gross_yards = data['gross_yards']
@touchback = data['touchback']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end

class Nfl::PlayReturnStatistics < Data
attr_accessor :category, :downed, :faircatch, :out_of_bounds, :return, :touchback, :yards, :team, :nullified, :player
def initialize(data)
@category = data['category']
@downed = data['downed']
@faircatch = data['faircatch']
@out_of_bounds = data['out_of_bounds']
@return = data['return']
@touchback = data['touchback']
@yards = data['yards']
@team = Sportradar::Api::Nfl::Team.new(data['team']) if data['team']
@player = Nfl::Player.new(data['player']) if data['player']
@nullified = data['nullified']
end

def nullified?
@nullified.to_s == 'true'
end
end
end
end
11 changes: 10 additions & 1 deletion lib/sportradar/api/nfl/quarter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Sportradar
module Api
class Nfl::Quarter < Data
attr_accessor :response, :id, :number, :sequence, :home_points, :away_points, :drives
attr_accessor :response, :id, :number, :sequence, :home_points, :away_points, :drives, :scoring

def initialize(data)
@response = data
Expand All @@ -13,8 +13,17 @@ def initialize(data)
@away_points = data["away_points"]
# @away_points = response['scoring']['away']['points'] # from play_by_play
@drives = parse_into_array(selector: response["play_by_play"]["drive"], klass: Sportradar::Api::Nfl::Drive) if response["play_by_play"] && response["play_by_play"]["drive"]
@scoring = Nfl::QuarterScoring.new(data['scoring']) if data['scoring']
end

end

class Nfl::QuarterScoring < Data
attr_accessor :home, :away
def initialize(data)
@home = OpenStruct.new(data['home'])
@away = OpenStruct.new(data['away'])
end
end
end
end
Loading

0 comments on commit 3f07493

Please sign in to comment.