lib/sportradar/api/football/play_statistics.rb in sportradar-api-0.11.29 vs lib/sportradar/api/football/play_statistics.rb in sportradar-api-0.11.30
- old
+ new
@@ -4,10 +4,19 @@
class 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)
data = [data] if data.is_a?(Hash)
@response = data
+ if data.first['name'] # indicates college data structures. we want to convert it to nfl data structures
+ data.map! do |hash|
+ type = self.class.college_type_translations.each_key.detect { |str| hash.key?(str) }
+ binding.pry if type.nil?
+ stats = hash.delete(type)
+ new_team = { 'id' => hash['team'], 'alias' => hash['team'] } # use intermediate variable to avoid temp memory blowup
+ new_hash = { 'player' => hash, 'team' => new_team, 'stat_type' => self.class.college_type_translations[type] }.merge(stats)
+ end
+ end
data.each do |hash|
var = instance_variable_get("@#{hash['stat_type']}")
unless var
instance_variable_set("@#{hash['stat_type']}", [])
var = instance_variable_get("@#{hash['stat_type']}")
@@ -25,10 +34,31 @@
def players_by_team
@players_by_team ||= players.group_by(&:team)
end
+ def self.college_type_translations
+ @college_type_translations ||= {
+ "kickoffs" => 'kick',
+ "kick_return" => 'return',
+ "rushing" => 'rush',
+ "fumble" => 'fumble',
+ "defense" => 'defense',
+ "receiving" => 'receive',
+ "punting" => 'punt',
+ "penalty" => 'penalty',
+ "passing" => 'pass',
+ "field_goal" => 'field_goal',
+ "extra_point" => 'extra_point',
+ "blocked_field_goal_return" => 'block',
+ "interception_return" => 'return',
+ "fumble_return" => 'return',
+ "punt_return" => 'return',
+ 'misc' => 'misc',
+ }.freeze
+ end
+
def self.stat_type_classes
@stat_type_classes ||= {
'kick' => PlayKickStatistics,
'return' => PlayReturnStatistics,
'rush' => PlayRushStatistics,
@@ -50,29 +80,32 @@
end
class MiscStatistics < Data
attr_reader :team, :player, :yards
def initialize(data)
- @yards = data['yards']
+ @response = data
+ @yards = data['yards'] || data['yds']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
end
end
class BlockStatistics < Data
attr_reader :team, :player, :block, :category
def initialize(data)
+ @response = data
@category = data['category']
- @block = data['block']
+ @block = data['block'] || data['blk']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
end
end
class PlayDownConversionStatistics < Data
attr_accessor :attempt, :complete, :down, :nullified, :team, :player
def initialize(data)
+ @response = data
@attempt = data['attempt']
@complete = data['complete']
@down = data['down']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@@ -85,10 +118,11 @@
end
class PlayDefenseStatistics < Data
attr_accessor :ast_tackle, :interception, :int_yards, :nullified, :pass_defended, :primary, :qb_hit, :sack, :sack_yards, :tlost, :tlost_yards, :team, :player, :tackle, :int_touchdown
def initialize(data)
+ @response = data
@ast_tackle = data['ast_tackle']
@interception = data['interception']
@int_yards = data['int_yards']
@int_touchdown = data['int_touchdown']
@nullified = data['nullified']
@@ -111,10 +145,11 @@
end
class PlayExtraPointStatistics < Data
attr_accessor :attempt, :nullified
def initialize(data)
+ @response = data
@attempt = data['attempt']
@nullified = data['nullified']
end
def nullified?
@@ -123,15 +158,17 @@
end
class PlayFieldGoalStatistics < Data
attr_accessor :attempt, :att_yards, :missed, :yards, :nullified, :blocked, :team, :player
def initialize(data)
- @attempt = data['attempt']
+ "att"=>1, "made"=>1, "yds"=>17, "att_yds"=>17, "blk"=>0, "ret"=>0}
+ @response = data
+ @attempt = data['attempt'] || data['att']
@att_yards = data['att_yards']
- @missed = data['missed']
- @blocked = data['blocked']
- @yards = data['yards']
+ @missed = data['missed'] || (data['made'] - 1).abs
+ @blocked = data['blocked'] || data['blk']
+ @yards = data['yards'] || data['yds']
@nullified = data['nullified']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
end
@@ -141,10 +178,11 @@
end
class PlayFirstDownStatistics < Data
attr_accessor :category, :nullified, :team
def initialize(data)
+ @response = data
@category = data['category']
@team = OpenStruct.new(data['team']) if data['team']
@nullified = data['nullified']
end
@@ -154,21 +192,22 @@
end
class 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']
+ @response = data
+ @attempt = data['attempt'] || data['att']
@att_yards = data['att_yards']
- @complete = data['complete']
- @firstdown = data['firstdown']
+ @complete = data['complete'] || data['cmp']
+ @firstdown = data['firstdown'] || data['fd']
@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']
+ @inside_20 = data['inside_20'] || data['rz_att']
+ @interception = data['interception'] || data['int']
+ @sack = data['sack'] || data['sk']
+ @sack_yards = data['sack_yards'] || data['sk_yds']
+ @touchdown = data['touchdown'] || data['td']
+ @yards = data['yards'] || data['yds']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
@@ -176,14 +215,16 @@
@nullified.to_s == 'true'
end
end
class PlayPenaltyStatistics < Data
- attr_accessor :penalty, :yards, :nullified, :team, :player
+ attr_accessor :penalty, :yards, :nullified, :team, :player, :first_down
def initialize(data)
- @penalty = data['penalty'] if data['penalty']
- @yards = data['yards'] if data['yards']
+ @response = data
+ @penalty = data['penalty'] || data['abbr'] # unsure about abbr here
+ @yards = data['yards'] || data['yds']
+ @first_down = data['fd']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
@@ -193,17 +234,19 @@
end
class PlayPuntStatistics < Data
attr_accessor :attempt, :downed, :faircatch, :inside_20, :out_of_bounds, :touchback, :yards, :nullified, :team, :player
def initialize(data)
+ @response = data
data = data.first if data.is_a?(Array)
- @attempt = data['attempt']
+ @attempt = data['attempt'] || data['punts']
@downed = data['downed']
- @inside_20 = data['inside_20']
+ @inside_20 = data['inside_20'] || data['in20']
@out_of_bounds = data['out_of_bounds']
- @touchback = data['touchback']
- @yards = data['yards']
+ @touchback = data['touchback'] || data['tb']
+ @yards = data['yards'] || data['yds']
+ @blocked = data['blk']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
@@ -213,18 +256,19 @@
end
class PlayReceiveStatistics < Data
attr_accessor :firstdown, :goaltogo, :inside_20, :reception, :target, :touchdown, :yards, :yards_after_catch, :nullified, :team, :player
def initialize(data)
- @firstdown = data['firstdown']
+ @response = data
+ @firstdown = data['firstdown'] || data['fd']
@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']
+ @inside_20 = data['inside_20'] || data['rz_tar']
+ @reception = data['reception'] || data['rec']
+ @target = data['target'] || data['tar']
+ @touchdown = data['touchdown'] || data['td']
+ @yards = data['yards'] || data['yds']
+ @yards_after_catch = data['yards_after_catch'] || data['yac']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
@@ -234,10 +278,11 @@
end
class PlayFumbleStatistics < Data
attr_reader :own_rec, :own_rec_yards, :forced, :team, :player
def initialize(data)
+ @response = data
@own_rec = data['own_rec']
@own_rec_yards = data['own_rec_yards']
@forced = data['forced']
@team = OpenStruct.new(data['team']) if data['team']
@@ -246,18 +291,19 @@
end
class 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']
+ @response = data
+ @attempt = data['attempt'] || data['att']
+ @firstdown = data['firstdown'] || data['fd']
@goal_to_go = data['goal_to_go']
- @inside_20 = data['inside_20']
+ @inside_20 = data['inside_20'] || data['rz_att']
@tlost = data['tlost']
@tlost_yards = data['tlost_yards']
- @touchdown = data['touchdown']
- @yards = data['yards']
+ @touchdown = data['touchdown'] || data['td']
+ @yards = data['yards'] || data['yds']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
@@ -269,16 +315,18 @@
class PlayKickStatistics < Data
attr_accessor :attempt, :yards, :gross_yards, :touchback, :team, :player, :endzone, :inside_20, :nullified
def initialize(data)
+ @response = data
@endzone = data['endzone']
- @inside_20 = data['inside_20']
- @attempt = data['attempt']
- @yards = data['yards']
- @gross_yards = data['gross_yards']
- @touchback = data['touchback']
+ @inside_20 = data['inside_20'] || data['in20']
+ @attempt = data['attempt'] || data['kicks']
+ @returned = data['ret']
+ @yards = data['yards'] || data['yds']
+ @gross_yards = data['gross_yards'] || data['net_yds']
+ @touchback = data['touchback'] || data['tb']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
@@ -288,10 +336,11 @@
end
class ConversionStatistics < Data
attr_reader :stat_type, :attempt, :complete, :category, :player, :team
def initialize(data)
+ @response = data
@stat_type = data['stat_type']
@attempt = data['attempt']
@complete = data['complete']
@category = data['category']
@team = OpenStruct.new(data['team']) if data['team']
@@ -300,17 +349,18 @@
end
class PlayReturnStatistics < Data
attr_accessor :category, :downed, :faircatch, :out_of_bounds, :return, :touchback, :yards, :team, :nullified, :player, :touchdown
def initialize(data)
+ @response = data
@category = data['category']
@downed = data['downed']
- @faircatch = data['faircatch']
+ @faircatch = data['faircatch'] || data['fc']
@out_of_bounds = data['out_of_bounds']
- @return = data['return']
- @touchback = data['touchback']
- @touchdown = data['touchdown']
- @yards = data['yards']
+ @return = data['return'] || data['returns']
+ @touchback = data['touchback'] || data['tb']
+ @touchdown = data['touchdown'] || data['td']
+ @yards = data['yards'] || data['yds']
@team = OpenStruct.new(data['team']) if data['team']
@player = OpenStruct.new(data['player']) if data['player']
@nullified = data['nullified']
end
\ No newline at end of file