sportradar-api 0.13.0 → 0.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sportradar/api/baseball/game.rb +1 -1
- data/lib/sportradar/api/basketball/game.rb +5 -4
- data/lib/sportradar/api/basketball/nba/game.rb +1 -1
- data/lib/sportradar/api/basketball/nba/quarter.rb +9 -2
- data/lib/sportradar/api/basketball/ncaamb/game.rb +1 -1
- data/lib/sportradar/api/basketball/ncaamb/half.rb +9 -0
- data/lib/sportradar/api/basketball/play.rb +1 -0
- data/lib/sportradar/api/basketball/plays/jumpball_violation.rb +11 -0
- data/lib/sportradar/api/basketball/plays.rb +1 -0
- data/lib/sportradar/api/football/ncaafb/game.rb +1 -1
- data/lib/sportradar/api/football/nfl/game.rb +1 -1
- data/lib/sportradar/api/soccer/README.md +4 -0
- data/lib/sportradar/api/soccer/event.rb +14 -13
- data/lib/sportradar/api/soccer/match.rb +130 -4
- data/lib/sportradar/api/soccer/player.rb +8 -2
- data/lib/sportradar/api/soccer/scoring.rb +71 -0
- data/lib/sportradar/api/soccer/team.rb +7 -2
- data/lib/sportradar/api/soccer/tournament.rb +21 -2
- data/lib/sportradar/api/soccer.rb +1 -0
- data/lib/sportradar/api/version.rb +1 -1
- metadata +5 -29
- data/lib/sportradar/api/soccer-old/boxscore.rb +0 -13
- data/lib/sportradar/api/soccer-old/category.rb +0 -17
- data/lib/sportradar/api/soccer-old/fact.rb +0 -61
- data/lib/sportradar/api/soccer-old/hierarchy.rb +0 -14
- data/lib/sportradar/api/soccer-old/match.rb +0 -55
- data/lib/sportradar/api/soccer-old/player.rb +0 -88
- data/lib/sportradar/api/soccer-old/ranking.rb +0 -13
- data/lib/sportradar/api/soccer-old/schedule.rb +0 -22
- data/lib/sportradar/api/soccer-old/season.rb +0 -14
- data/lib/sportradar/api/soccer-old/standing.rb +0 -13
- data/lib/sportradar/api/soccer-old/statistic.rb +0 -14
- data/lib/sportradar/api/soccer-old/summary.rb +0 -13
- data/lib/sportradar/api/soccer-old/team.rb +0 -63
- data/lib/sportradar/api/soccer-old/tournament.rb +0 -20
- data/lib/sportradar/api/soccer-old/tournament_group.rb +0 -35
- data/lib/sportradar/api/soccer-old/venue.rb +0 -21
- data/lib/sportradar/api/soccer-old.rb +0 -158
- data/soccer-old/boxscore_test.rb +0 -14
- data/soccer-old/hierarchy_test.rb +0 -14
- data/soccer-old/match_test.rb +0 -23
- data/soccer-old/player_test.rb +0 -40
- data/soccer-old/ranking_test.rb +0 -16
- data/soccer-old/schedule_test.rb +0 -24
- data/soccer-old/standing_test.rb +0 -14
- data/soccer-old/summary_test.rb +0 -14
- data/soccer-old/team_test.rb +0 -21
- data/soccer-old_test.rb +0 -184
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3d49ce56fe5c2ca03df70263e5b216efe58d4fbb
|
|
4
|
+
data.tar.gz: 65d90cefb754021c67c6dda94fa53fb4f8ad33d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43ac236b4a45c7178c929036d25a4ae99340bc8e8710a4307e9f7d5791079b5e547aca9757c11ee6ae44e525c786c35687db9140474e7c90dc23e48c164c25f6
|
|
7
|
+
data.tar.gz: 9ccedccca1160d5725a5553ea5b327884ffcae3cf11548910b5fcdd8e93dff9998fd250f371665d275bf35393cbdf3b79494c32cb17d4068c3b3716aff5b2f5e
|
data/Gemfile.lock
CHANGED
|
@@ -212,7 +212,7 @@ module Sportradar
|
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
def halftime?
|
|
215
|
-
clock == '
|
|
215
|
+
status == 'halftime' || clock == '00:00' && quarter == 2
|
|
216
216
|
end
|
|
217
217
|
def clock_display
|
|
218
218
|
if clock && period
|
|
@@ -266,7 +266,7 @@ module Sportradar
|
|
|
266
266
|
# data retrieval
|
|
267
267
|
|
|
268
268
|
def get_box
|
|
269
|
-
data = api.get_data(path_box)
|
|
269
|
+
data = api.get_data(path_box).to_h
|
|
270
270
|
ingest_box(data)
|
|
271
271
|
end
|
|
272
272
|
|
|
@@ -283,7 +283,7 @@ module Sportradar
|
|
|
283
283
|
end
|
|
284
284
|
|
|
285
285
|
def get_pbp
|
|
286
|
-
data = api.get_data(path_pbp)
|
|
286
|
+
data = api.get_data(path_pbp).to_h
|
|
287
287
|
ingest_pbp(data)
|
|
288
288
|
end
|
|
289
289
|
|
|
@@ -305,12 +305,13 @@ module Sportradar
|
|
|
305
305
|
set_pbp(period_data)
|
|
306
306
|
@pbp = @periods_hash.values
|
|
307
307
|
check_newness(:pbp, plays.last&.updated)
|
|
308
|
+
check_newness(:clock, @clock)
|
|
308
309
|
check_newness(:score, @score)
|
|
309
310
|
data
|
|
310
311
|
end
|
|
311
312
|
|
|
312
313
|
def get_summary
|
|
313
|
-
data = api.get_data(path_summary)
|
|
314
|
+
data = api.get_data(path_summary).to_h
|
|
314
315
|
ingest_summary(data)
|
|
315
316
|
end
|
|
316
317
|
|
|
@@ -33,8 +33,15 @@ module Sportradar
|
|
|
33
33
|
end
|
|
34
34
|
def update(data, **opts)
|
|
35
35
|
create_data(@plays_hash, data.dig('events'), klass: Play, api: @api, quarter: self)
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def plays_by_type(play_type, *types)
|
|
39
|
+
if types.empty?
|
|
40
|
+
plays.grep(Play.subclass(play_type.delete('_')))
|
|
41
|
+
else
|
|
42
|
+
play_classes = [play_type, *types].map { |type| Play.subclass(type.delete('_')) }
|
|
43
|
+
plays.select { |play| play_classes.any? { |klass| play.kind_of?(klass) } }
|
|
44
|
+
end
|
|
38
45
|
end
|
|
39
46
|
|
|
40
47
|
def plays
|
|
@@ -35,6 +35,15 @@ module Sportradar
|
|
|
35
35
|
create_data(@plays_hash, data.dig('events'), klass: Play, api: @api, half: self)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
def plays_by_type(play_type, *types)
|
|
39
|
+
if types.empty?
|
|
40
|
+
plays.grep(Play.subclass(play_type.delete('_')))
|
|
41
|
+
else
|
|
42
|
+
play_classes = [play_type, *types].map { |type| Play.subclass(type.delete('_')) }
|
|
43
|
+
plays.select { |play| play_classes.any? { |klass| play.kind_of?(klass) } }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
38
47
|
def plays
|
|
39
48
|
@plays_hash.values
|
|
40
49
|
end
|
|
@@ -38,6 +38,7 @@ require_relative 'plays/flagrant_two'
|
|
|
38
38
|
require_relative 'plays/delay'
|
|
39
39
|
require_relative 'plays/ejection'
|
|
40
40
|
require_relative 'plays/default_violation'
|
|
41
|
+
require_relative 'plays/jumpball_violation'
|
|
41
42
|
require_relative 'plays/defensive_goal_tending'
|
|
42
43
|
require_relative 'plays/double_lane'
|
|
43
44
|
require_relative 'plays/lane'
|
|
@@ -12,18 +12,19 @@ module Sportradar
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def update(data, **opts)
|
|
15
|
-
@type = data['type']
|
|
16
|
-
@time = Time.parse(data['time'])
|
|
17
|
-
@period = data['period']
|
|
18
|
-
@period_type = data['period_type']
|
|
19
|
-
@period_name = data['period_name']
|
|
20
|
-
@match_time = data['match_time']
|
|
21
|
-
@team = data['team']
|
|
22
|
-
@x = data['x']
|
|
23
|
-
@y = data['y']
|
|
24
|
-
@outcome = data['outcome']
|
|
25
|
-
@home_score = data['home_score']
|
|
26
|
-
@away_score = data['away_score']
|
|
15
|
+
@type = data['type'] if data['type']
|
|
16
|
+
@time = Time.parse(data['time']) if data['time']
|
|
17
|
+
@period = data['period'] if data['period']
|
|
18
|
+
@period_type = data['period_type'] if data['period_type']
|
|
19
|
+
@period_name = data['period_name'] if data['period_name']
|
|
20
|
+
@match_time = data['match_time'] if data['match_time']
|
|
21
|
+
@team = data['team'] if data['team']
|
|
22
|
+
@x = data['x'] if data['x']
|
|
23
|
+
@y = data['y'] if data['y']
|
|
24
|
+
@outcome = data['outcome'] if data['outcome']
|
|
25
|
+
@home_score = data['home_score'] if data['home_score']
|
|
26
|
+
@away_score = data['away_score'] if data['away_score']
|
|
27
|
+
@commentaries = data['commentaries'] if data['commentaries']
|
|
27
28
|
@goal_scorer = OpenStruct.new(data['goal_scorer']) if data['goal_scorer']
|
|
28
29
|
@stoppage_time = data['stoppage_time'].to_i if data['stoppage_time']
|
|
29
30
|
@player_out = OpenStruct.new(data['player_out']) if data['player_out']
|
|
@@ -31,7 +32,7 @@ module Sportradar
|
|
|
31
32
|
@player = OpenStruct.new(data['player']) if data['player'] # red/yellow cards
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
def
|
|
35
|
+
def updated
|
|
35
36
|
@time
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -6,17 +6,22 @@ module Sportradar
|
|
|
6
6
|
attr_reader :home_score, :away_score, :winner_id, :aggregate_home_score, :aggregate_away_score, :aggregate_winner_id
|
|
7
7
|
attr_reader :referee, :weather_info, :coverage_info, :probabilities
|
|
8
8
|
attr_reader :home, :away, :tournament_id
|
|
9
|
+
attr_reader :period, :score, :broadcast, :coverage # these are for consistency with other sports
|
|
10
|
+
attr_reader :match_time, :stoppage_time
|
|
9
11
|
|
|
10
12
|
def initialize(data = {}, league_group: nil, **opts)
|
|
11
13
|
@response = data
|
|
12
14
|
@id = data['id']
|
|
13
15
|
@api = opts[:api]
|
|
16
|
+
@updates = {}
|
|
17
|
+
@changes = {}
|
|
14
18
|
|
|
15
19
|
@league_group = league_group || data['league_group'] || @api&.league_group
|
|
16
20
|
|
|
17
21
|
@timeline_hash = {}
|
|
18
22
|
@lineups_hash = {}
|
|
19
23
|
get_tournament_id(data, **opts)
|
|
24
|
+
@scoring_raw = Scoring.new(data, game: self)
|
|
20
25
|
@home = Team.new({}, api: api, match: self)
|
|
21
26
|
@away = Team.new({}, api: api, match: self)
|
|
22
27
|
@teams_hash = { away: @away, home: @home }
|
|
@@ -47,7 +52,6 @@ module Sportradar
|
|
|
47
52
|
update_teams(stats)
|
|
48
53
|
end
|
|
49
54
|
|
|
50
|
-
|
|
51
55
|
@scheduled = Time.parse(data['scheduled']) if data['scheduled']
|
|
52
56
|
@start_time_tbd = data['start_time_tbd'] if data.key?('start_time_tbd')
|
|
53
57
|
@status = data['status'] if data['status']
|
|
@@ -60,14 +64,18 @@ module Sportradar
|
|
|
60
64
|
|
|
61
65
|
@home_score = data['home_score'] if data['home_score']
|
|
62
66
|
@away_score = data['away_score'] if data['away_score']
|
|
67
|
+
@period = data['period'] if data['period']
|
|
68
|
+
@match_time = data.dig('clock', 'match_time') if data.dig('clock', 'match_time')
|
|
69
|
+
@stoppage_time = data.dig('clock', 'stoppage_time') if data.dig('clock', 'stoppage_time')
|
|
70
|
+
@ball_locations = data['ball_locations'] if data['ball_locations']
|
|
63
71
|
@winner_id = data['winner_id'] if data['winner_id']
|
|
64
72
|
|
|
65
73
|
@aggregate_home_score = data['aggregate_home_score'] if data['aggregate_home_score']
|
|
66
74
|
@aggregate_away_score = data['aggregate_away_score'] if data['aggregate_away_score']
|
|
67
75
|
@aggregate_winner_id = data['aggregate_winner_id'] if data['aggregate_winner_id']
|
|
76
|
+
@scoring_raw.update(data, source: opts[:source])
|
|
68
77
|
create_data(@timeline_hash, data['timeline'], klass: Event, api: api)
|
|
69
|
-
|
|
70
|
-
# @tournament
|
|
78
|
+
|
|
71
79
|
if data['competitors']
|
|
72
80
|
update_teams(data['competitors'])
|
|
73
81
|
end
|
|
@@ -75,6 +83,96 @@ module Sportradar
|
|
|
75
83
|
# parse_nested_data(data)
|
|
76
84
|
end
|
|
77
85
|
|
|
86
|
+
def title
|
|
87
|
+
[@home, @away].compact.map(&:name).join(' vs ')
|
|
88
|
+
end
|
|
89
|
+
def scoring
|
|
90
|
+
@scoring_raw.scores.each { |period, hash| hash[@home.id] = hash['home']; hash[@away.id] = hash['away'] }
|
|
91
|
+
end
|
|
92
|
+
def score
|
|
93
|
+
{@home.id => @home_score, @away.id => @away_score}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# status helpers
|
|
97
|
+
def realtime_state_short
|
|
98
|
+
if future?
|
|
99
|
+
'Scheduled' # ??
|
|
100
|
+
elsif finished?
|
|
101
|
+
'FT'
|
|
102
|
+
elsif postponed?
|
|
103
|
+
'PPD'
|
|
104
|
+
elsif halftime?
|
|
105
|
+
'HT'
|
|
106
|
+
else
|
|
107
|
+
clock_display
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def realtime_state
|
|
112
|
+
if future?
|
|
113
|
+
'Scheduled'
|
|
114
|
+
elsif finished?
|
|
115
|
+
'Final'
|
|
116
|
+
elsif postponed?
|
|
117
|
+
'Postponed'
|
|
118
|
+
elsif halftime?
|
|
119
|
+
'Halftime'
|
|
120
|
+
else
|
|
121
|
+
clock_display
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def halftime?
|
|
126
|
+
@match_status == "halftime"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def postponed?
|
|
130
|
+
'postponed' == status
|
|
131
|
+
end
|
|
132
|
+
def unnecessary?
|
|
133
|
+
'unnecessary' == status
|
|
134
|
+
end
|
|
135
|
+
def cancelled?
|
|
136
|
+
['unnecessary', 'postponed'].include? status
|
|
137
|
+
end
|
|
138
|
+
def future?
|
|
139
|
+
['not_started', 'scheduled', 'delayed', 'created', 'time-tbd', 'if-necessary'].include? status
|
|
140
|
+
end
|
|
141
|
+
def started?
|
|
142
|
+
['live'].include?(@status) || ['halftime', '1st_half', '2nd_half'].include?(@match_status)
|
|
143
|
+
end
|
|
144
|
+
def finished?
|
|
145
|
+
['complete', 'closed'].include?(@status) || ['ended'].include?(@match_status)
|
|
146
|
+
end
|
|
147
|
+
def completed?
|
|
148
|
+
'complete' == status
|
|
149
|
+
end
|
|
150
|
+
def closed?
|
|
151
|
+
'closed' == status
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def clock_display
|
|
155
|
+
if @match_time == '45:00' || @match_time == '90:00' # stoppage time
|
|
156
|
+
@match_time.split(':').first + ?'
|
|
157
|
+
else
|
|
158
|
+
@match_time.split(':').first + ?'
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
alias :clock :clock_display
|
|
162
|
+
|
|
163
|
+
def match_seconds
|
|
164
|
+
return nil unless @match_time
|
|
165
|
+
mm, ss = @match_time.split(':').map(&:to_i)
|
|
166
|
+
time = mm * 60 + ss
|
|
167
|
+
if @match_time == '45:00' || @match_time == '90:00' # stoppage time
|
|
168
|
+
mm, ss = @stoppage_time.split(':').map(&:to_i)
|
|
169
|
+
stop_time = mm * 60 + ss
|
|
170
|
+
time += stop_time
|
|
171
|
+
end
|
|
172
|
+
time
|
|
173
|
+
end
|
|
174
|
+
alias :game_seconds :match_seconds
|
|
175
|
+
|
|
78
176
|
def update_teams(data)
|
|
79
177
|
home_hash = data.detect { |team_hash| team_hash["qualifier"] == "home" || team_hash["team"] == "home" }
|
|
80
178
|
away_hash = (data - [home_hash]).first
|
|
@@ -200,7 +298,9 @@ module Sportradar
|
|
|
200
298
|
ingest_timeline(data)
|
|
201
299
|
end
|
|
202
300
|
def ingest_timeline(data)
|
|
203
|
-
update(data)
|
|
301
|
+
update(data, source: :pbp)
|
|
302
|
+
check_newness(:pbp, timeline.last&.updated)
|
|
303
|
+
check_newness(:clock, self.match_seconds.to_s)
|
|
204
304
|
data
|
|
205
305
|
end
|
|
206
306
|
def queue_timeline
|
|
@@ -208,6 +308,21 @@ module Sportradar
|
|
|
208
308
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_timeline)}
|
|
209
309
|
end
|
|
210
310
|
|
|
311
|
+
# tracking updates
|
|
312
|
+
def remember(key, object)
|
|
313
|
+
@updates[key] = object&.dup
|
|
314
|
+
end
|
|
315
|
+
def not_updated?(key, object)
|
|
316
|
+
@updates[key] == object
|
|
317
|
+
end
|
|
318
|
+
def changed?(key)
|
|
319
|
+
@changes[key]
|
|
320
|
+
end
|
|
321
|
+
def check_newness(key, new_object)
|
|
322
|
+
@changes[key] = !not_updated?(key, new_object)
|
|
323
|
+
remember(key, new_object)
|
|
324
|
+
end
|
|
325
|
+
|
|
211
326
|
end
|
|
212
327
|
end
|
|
213
328
|
end
|
|
@@ -226,6 +341,17 @@ __END__
|
|
|
226
341
|
[{"id"=>"sr:competitor:2793", "name"=>"US Sassuolo", "country"=>"Italy", "country_code"=>"ITA", "abbreviation"=>"SAS", "qualifier"=>"home"},
|
|
227
342
|
{"id"=>"sr:competitor:2702", "name"=>"AS Roma", "country"=>"Italy", "country_code"=>"ITA", "abbreviation"=>"ROM", "qualifier"=>"away"}]
|
|
228
343
|
|
|
344
|
+
"sport_event_status"=>
|
|
345
|
+
{"status"=>"live",
|
|
346
|
+
"match_status"=>"1st_half",
|
|
347
|
+
"home_score"=>1,
|
|
348
|
+
"away_score"=>0,
|
|
349
|
+
"period"=>1,
|
|
350
|
+
"clock"=>{"match_time"=>"19:25"},
|
|
351
|
+
"clock"=>{"match_time"=>"45:00", "stoppage_time"=>"00:05"}
|
|
352
|
+
"ball_locations"=>[{"x"=>"95", "y"=>"50", "team"=>"away"}, {"x"=>"80", "y"=>"62", "team"=>"home"}, {"x"=>"82", "y"=>"60", "team"=>"home"}, {"x"=>"79", "y"=>"58", "team"=>"home"}]},
|
|
353
|
+
|
|
354
|
+
|
|
229
355
|
|
|
230
356
|
m = Sportradar::Api::Soccer::Match.new({"id"=>"sr:match:12090446"}, league_group: 'eu')
|
|
231
357
|
res = m.get_summary
|
|
@@ -44,6 +44,14 @@ module Sportradar
|
|
|
44
44
|
@name || [@first_name, @last_name].join(' ')
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
def first_name
|
|
48
|
+
@first_name || (@name && @name.split(', ')[1])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def last_name
|
|
52
|
+
@last_name || (@name && @name.split(', ')[0])
|
|
53
|
+
end
|
|
54
|
+
|
|
47
55
|
def api
|
|
48
56
|
@api || Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
49
57
|
end
|
|
@@ -67,9 +75,7 @@ module Sportradar
|
|
|
67
75
|
url, headers, options, timeout = api.get_request_info(path_profile)
|
|
68
76
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_profile)}
|
|
69
77
|
end
|
|
70
|
-
|
|
71
78
|
end
|
|
72
|
-
|
|
73
79
|
end
|
|
74
80
|
end
|
|
75
81
|
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Soccer
|
|
4
|
+
class Scoring < Data
|
|
5
|
+
attr_accessor :response, :api, :id, :home, :away, :scores
|
|
6
|
+
|
|
7
|
+
def initialize(data, **opts)
|
|
8
|
+
@api = opts[:api]
|
|
9
|
+
@match = opts[:match]
|
|
10
|
+
|
|
11
|
+
@scores = {}
|
|
12
|
+
@id = data['id']
|
|
13
|
+
|
|
14
|
+
update(data, **opts)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update(data, source: nil, **opts)
|
|
18
|
+
# new_scores = case source
|
|
19
|
+
# when :box
|
|
20
|
+
# parse_from_box(data)
|
|
21
|
+
# when :timeline
|
|
22
|
+
# parse_from_timeline(data)
|
|
23
|
+
# when :summary
|
|
24
|
+
# parse_from_box(data)
|
|
25
|
+
# else
|
|
26
|
+
# if data['period'] || data['half']
|
|
27
|
+
# parse_from_timeline(data)
|
|
28
|
+
# elsif data['team']
|
|
29
|
+
# parse_from_box(data)
|
|
30
|
+
# else # schedule requests
|
|
31
|
+
# {}
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
new_scores = parse_from_timeline(data)
|
|
35
|
+
# parse data structure
|
|
36
|
+
# handle data from team (all periods)
|
|
37
|
+
# handle data from period (both teams)
|
|
38
|
+
# handle data from match?
|
|
39
|
+
@scores.each { |k, v| v.merge!(new_scores.delete(k) || {} ) }
|
|
40
|
+
new_scores.each { |k, v| @scores.merge!(k => v) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def goals(team_id)
|
|
44
|
+
@score[team_id].to_i
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def parse_from_timeline(data)
|
|
51
|
+
if data['period_scores']
|
|
52
|
+
data['period_scores'].map do |hash|
|
|
53
|
+
[hash["number"], {"home"=>hash['home_score'], "away"=>hash['away_score']}]
|
|
54
|
+
end.to_h
|
|
55
|
+
else
|
|
56
|
+
{}
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# def period_name
|
|
61
|
+
# 'period'
|
|
62
|
+
# end
|
|
63
|
+
|
|
64
|
+
def parse_from_summary(data)
|
|
65
|
+
#
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -2,9 +2,12 @@ module Sportradar
|
|
|
2
2
|
module Api
|
|
3
3
|
module Soccer
|
|
4
4
|
class Team < Data
|
|
5
|
-
attr_accessor :tournament_id
|
|
6
|
-
attr_reader :id, :league_group, :name, :country, :country_code, :abbreviation, :qualifier
|
|
5
|
+
attr_accessor :tournament_id, :venue
|
|
6
|
+
attr_reader :id, :league_group, :name, :country, :country_code, :abbreviation, :qualifier
|
|
7
7
|
alias :alias :abbreviation
|
|
8
|
+
alias :market :name
|
|
9
|
+
alias :display_name :name
|
|
10
|
+
alias :full_name :name
|
|
8
11
|
attr_reader :team_statistics, :jerseys, :manager, :statistics
|
|
9
12
|
|
|
10
13
|
def initialize(data = {}, league_group: nil, **opts)
|
|
@@ -58,6 +61,8 @@ module Sportradar
|
|
|
58
61
|
opts[:season].tournament_id
|
|
59
62
|
elsif opts[:match]
|
|
60
63
|
opts[:match].tournament_id
|
|
64
|
+
elsif data['tournament_id']
|
|
65
|
+
data['tournament_id']
|
|
61
66
|
elsif data['tournament']
|
|
62
67
|
data.dig('tournament', 'id')
|
|
63
68
|
elsif data['season']
|
|
@@ -3,6 +3,8 @@ module Sportradar
|
|
|
3
3
|
module Soccer
|
|
4
4
|
class Tournament < Data
|
|
5
5
|
attr_reader :id, :league_group, :name, :category
|
|
6
|
+
alias :display_name :name
|
|
7
|
+
alias :alias :name
|
|
6
8
|
|
|
7
9
|
def initialize(data = {}, league_group: nil, **opts)
|
|
8
10
|
@response = data
|
|
@@ -24,8 +26,8 @@ module Sportradar
|
|
|
24
26
|
update(data['tournament'])
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
@name = data["name"]
|
|
28
|
-
@category = data['category']
|
|
29
|
+
@name = data["name"] || @name
|
|
30
|
+
@category = data['category'] || @category
|
|
29
31
|
|
|
30
32
|
parse_info(data)
|
|
31
33
|
parse_season(data)
|
|
@@ -38,6 +40,22 @@ module Sportradar
|
|
|
38
40
|
@seasons_hash.values
|
|
39
41
|
end
|
|
40
42
|
|
|
43
|
+
def schedule
|
|
44
|
+
return self if @schedule_retrieved
|
|
45
|
+
get_schedule
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def year
|
|
50
|
+
if current_season&.year&.split('/')&.last
|
|
51
|
+
2000 + current_season.year.split('/').last.to_i
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def current_season
|
|
56
|
+
seasons.detect(&:current?)
|
|
57
|
+
end
|
|
58
|
+
|
|
41
59
|
def standings(type = nil)
|
|
42
60
|
if type
|
|
43
61
|
@standings_hash[type]
|
|
@@ -150,6 +168,7 @@ module Sportradar
|
|
|
150
168
|
ingest_schedule(data)
|
|
151
169
|
end
|
|
152
170
|
def ingest_schedule(data)
|
|
171
|
+
@schedule_retrieved = true
|
|
153
172
|
update(data)
|
|
154
173
|
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
155
174
|
data
|