sportradar-api 0.16.0 → 0.17.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 +10 -6
- data/lib/sportradar/api/baseball/game.rb +1 -0
- data/lib/sportradar/api/baseball/lineup.rb +8 -0
- data/lib/sportradar/api/basketball/nba/player.rb +3 -1
- data/lib/sportradar/api/images.rb +5 -4
- data/lib/sportradar/api/odds/README.md +49 -0
- data/lib/sportradar/api/odds/api.rb +60 -0
- data/lib/sportradar/api/odds/base.rb +77 -0
- data/lib/sportradar/api/odds/book.rb +23 -0
- data/lib/sportradar/api/odds/book_market.rb +38 -0
- data/lib/sportradar/api/odds/competition.rb +52 -0
- data/lib/sportradar/api/odds/market.rb +34 -0
- data/lib/sportradar/api/odds/outcome.rb +35 -0
- data/lib/sportradar/api/odds/player.rb +29 -0
- data/lib/sportradar/api/odds/player_odds.rb +13 -0
- data/lib/sportradar/api/odds/player_prop.rb +29 -0
- data/lib/sportradar/api/odds/prematch_odds.rb +9 -0
- data/lib/sportradar/api/odds/probabilities.rb +9 -0
- data/lib/sportradar/api/odds/regular_odds.rb +18 -0
- data/lib/sportradar/api/odds/sport.rb +47 -0
- data/lib/sportradar/api/odds/sport_event.rb +40 -0
- data/lib/sportradar/api/odds.rb +19 -28
- data/lib/sportradar/api/soccer/api.rb +9 -9
- data/lib/sportradar/api/soccer/competition.rb +305 -0
- data/lib/sportradar/api/soccer/match.rb +22 -8
- data/lib/sportradar/api/soccer/player.rb +5 -3
- data/lib/sportradar/api/soccer/season.rb +49 -14
- data/lib/sportradar/api/soccer.rb +36 -0
- data/lib/sportradar/api/version.rb +1 -1
- data/lib/sportradar/api.rb +5 -3
- metadata +19 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Odds
|
|
4
|
+
class SportEvent < Data
|
|
5
|
+
attr_accessor :response, :api, :id
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def initialize(data, **opts)
|
|
9
|
+
@response = data
|
|
10
|
+
@api = opts[:api]
|
|
11
|
+
@id = data['id'] || data.dig('sport_event', 'id')
|
|
12
|
+
|
|
13
|
+
@player_props_hash = {}
|
|
14
|
+
@player_markets_hash = {}
|
|
15
|
+
|
|
16
|
+
update(data)
|
|
17
|
+
# update(data['sport_event']) if data['sport_event']
|
|
18
|
+
# update(data['players_props']) if data['players_props']
|
|
19
|
+
# update(data['players_markets']) if data['players_markets']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def player_props
|
|
23
|
+
@player_props_hash.values
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def player_markets
|
|
27
|
+
@player_markets_hash.values
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def update(data, **opts)
|
|
31
|
+
create_data(@player_props_hash, data['players_props'], klass: PlayerProp, api: api) if data['players_props']
|
|
32
|
+
create_data(@player_markets_hash, data['players_markets'], klass: Market, api: api) if data['players_markets']
|
|
33
|
+
rescue => e
|
|
34
|
+
binding.pry
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/sportradar/api/odds.rb
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
module Sportradar
|
|
2
2
|
module Api
|
|
3
|
-
|
|
4
|
-
attr_accessor :access_level
|
|
5
|
-
|
|
6
|
-
def initialize( access_level = 't')
|
|
7
|
-
raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
|
|
8
|
-
@access_level = access_level
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def odds
|
|
12
|
-
get request_url, {format: 'none'}
|
|
13
|
-
end
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def request_url(path = nil)
|
|
17
|
-
"/odds-#{access_level}#{version}"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def api_key
|
|
21
|
-
Sportradar::Api.api_key_params("odds")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def version
|
|
25
|
-
Sportradar::Api.version('odds')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def allowed_access_levels
|
|
29
|
-
['p', 's', 'b', 't']
|
|
30
|
-
end
|
|
3
|
+
module Odds
|
|
31
4
|
|
|
32
5
|
end
|
|
33
6
|
end
|
|
34
7
|
end
|
|
8
|
+
|
|
9
|
+
require_relative 'odds/api'
|
|
10
|
+
|
|
11
|
+
require_relative 'odds/book'
|
|
12
|
+
require_relative 'odds/sport'
|
|
13
|
+
require_relative 'odds/competition'
|
|
14
|
+
require_relative 'odds/player'
|
|
15
|
+
require_relative 'odds/player_prop'
|
|
16
|
+
require_relative 'odds/sport_event'
|
|
17
|
+
require_relative 'odds/market'
|
|
18
|
+
require_relative 'odds/book_market'
|
|
19
|
+
require_relative 'odds/outcome'
|
|
20
|
+
|
|
21
|
+
require_relative 'odds/base'
|
|
22
|
+
require_relative 'odds/player_odds'
|
|
23
|
+
require_relative 'odds/regular_odds'
|
|
24
|
+
require_relative 'odds/prematch_odds'
|
|
25
|
+
require_relative 'odds/probabilities'
|
|
@@ -4,11 +4,11 @@ module Sportradar
|
|
|
4
4
|
class Api < Request
|
|
5
5
|
attr_accessor :league_group, :access_level, :language_code, :error
|
|
6
6
|
|
|
7
|
-
def initialize(access_level: default_access_level,
|
|
7
|
+
def initialize(access_level: default_access_level, language_code: 'en', **args)
|
|
8
8
|
@league_group = league_group
|
|
9
9
|
@language_code = language_code
|
|
10
10
|
@access_level = access_level
|
|
11
|
-
raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? @league_group
|
|
11
|
+
# raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? @league_group
|
|
12
12
|
raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? @access_level
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -20,9 +20,9 @@ module Sportradar
|
|
|
20
20
|
end
|
|
21
21
|
def default_access_level
|
|
22
22
|
if (ENV['SPORTRADAR_SOCCER_ENV'] || ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
|
|
23
|
-
'
|
|
23
|
+
'production'
|
|
24
24
|
else
|
|
25
|
-
'
|
|
25
|
+
'trial'
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -33,14 +33,14 @@ module Sportradar
|
|
|
33
33
|
private
|
|
34
34
|
|
|
35
35
|
def request_url(path)
|
|
36
|
-
"/soccer
|
|
36
|
+
"/soccer/#{access_level}/v#{version}/#{language_code}/#{path}"
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def api_key
|
|
40
|
-
if !['
|
|
41
|
-
Sportradar::Api.api_key_params("soccer
|
|
40
|
+
if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
|
|
41
|
+
Sportradar::Api.api_key_params("soccer", 'production')
|
|
42
42
|
else
|
|
43
|
-
Sportradar::Api.api_key_params("soccer
|
|
43
|
+
Sportradar::Api.api_key_params("soccer")
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ module Sportradar
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def allowed_access_levels
|
|
52
|
-
%w[
|
|
52
|
+
%w[production trial sim]
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def allowed_leagues
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Soccer
|
|
4
|
+
class Competition < Data
|
|
5
|
+
attr_reader :id, :league_group, :name, :category, :coverage_info, :live_coverage, :season_coverage_info
|
|
6
|
+
alias :display_name :name
|
|
7
|
+
alias :alias :name
|
|
8
|
+
|
|
9
|
+
def initialize(data = {}, league_group: nil, **opts)
|
|
10
|
+
@response = data
|
|
11
|
+
@id = data["id"]
|
|
12
|
+
@api = opts[:api]
|
|
13
|
+
|
|
14
|
+
@seasons_hash = {}
|
|
15
|
+
@teams_hash = {}
|
|
16
|
+
@standings_hash = {}
|
|
17
|
+
@groups_hash = {}
|
|
18
|
+
|
|
19
|
+
update(data, **opts)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def update(data, **opts)
|
|
23
|
+
# if data['tournament']
|
|
24
|
+
# update(data['tournament'])
|
|
25
|
+
# end
|
|
26
|
+
|
|
27
|
+
@name = data["name"] || @name
|
|
28
|
+
@category = data['category'] || @category
|
|
29
|
+
@gender = data['gender'] || @gender
|
|
30
|
+
@coverage_info = data['coverage_info'] || @coverage_info
|
|
31
|
+
@live_coverage = data.dig('coverage_info', 'live_coverage') || @live_coverage
|
|
32
|
+
|
|
33
|
+
# parse_info(data)
|
|
34
|
+
parse_season(data)
|
|
35
|
+
# parse_results(data)
|
|
36
|
+
# parse_standings(data)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def seasons
|
|
40
|
+
@seasons_hash.values
|
|
41
|
+
end
|
|
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
|
+
|
|
59
|
+
def standings(type = nil)
|
|
60
|
+
if type
|
|
61
|
+
@standings_hash[type]
|
|
62
|
+
else
|
|
63
|
+
@standings_hash.values
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def groups
|
|
68
|
+
@groups_hash.values
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def group(name = nil) # nil represents the complete team listing
|
|
72
|
+
@groups_hash[name]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def matches
|
|
76
|
+
@matches_hash.values
|
|
77
|
+
end
|
|
78
|
+
alias :games :matches
|
|
79
|
+
|
|
80
|
+
# parsing helpers
|
|
81
|
+
def parse_info(data)
|
|
82
|
+
if data['groups']
|
|
83
|
+
create_data(@groups_hash, data['groups'], klass: TeamGroup, api: api, competition: self, identifier: 'name')
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def parse_season(data)
|
|
88
|
+
if data['season_coverage_info']
|
|
89
|
+
@season_coverage_info = data['season_coverage_info'] if data['season_coverage_info']
|
|
90
|
+
data['season_coverage_info']['id'] ||= data['season_coverage_info'].delete('season_id')
|
|
91
|
+
create_data(@seasons_hash, data['season_coverage_info'], klass: Season, api: api, competition: self)
|
|
92
|
+
end
|
|
93
|
+
if data['current_season']
|
|
94
|
+
create_data(@seasons_hash, data['current_season'], klass: Season, api: api, competition: self, current: true)
|
|
95
|
+
end
|
|
96
|
+
if data['seasons']
|
|
97
|
+
create_data(@seasons_hash, data['seasons'], klass: Season, api: api, competition: self)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def parse_results(data)
|
|
102
|
+
if data['results']
|
|
103
|
+
merged_data = Soccer.parse_results(data['results'])
|
|
104
|
+
create_data(@matches_hash, merged_data, klass: Match, api: api, competition: self)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def parse_standings(data)
|
|
109
|
+
if data['standings']
|
|
110
|
+
create_data(@standings_hash, data['standings'], klass: Standing, api: api, competition: self, identifier: 'type')
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def api
|
|
115
|
+
@api ||= Sportradar::Api::Soccer::Api.new
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# url path helpers
|
|
119
|
+
def path_base
|
|
120
|
+
"competitions/#{ id }"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def path_live_standings
|
|
124
|
+
"#{ path_base }/live_standings"
|
|
125
|
+
end
|
|
126
|
+
def get_live_standings
|
|
127
|
+
data = api.get_data(path_live_standings).to_h
|
|
128
|
+
ingest_live_standings(data)
|
|
129
|
+
end
|
|
130
|
+
alias :get_standings :get_live_standings
|
|
131
|
+
def ingest_live_standings(data)
|
|
132
|
+
update(data)
|
|
133
|
+
# TODO parse the rest of the data. keys: ["tournament", "season", "standings"]
|
|
134
|
+
data
|
|
135
|
+
end
|
|
136
|
+
def queue_live_standings
|
|
137
|
+
url, headers, options, timeout = api.get_request_info(path_live_standings)
|
|
138
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_live_standings)}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def path_results
|
|
142
|
+
"#{ path_base }/results"
|
|
143
|
+
end
|
|
144
|
+
def get_results
|
|
145
|
+
data = api.get_data(path_results).to_h
|
|
146
|
+
ingest_results(data)
|
|
147
|
+
end
|
|
148
|
+
def ingest_results(data)
|
|
149
|
+
update(data)
|
|
150
|
+
# TODO parse the rest of the data. keys: ["tournament", "results"]
|
|
151
|
+
data
|
|
152
|
+
end
|
|
153
|
+
def queue_results
|
|
154
|
+
url, headers, options, timeout = api.get_request_info(path_results)
|
|
155
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_results)}
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def path_seasons
|
|
159
|
+
"#{ path_base }/seasons"
|
|
160
|
+
end
|
|
161
|
+
def get_seasons
|
|
162
|
+
data = api.get_data(path_seasons).to_h
|
|
163
|
+
ingest_seasons(data)
|
|
164
|
+
end
|
|
165
|
+
def ingest_seasons(data)
|
|
166
|
+
update(data)
|
|
167
|
+
# TODO parse the rest of the data. keys: ["tournament", "seasons"]
|
|
168
|
+
data
|
|
169
|
+
end
|
|
170
|
+
def queue_seasons
|
|
171
|
+
url, headers, options, timeout = api.get_request_info(path_seasons)
|
|
172
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_seasons)}
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def path_info
|
|
176
|
+
"#{ path_base }/info"
|
|
177
|
+
end
|
|
178
|
+
def get_info
|
|
179
|
+
data = api.get_data(path_info).to_h
|
|
180
|
+
ingest_info(data)
|
|
181
|
+
end
|
|
182
|
+
def ingest_info(data)
|
|
183
|
+
update(data)
|
|
184
|
+
# TODO parse the rest of the data. keys: ["tournament", "season", "round", "season_coverage_info", "coverage_info", "groups"]
|
|
185
|
+
data
|
|
186
|
+
end
|
|
187
|
+
def queue_info
|
|
188
|
+
url, headers, options, timeout = api.get_request_info(path_info)
|
|
189
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_info)}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def path_leaders
|
|
193
|
+
"#{ path_base }/leaders"
|
|
194
|
+
end
|
|
195
|
+
def get_leaders
|
|
196
|
+
data = api.get_data(path_leaders).to_h
|
|
197
|
+
ingest_leaders(data)
|
|
198
|
+
end
|
|
199
|
+
def ingest_leaders(data)
|
|
200
|
+
update(data)
|
|
201
|
+
# TODO parse the rest of the data. keys: ["tournament", "season_coverage_info", "top_points", "top_goals", "top_assists", "top_cards", "top_own_goals"]
|
|
202
|
+
data
|
|
203
|
+
end
|
|
204
|
+
def queue_leaders
|
|
205
|
+
url, headers, options, timeout = api.get_request_leaders(path_leaders)
|
|
206
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_leaders)}
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def self.tournament_ids
|
|
210
|
+
@tournament_ids ||= {
|
|
211
|
+
# Europe group
|
|
212
|
+
'eu.uefa_champions_league' => "sr:tournament:7",
|
|
213
|
+
'eu.la_liga' => "sr:tournament:8",
|
|
214
|
+
'eu.eng_premier_league' => "sr:tournament:17",
|
|
215
|
+
'eu.premier_league' => "sr:tournament:17",
|
|
216
|
+
'eu.serie_a' => "sr:tournament:23",
|
|
217
|
+
'eu.ligue_1' => "sr:tournament:34",
|
|
218
|
+
'eu.bundesliga' => "sr:tournament:35",
|
|
219
|
+
'eu.eredivisie' => "sr:tournament:37",
|
|
220
|
+
'eu.first_division_a' => "sr:tournament:38",
|
|
221
|
+
'eu.super_lig' => "sr:tournament:52",
|
|
222
|
+
'eu.super_league' => "sr:tournament:185",
|
|
223
|
+
'eu.rus_premier_league' => "sr:tournament:203",
|
|
224
|
+
'eu.ukr_premier_league' => "sr:tournament:218",
|
|
225
|
+
'eu.primeira_liga' => "sr:tournament:238",
|
|
226
|
+
'eu.uefa_super_cup' => "sr:tournament:465",
|
|
227
|
+
'eu.uefa_europa_league' => "sr:tournament:679",
|
|
228
|
+
'eu.uefa_youth_league' => "sr:tournament:2324",
|
|
229
|
+
# international (partial listing)
|
|
230
|
+
"intl.world_cup" => "sr:tournament:16",
|
|
231
|
+
"intl.copa_america" => "sr:tournament:133",
|
|
232
|
+
"intl.gold_cup" => "sr:tournament:140",
|
|
233
|
+
"intl.africa_cup_of_nations" => "sr:tournament:270",
|
|
234
|
+
"intl.womens_world_cup" => "sr:tournament:290",
|
|
235
|
+
"intl.olympic_games" => "sr:tournament:436",
|
|
236
|
+
"intl.olympic_games_women" => "sr:tournament:437",
|
|
237
|
+
# other groups below
|
|
238
|
+
}
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
self.tournament_ids.each do |tour_name, tour_id|
|
|
242
|
+
group_code, name = tour_name.split('.')
|
|
243
|
+
# define_singleton_method(name) { Sportradar::Api::Soccer::Tournament.new({'id' => tour_id}, league_group: group_code) }
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
__END__
|
|
252
|
+
|
|
253
|
+
{"id"=>"sr:tournament:17",
|
|
254
|
+
"name"=>"Premier League",
|
|
255
|
+
"sport"=>{"id"=>"sr:sport:1", "name"=>"Soccer"},
|
|
256
|
+
"category"=>{"id"=>"sr:category:1", "name"=>"England", "country_code"=>"ENG"},
|
|
257
|
+
"current_season"=>{"id"=>"sr:season:40942", "name"=>"Premier League 17/18", "start_date"=>"2017-08-11", "end_date"=>"2018-05-14", "year"=>"17/18"},
|
|
258
|
+
"season_coverage_info"=>{"season_id"=>"sr:season:40942", "scheduled"=>381, "played"=>70, "max_coverage_level"=>"platinum", "max_covered"=>70, "min_coverage_level"=>"platinum"}}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
group = Sportradar::Api::Soccer::Group.new(league_group: 'eu')
|
|
262
|
+
res = group.get_tournaments;
|
|
263
|
+
tour = group.tournaments.sample
|
|
264
|
+
tour.get_seasons
|
|
265
|
+
tour.get_results
|
|
266
|
+
res = tour.get_schedule
|
|
267
|
+
tour.matches.size
|
|
268
|
+
tour
|
|
269
|
+
|
|
270
|
+
group = Sportradar::Api::Soccer::Group.new(league_group: 'eu')
|
|
271
|
+
res = group.get_tournaments;
|
|
272
|
+
infos = group.tournaments.map{|tour| sleep 1; tour.get_info }
|
|
273
|
+
standings = group.tournaments.map{|tour| sleep 1; tour.get_standings }
|
|
274
|
+
results = group.tournaments.each{|tour| sleep 1; tour.get_results }.flat_map(&:matches)
|
|
275
|
+
standings = group.tournaments.map{|tour| sleep 1; (tour.get_standings rescue nil) }
|
|
276
|
+
|
|
277
|
+
{"UEFA Champions League"=>"sr:tournament:7",
|
|
278
|
+
"LaLiga"=>"sr:tournament:8",
|
|
279
|
+
"Premier League"=>"sr:tournament:218",
|
|
280
|
+
"Serie A"=>"sr:tournament:23",
|
|
281
|
+
"Ligue 1"=>"sr:tournament:34",
|
|
282
|
+
"Bundesliga"=>"sr:tournament:35",
|
|
283
|
+
"Eredivisie"=>"sr:tournament:37",
|
|
284
|
+
"First Division A"=>"sr:tournament:38",
|
|
285
|
+
"Super Lig"=>"sr:tournament:52",
|
|
286
|
+
"Super League"=>"sr:tournament:185",
|
|
287
|
+
"Primeira Liga"=>"sr:tournament:238",
|
|
288
|
+
"UEFA Super Cup"=>"sr:tournament:465",
|
|
289
|
+
"UEFA Europa League"=>"sr:tournament:679",
|
|
290
|
+
"UEFA Youth League"=>"sr:tournament:2324"}
|
|
291
|
+
|
|
292
|
+
sample_leagues = [:la_liga, :eng_premier_league, :bundesliga, :serie_a, :ligue_1]
|
|
293
|
+
tours = sample_leagues.map { |code| Sportradar::Api::Soccer::Tournament.send(code) }
|
|
294
|
+
tours.each{|t| sleep 1; t.get_info }
|
|
295
|
+
teams = tours.flat_map(&:groups).flat_map(&:teams)
|
|
296
|
+
teams.each { |t| sleep 1; t.get_roster }
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
sample_leagues = [:la_liga, :eng_premier_league, :bundesliga, :serie_a, :ligue_1];
|
|
300
|
+
tours = sample_leagues.map { |code| Sportradar::Api::Soccer::Tournament.send(code) };
|
|
301
|
+
tours.each{|t| sleep 1; t.get_info };
|
|
302
|
+
tours.flat_map(&:groups).flat_map(&:teams);
|
|
303
|
+
teams = tours.flat_map(&:groups).flat_map(&:teams);
|
|
304
|
+
teams.each { |t| sleep 1; t.get_roster };
|
|
305
|
+
teams.map {|t| ["#{t.tournament_id} #{t.name}",t.jerseys]}.to_h
|
|
@@ -10,18 +10,18 @@ module Sportradar
|
|
|
10
10
|
attr_reader :match_time, :stoppage_time
|
|
11
11
|
attr_reader :team_stats, :player_stats
|
|
12
12
|
|
|
13
|
-
def initialize(data = {},
|
|
13
|
+
def initialize(data = {}, season: nil, **opts)
|
|
14
14
|
@response = data
|
|
15
|
-
@id = data['id']
|
|
15
|
+
@id = data['id'] || data.dig("sport_event", 'id')
|
|
16
16
|
@api = opts[:api]
|
|
17
|
+
@season = season
|
|
17
18
|
@updates = {}
|
|
18
19
|
@changes = {}
|
|
19
20
|
|
|
20
|
-
@league_group = league_group || data['league_group'] || @api&.league_group
|
|
21
21
|
|
|
22
22
|
@timeline_hash = {}
|
|
23
23
|
@lineups_hash = {}
|
|
24
|
-
get_tournament_id(data, **opts)
|
|
24
|
+
# get_tournament_id(data, **opts)
|
|
25
25
|
@scoring_raw = Scoring.new(data, game: self)
|
|
26
26
|
@home = Team.new(data['home'].to_h, api: api, match: self)
|
|
27
27
|
@away = Team.new(data['away'].to_h, api: api, match: self)
|
|
@@ -34,8 +34,6 @@ module Sportradar
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def update(data, **opts)
|
|
37
|
-
@league_group = opts[:league_group] || data['league_group'] || @league_group
|
|
38
|
-
get_tournament_id(data, **opts)
|
|
39
37
|
if data["sport_event"]
|
|
40
38
|
update(data["sport_event"])
|
|
41
39
|
end
|
|
@@ -52,11 +50,12 @@ module Sportradar
|
|
|
52
50
|
if data['lineups']
|
|
53
51
|
create_data(@lineups_hash, data['lineups'], klass: Lineup, identifier: 'team', api: api)
|
|
54
52
|
end
|
|
55
|
-
if (stats = data.dig('statistics', '
|
|
53
|
+
if (stats = data.dig('statistics', 'totals', 'competitors'))
|
|
56
54
|
update_teams(stats)
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
@scheduled = Time.parse(data['scheduled']) if data['scheduled']
|
|
58
|
+
@scheduled = Time.parse(data['start_time']) if data['start_time']
|
|
60
59
|
@start_time_tbd = data['start_time_tbd'] if data.key?('start_time_tbd')
|
|
61
60
|
@status = data['status'] if data['status']
|
|
62
61
|
@match_status = data['match_status'] if data['match_status']
|
|
@@ -68,8 +67,10 @@ module Sportradar
|
|
|
68
67
|
|
|
69
68
|
@home_score = data['home_score'] if data['home_score']
|
|
70
69
|
@away_score = data['away_score'] if data['away_score']
|
|
70
|
+
@period = parse_period(data['match_status']) if data['match_status']
|
|
71
71
|
@period = data['period'] if data['period']
|
|
72
72
|
@match_time = data.dig('clock', 'match_time') if data.dig('clock', 'match_time')
|
|
73
|
+
@match_time = data.dig('clock', 'played') if data.dig('clock', 'played')
|
|
73
74
|
@stoppage_time = data.dig('clock', 'stoppage_time')
|
|
74
75
|
@ball_locations = data['ball_locations'] if data['ball_locations']
|
|
75
76
|
@winner_id = data['winner_id'] if data['winner_id']
|
|
@@ -130,6 +131,19 @@ module Sportradar
|
|
|
130
131
|
@match_status == "halftime"
|
|
131
132
|
end
|
|
132
133
|
|
|
134
|
+
def parse_period(status)
|
|
135
|
+
case status
|
|
136
|
+
when '1st_half', 'halftime'
|
|
137
|
+
1
|
|
138
|
+
when '2nd_half'
|
|
139
|
+
2
|
|
140
|
+
when 'overtime', '1st_extra'
|
|
141
|
+
3
|
|
142
|
+
when '2nd_extra'
|
|
143
|
+
4
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
133
147
|
def postponed?
|
|
134
148
|
'postponed' == status
|
|
135
149
|
end
|
|
@@ -252,7 +266,7 @@ module Sportradar
|
|
|
252
266
|
end
|
|
253
267
|
|
|
254
268
|
def path_base
|
|
255
|
-
"
|
|
269
|
+
"sport_events/#{ id }"
|
|
256
270
|
end
|
|
257
271
|
|
|
258
272
|
def path_summary
|
|
@@ -40,9 +40,11 @@ module Sportradar
|
|
|
40
40
|
@date_of_birth = Date.parse(data['date_of_birth']) if data['date_of_birth']
|
|
41
41
|
set_game_stats(data)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if data['statistics'] && @team
|
|
44
|
+
@team.update_player_stats(self, data['statistics'])
|
|
45
|
+
if opts[:match]
|
|
46
|
+
@team.update_player_stats(self, data['statistics'], opts[:match])
|
|
47
|
+
end
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
end
|
|
@@ -2,13 +2,14 @@ module Sportradar
|
|
|
2
2
|
module Api
|
|
3
3
|
module Soccer
|
|
4
4
|
class Season < Data
|
|
5
|
-
attr_reader :id, :league_group, :name, :category, :current_season, :season_coverage_info, :
|
|
5
|
+
attr_reader :id, :league_group, :name, :category, :current_season, :season_coverage_info, :competition, :start_date, :end_date
|
|
6
6
|
|
|
7
|
-
def initialize(data = {},
|
|
7
|
+
def initialize(data = {}, competition: nil, **opts)
|
|
8
8
|
@response = data
|
|
9
9
|
@id = data["id"]
|
|
10
10
|
@api = opts[:api]
|
|
11
|
-
@
|
|
11
|
+
@competition = competition
|
|
12
|
+
@matches_hash = {}
|
|
12
13
|
|
|
13
14
|
update(data, **opts)
|
|
14
15
|
end
|
|
@@ -17,7 +18,7 @@ module Sportradar
|
|
|
17
18
|
@league_group = opts[:league_group] || data['league_group'] || @league_group
|
|
18
19
|
@id = data['id'] || data['season_id'] || @id
|
|
19
20
|
@current = opts[:current] || @current
|
|
20
|
-
get_tournament_id(data, **opts)
|
|
21
|
+
# get_tournament_id(data, **opts)
|
|
21
22
|
|
|
22
23
|
@name = data['name'] || @name
|
|
23
24
|
@start_date = data['start_date'] || @start_date
|
|
@@ -28,26 +29,60 @@ module Sportradar
|
|
|
28
29
|
@max_coverage_level = data['max_coverage_level'] || @max_coverage_level
|
|
29
30
|
@max_covered = data['max_covered'] || @max_covered
|
|
30
31
|
@min_coverage_level = data['min_coverage_level'] || @min_coverage_level
|
|
31
|
-
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
@tournament_id ||= if opts[:tournament]
|
|
35
|
-
opts[:tournament].id
|
|
36
|
-
elsif data['tournament_id']
|
|
37
|
-
data['tournament_id']
|
|
38
|
-
elsif data['tournament']
|
|
39
|
-
data.dig('tournament', 'id')
|
|
40
|
-
end
|
|
33
|
+
parse_schedule(data)
|
|
41
34
|
end
|
|
42
35
|
|
|
36
|
+
# def get_tournament_id(data, **opts)
|
|
37
|
+
# @tournament_id ||= if opts[:tournament]
|
|
38
|
+
# opts[:tournament].id
|
|
39
|
+
# elsif data['tournament_id']
|
|
40
|
+
# data['tournament_id']
|
|
41
|
+
# elsif data['tournament']
|
|
42
|
+
# data.dig('tournament', 'id')
|
|
43
|
+
# end
|
|
44
|
+
# end
|
|
45
|
+
|
|
43
46
|
def current?
|
|
44
47
|
!!@current
|
|
45
48
|
end
|
|
46
49
|
|
|
50
|
+
def matches
|
|
51
|
+
@matches_hash.values
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def parse_schedule(data)
|
|
55
|
+
if data['schedules']
|
|
56
|
+
create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
47
60
|
def api
|
|
48
61
|
@api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
49
62
|
end
|
|
50
63
|
|
|
64
|
+
def path_base
|
|
65
|
+
"seasons/#{@id}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def path_schedule
|
|
69
|
+
"#{ path_base }/schedules"
|
|
70
|
+
end
|
|
71
|
+
def get_schedule
|
|
72
|
+
data = api.get_data(path_schedule).to_h
|
|
73
|
+
ingest_schedule(data)
|
|
74
|
+
end
|
|
75
|
+
def ingest_schedule(data)
|
|
76
|
+
@schedule_retrieved = true
|
|
77
|
+
update(data)
|
|
78
|
+
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
79
|
+
data
|
|
80
|
+
end
|
|
81
|
+
def queue_schedule
|
|
82
|
+
url, headers, options, timeout = api.get_request_info(path_schedule)
|
|
83
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
84
|
+
end
|
|
85
|
+
|
|
51
86
|
end
|
|
52
87
|
end
|
|
53
88
|
end
|
|
@@ -62,4 +97,4 @@ group = Sportradar::Api::Soccer::Group.new(league_group: 'eu')
|
|
|
62
97
|
res = group.get_tournaments;
|
|
63
98
|
tour = group.tournaments.sample
|
|
64
99
|
tour.get_seasons
|
|
65
|
-
tour
|
|
100
|
+
tour
|