Class: Sportradar::Api::Basketball::Play::Base
- Defined in:
- lib/sportradar/api/basketball/plays/base.rb
Direct Known Subclasses
Assist, Block, Deadball, DefaultViolation, DefensiveGoalTending, DefensiveThreeSeconds, Delay, DoubleLane, Ejection, EndPeriod, Foul, Jumpball, JumpballViolation, Kickball, Lane, LineupChange, OpenInbound, Sportradar::Api::Basketball::Possession, Rebound, Review, ShotMade, ShotMiss, Steal, Stoppage, TechnicalFoul, Timeout, Turnover
Instance Attribute Summary collapse
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#description ⇒ Object
Returns the value of attribute description.
-
#event_type ⇒ Object
(also: #type)
Returns the value of attribute event_type.
-
#game_seconds ⇒ Object
Returns the value of attribute game_seconds.
-
#half ⇒ Object
Returns the value of attribute half.
-
#id ⇒ Object
Returns the value of attribute id.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#location ⇒ Object
Returns the value of attribute location.
-
#on_court ⇒ Object
Returns the value of attribute on_court.
-
#on_court_ids ⇒ Object
Returns the value of attribute on_court_ids.
-
#player_id ⇒ Object
Returns the value of attribute player_id.
-
#possession ⇒ Object
Returns the value of attribute possession.
-
#quarter ⇒ Object
Returns the value of attribute quarter.
-
#response ⇒ Object
Returns the value of attribute response.
-
#score ⇒ Object
Returns the value of attribute score.
-
#statistics ⇒ Object
Returns the value of attribute statistics.
-
#team_id ⇒ Object
Returns the value of attribute team_id.
-
#updated ⇒ Object
Returns the value of attribute updated.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #base_key ⇒ Object
- #clock_seconds ⇒ Object
-
#display_type ⇒ Object
def game quarter.game end.
- #end_of_ot? ⇒ Boolean
- #end_of_period? ⇒ Boolean
- #end_of_regulation? ⇒ Boolean
- #halftime? ⇒ Boolean
- #handle_on_court(data) ⇒ Object
- #handle_time(data, **opts) ⇒ Object
-
#initialize(data, **opts) ⇒ Base
constructor
A new instance of Base.
- #media_timeout? ⇒ Boolean
- #nba_game_seconds ⇒ Object
- #parse_statistics(data) ⇒ Object
- #period ⇒ Object
- #points ⇒ Object
- #quarter_break? ⇒ Boolean
- #scoring_play? ⇒ Boolean
- #timeout? ⇒ Boolean
- #update(data, **opts) ⇒ Object
Methods inherited from Data
#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data
Constructor Details
#initialize(data, **opts) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 9 def initialize(data, **opts) @response = data @api = opts[:api] @id = data['id'] @quarter = opts[:quarter].sequence.to_i rescue opts[:quarter].to_i @half = opts[:half].sequence.to_i rescue opts[:half].to_i update(data, **opts) end |
Instance Attribute Details
#clock ⇒ Object
Returns the value of attribute clock.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def clock @clock end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def description @description end |
#event_type ⇒ Object Also known as: type
Returns the value of attribute event_type.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def event_type @event_type end |
#game_seconds ⇒ Object
Returns the value of attribute game_seconds.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def game_seconds @game_seconds end |
#half ⇒ Object
Returns the value of attribute half.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def half @half end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def id @id end |
#identifier ⇒ Object
Returns the value of attribute identifier.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def identifier @identifier end |
#location ⇒ Object
Returns the value of attribute location.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def location @location end |
#on_court ⇒ Object
Returns the value of attribute on_court.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def on_court @on_court end |
#on_court_ids ⇒ Object
Returns the value of attribute on_court_ids.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def on_court_ids @on_court_ids end |
#player_id ⇒ Object
Returns the value of attribute player_id.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def player_id @player_id end |
#possession ⇒ Object
Returns the value of attribute possession.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def possession @possession end |
#quarter ⇒ Object
Returns the value of attribute quarter.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def quarter @quarter end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def response @response end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def score @score end |
#statistics ⇒ Object
Returns the value of attribute statistics.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def statistics @statistics end |
#team_id ⇒ Object
Returns the value of attribute team_id.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def team_id @team_id end |
#updated ⇒ Object
Returns the value of attribute updated.
6 7 8 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 6 def updated @updated end |
Instance Method Details
#==(other) ⇒ Object
64 65 66 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 64 def ==(other) id == other.id && description == other.description end |
#base_key ⇒ Object
56 57 58 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 56 def base_key nil end |
#clock_seconds ⇒ Object
68 69 70 71 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 68 def clock_seconds m,s = @clock.split(':') m.to_i * 60 + s.to_i end |
#display_type ⇒ Object
def game
quarter.game
end
28 29 30 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 28 def display_type '' end |
#end_of_ot? ⇒ Boolean
53 54 55 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 53 def end_of_ot? false end |
#end_of_period? ⇒ Boolean
47 48 49 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 47 def end_of_period? false end |
#end_of_regulation? ⇒ Boolean
50 51 52 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 50 def end_of_regulation? false end |
#halftime? ⇒ Boolean
44 45 46 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 44 def halftime? false end |
#handle_on_court(data) ⇒ Object
96 97 98 99 100 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 96 def handle_on_court(data) teams = [data['home'], data['away']] @on_court = teams.flat_map { |hash| hash['players'].map { |pl| OpenStruct.new(pl) } } @on_court_ids = @on_court.map(&:id) end |
#handle_time(data, **opts) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 102 def handle_time(data, **opts) @game_seconds = if opts[:quarter] @quarter = opts[:quarter].sequence.to_i rescue opts[:quarter].to_i @identifier = "#{quarter}_#{(720 - clock_seconds).to_s.rjust(3, '0')}".to_i nba_game_seconds elsif opts[:half] @half = opts[:half].sequence.to_i rescue opts[:half].to_i @identifier = "#{half}_#{(1200 - clock_seconds).to_s.rjust(4, '0')}".to_i ncaa_game_seconds end end |
#media_timeout? ⇒ Boolean
38 39 40 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 38 def media_timeout? false end |
#nba_game_seconds ⇒ Object
72 73 74 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 72 def nba_game_seconds ([quarter, 4].min * 720) + ([quarter - 4, 0].max * 300) - clock_seconds # seconds elapsed in game, only works for NBA end |
#parse_statistics(data) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 114 def parse_statistics(data) return unless data['statistics'] @statistics = data['statistics'] stat = @statistics.detect { |hash| hash['type'] == base_key } # stat = data.dig('statistics', base_key) rescue data.dig('statistics', 0, base_key) # stat = stat[0] if stat.is_a?(Array) # sometimes SR has an array of identical assist hashes @team = stat['team'] @team_id = @team['id'] if @team @player = stat['player'] @player_id = @player['id'] if @player rescue => e puts e # binding.pry end |
#period ⇒ Object
21 22 23 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 21 def period @quarter.nonzero? || @half.nonzero? end |
#points ⇒ Object
60 61 62 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 60 def points 0 end |
#quarter_break? ⇒ Boolean
41 42 43 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 41 def quarter_break? false end |
#scoring_play? ⇒ Boolean
32 33 34 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 32 def scoring_play? points.nonzero? end |
#timeout? ⇒ Boolean
35 36 37 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 35 def timeout? false end |
#update(data, **opts) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sportradar/api/basketball/plays/base.rb', line 80 def update(data, **opts) @event_type = data['event_type'] # "lineupchange", @clock = data['clock'] # "12:00", @updated = Time.parse(data['updated']) if data['updated'] # "2016-10-26T00:07:52+00:00", @description = data['description'] # "Cavaliers lineup change (Richard Jefferson, Kyrie Irving, Mike Dunleavy, Channing Frye, LeBron James)", @attribution = data['attribution'] # {"name"=>"Cavaliers", "market"=>"Cleveland", "id"=>"583ec773-fb46-11e1-82cb-f4ce4684ea4c", "team_basket"=>"left"}, @team_id = data.dig('attribution', "id") @location = data['location'] # {"coord_x"=>"0", "coord_y"=>"0"}, @possession = data['possession'] # {"name"=>"Knicks", "market"=>"New York", "id"=>"583ec70e-fb46-11e1-82cb-f4ce4684ea4c"}, # @on_court = data['on_court'] # hash handle_on_court(data['on_court']) if data['on_court'] handle_time(data, **opts) parse_statistics(data) if data['statistics'] end |