sportradar-api 0.18.1 → 0.19.4
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/football/game.rb +5 -1
- data/lib/sportradar/api/football/game_stats.rb +4 -0
- data/lib/sportradar/api/football/nfl/api.rb +5 -5
- data/lib/sportradar/api/football/nfl.rb +14 -4
- data/lib/sportradar/api/football/player.rb +2 -2
- data/lib/sportradar/api/football/stat_pack.rb +4 -0
- data/lib/sportradar/api/football/stats_shim.rb +24 -0
- data/lib/sportradar/api/football.rb +1 -0
- data/lib/sportradar/api/odds/README.md +1 -1
- data/lib/sportradar/api/odds/base.rb +18 -2
- data/lib/sportradar/api/odds/competition.rb +12 -4
- data/lib/sportradar/api/odds/sport_event.rb +0 -2
- data/lib/sportradar/api/request.rb +2 -2
- data/lib/sportradar/api/soccer/competition.rb +17 -0
- data/lib/sportradar/api/soccer/player.rb +5 -1
- data/lib/sportradar/api/soccer/season.rb +26 -0
- data/lib/sportradar/api/soccer/team.rb +12 -6
- data/lib/sportradar/api/version.rb +1 -1
- data/lib/sportradar/api.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd632c76f639fcdd6627dbc2323fc85ee6b8fe20d3eb37b3f4ee1855590e2d54
|
|
4
|
+
data.tar.gz: acaf3b496f64a18051969bd18a84de9dc8c717535c371cbd297329b5be804b6f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3d9a2d3b120f76804a9287ff0f5d734dccc674451bcaf48b71542849c62ac9e97480c43de38d886a564a3e30ee86075ce57152f68cf70524b508d6856dc7f9b
|
|
7
|
+
data.tar.gz: ce834768c971a60c379029efa678a687c3465e0a4d2d75af51158068cc10e9436eca4014ddd2757cb018c0c3a611a10b107ada473b351391fde73b2512da1cea
|
data/Gemfile.lock
CHANGED
|
@@ -20,7 +20,7 @@ module Sportradar
|
|
|
20
20
|
|
|
21
21
|
@teams_hash = {}
|
|
22
22
|
@team_stats = {}
|
|
23
|
-
@player_stats =
|
|
23
|
+
@player_stats = StatsShim.new(self)
|
|
24
24
|
|
|
25
25
|
@quarters_hash = {}
|
|
26
26
|
@drives_hash = {}
|
|
@@ -394,6 +394,10 @@ module Sportradar
|
|
|
394
394
|
ingest_statistics(data)
|
|
395
395
|
end
|
|
396
396
|
|
|
397
|
+
def get_summary
|
|
398
|
+
get_statistics
|
|
399
|
+
end
|
|
400
|
+
|
|
397
401
|
def queue_statistics
|
|
398
402
|
url, headers, options, timeout = api.get_request_info(path_statistics)
|
|
399
403
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_statistics)}
|
|
@@ -29,6 +29,10 @@ module Sportradar
|
|
|
29
29
|
@return_yards = data.dig('summary', "return_yards")
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
def dig(*args)
|
|
33
|
+
args.inject(self) { |memo, arg| memo.public_send(arg) }
|
|
34
|
+
end
|
|
35
|
+
|
|
32
36
|
def turnovers
|
|
33
37
|
@turnovers || passing.interceptions + fumbles&.lost_fumbles.to_i
|
|
34
38
|
end
|
|
@@ -22,9 +22,9 @@ module Sportradar
|
|
|
22
22
|
end
|
|
23
23
|
def default_access_level
|
|
24
24
|
if (ENV['SPORTRADAR_ENV'] || ENV['SPORTRADAR_ENV_NFL'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
|
|
25
|
-
'
|
|
25
|
+
'production'
|
|
26
26
|
else
|
|
27
|
-
'
|
|
27
|
+
'trial'
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -35,11 +35,11 @@ module Sportradar
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def request_url(path)
|
|
38
|
-
"/nfl
|
|
38
|
+
"/nfl/official/#{access_level}/v#{version}/en/#{path}"
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def api_key
|
|
42
|
-
if !['
|
|
42
|
+
if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
|
|
43
43
|
::Sportradar::Api.api_key_params('nfl', 'production')
|
|
44
44
|
else
|
|
45
45
|
::Sportradar::Api.api_key_params('nfl')
|
|
@@ -51,7 +51,7 @@ module Sportradar
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def allowed_access_levels
|
|
54
|
-
%w[
|
|
54
|
+
%w[production trial sim]
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def allowed_seasons
|
|
@@ -159,13 +159,13 @@ module Sportradar
|
|
|
159
159
|
"games/#{season_year}/#{nfl_season}/#{nfl_season_week}/schedule"
|
|
160
160
|
end
|
|
161
161
|
def path_weekly_depth_charts(nfl_season_week)
|
|
162
|
-
"
|
|
162
|
+
"seasons/#{season_year}/#{nfl_season}/#{nfl_season_week}/depth_charts"
|
|
163
163
|
end
|
|
164
164
|
def path_weekly_depth_injuries(nfl_season_week)
|
|
165
|
-
"
|
|
165
|
+
"seasons/#{season_year}/#{nfl_season}/#{nfl_season_week}/injuries"
|
|
166
166
|
end
|
|
167
167
|
def path_standings
|
|
168
|
-
"
|
|
168
|
+
"seasons/#{season_year}/standings"
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
# data retrieval
|
|
@@ -320,4 +320,14 @@ File.binwrite('nfl.bin', Marshal.dump(nfl))
|
|
|
320
320
|
nfl = Sportradar::Api::Football::Nfl.new
|
|
321
321
|
nfl.season = 2016
|
|
322
322
|
res = nfl.get_weekly_depth_charts
|
|
323
|
-
dc = nfl.instance_variable_get(:@depth_charts_hash)
|
|
323
|
+
dc = nfl.instance_variable_get(:@depth_charts_hash)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
nfl = Sportradar::Api::Football::Nfl.new
|
|
327
|
+
nfl.season = 2021
|
|
328
|
+
nfl.get_schedule
|
|
329
|
+
g = nfl.games.sample
|
|
330
|
+
data = g.get_statistics
|
|
331
|
+
g.team_stats
|
|
332
|
+
g.team_stats.values.first.dig('rushing', 'yards')
|
|
333
|
+
|
|
@@ -2,7 +2,7 @@ module Sportradar
|
|
|
2
2
|
module Api
|
|
3
3
|
module Football
|
|
4
4
|
class Player < Data
|
|
5
|
-
attr_accessor :response, :id, :preferred_name, :number, :name_full, :name_first, :name_last, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :depth, :api, :stats
|
|
5
|
+
attr_accessor :response, :id, :preferred_name, :number, :name_full, :name_first, :name_last, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :depth, :api, :stats, :team
|
|
6
6
|
|
|
7
7
|
def initialize(data, **opts)
|
|
8
8
|
@response = data
|
|
@@ -124,4 +124,4 @@ t = ncaafb.teams.sample
|
|
|
124
124
|
data = t.get_season_stats(2016);
|
|
125
125
|
t.get_roster;
|
|
126
126
|
t.players.sample
|
|
127
|
-
t.players.sample.totals
|
|
127
|
+
t.players.sample.totals
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Football
|
|
4
|
+
class StatsShim
|
|
5
|
+
attr_reader :game
|
|
6
|
+
|
|
7
|
+
def initialize(game)
|
|
8
|
+
@game = game
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def dig(player_id, category, stat)
|
|
12
|
+
game.team_stats.each_value do |stats|
|
|
13
|
+
player = stats.public_send(category).for_player(player_id)
|
|
14
|
+
if player
|
|
15
|
+
return player.send(stat)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -13,7 +13,7 @@ sport.get_competitions
|
|
|
13
13
|
comp = sport.competitions.first
|
|
14
14
|
|
|
15
15
|
api = Sportradar::Api::Odds::PlayerOdds.api
|
|
16
|
-
comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:
|
|
16
|
+
comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:109'}, api: api)
|
|
17
17
|
data = comp.get_player_props
|
|
18
18
|
comp.sport_events
|
|
19
19
|
event = comp.sport_events.first
|
|
@@ -31,11 +31,27 @@ module Sportradar
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def get_event_mappings
|
|
34
|
-
data = api.get_data(path_event_mappings)
|
|
34
|
+
data = api.get_data(path_event_mappings).fetch('mappings', [])
|
|
35
|
+
if data.size == 1000
|
|
36
|
+
new_data = data
|
|
37
|
+
while new_data.size == 1000
|
|
38
|
+
new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
|
|
39
|
+
data += new_data
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
{'mappings' => data }
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
def get_player_mappings
|
|
38
|
-
data = api.get_data(path_player_mappings)
|
|
46
|
+
data = api.get_data(path_player_mappings).fetch('mappings', [])
|
|
47
|
+
if data.size == 1000
|
|
48
|
+
new_data = data
|
|
49
|
+
while new_data.size == 1000
|
|
50
|
+
new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
|
|
51
|
+
data += new_data
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
{'mappings' => data }
|
|
39
55
|
end
|
|
40
56
|
|
|
41
57
|
def get_competitor_mappings
|
|
@@ -28,13 +28,21 @@ module Sportradar
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def get_player_props
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
prop_data = fetch_player_props.fetch('competition_sport_events_players_props', [])
|
|
32
|
+
if prop_data.size == 10
|
|
33
|
+
new_data = prop_data
|
|
34
|
+
while new_data.size == 10
|
|
35
|
+
new_data = fetch_player_props(start: prop_data.size).fetch('competition_sport_events_players_props', [])
|
|
36
|
+
prop_data += new_data
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
data = {'competition_sport_events_players_props' => prop_data }
|
|
40
|
+
create_data(@sport_events_hash, prop_data, klass: SportEvent, api: api)
|
|
33
41
|
data
|
|
34
42
|
end
|
|
35
43
|
|
|
36
|
-
def fetch_player_props
|
|
37
|
-
api.get_data(path_player_props)
|
|
44
|
+
def fetch_player_props(params = {})
|
|
45
|
+
api.get_data(path_player_props, params)
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
# url path helpers
|
|
@@ -30,8 +30,6 @@ module Sportradar
|
|
|
30
30
|
def update(data, **opts)
|
|
31
31
|
create_data(@player_props_hash, data['players_props'], klass: PlayerProp, api: api) if data['players_props']
|
|
32
32
|
create_data(@player_markets_hash, data['players_markets'], klass: Market, api: api) if data['players_markets']
|
|
33
|
-
rescue => e
|
|
34
|
-
binding.pry
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
end
|
|
@@ -52,10 +52,27 @@ module Sportradar
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
def hierarchy
|
|
56
|
+
self.get_seasons
|
|
57
|
+
season = self.latest_season
|
|
58
|
+
season.get_competitors
|
|
59
|
+
season.competitors
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def teams
|
|
63
|
+
season = self.latest_season
|
|
64
|
+
season.get_competitors if season.competitors.empty?
|
|
65
|
+
season.competitors
|
|
66
|
+
end
|
|
67
|
+
|
|
55
68
|
def current_season
|
|
56
69
|
seasons.detect(&:current?)
|
|
57
70
|
end
|
|
58
71
|
|
|
72
|
+
def latest_season
|
|
73
|
+
seasons.max_by(&:end_date)
|
|
74
|
+
end
|
|
75
|
+
|
|
59
76
|
def standings(type = nil)
|
|
60
77
|
if type
|
|
61
78
|
@standings_hash[type]
|
|
@@ -3,7 +3,7 @@ module Sportradar
|
|
|
3
3
|
module Soccer
|
|
4
4
|
class Player < Data
|
|
5
5
|
|
|
6
|
-
attr_reader :id, :league_group, :name, :type, :nationality, :country_code, :height, :weight, :jersey_number, :preferred_foot, :stats, :game_stats, :date_of_birth, :matches_played, :starter
|
|
6
|
+
attr_reader :id, :league_group, :name, :type, :nationality, :country_code, :height, :weight, :jersey_number, :preferred_foot, :stats, :game_stats, :date_of_birth, :matches_played, :starter, :team
|
|
7
7
|
alias :position :type
|
|
8
8
|
|
|
9
9
|
def initialize(data = {}, league_group: nil, **opts)
|
|
@@ -116,6 +116,10 @@ module Sportradar
|
|
|
116
116
|
@name.split()[0].delete(',')
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
def injured?
|
|
120
|
+
false
|
|
121
|
+
end
|
|
122
|
+
|
|
119
123
|
def api
|
|
120
124
|
@api || Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
121
125
|
end
|
|
@@ -10,6 +10,7 @@ module Sportradar
|
|
|
10
10
|
@api = opts[:api]
|
|
11
11
|
@competition = competition
|
|
12
12
|
@matches_hash = {}
|
|
13
|
+
@competitors_hash = {}
|
|
13
14
|
|
|
14
15
|
update(data, **opts)
|
|
15
16
|
end
|
|
@@ -31,6 +32,7 @@ module Sportradar
|
|
|
31
32
|
@min_coverage_level = data['min_coverage_level'] || @min_coverage_level
|
|
32
33
|
|
|
33
34
|
parse_schedule(data)
|
|
35
|
+
parse_competitors(data)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
# def get_tournament_id(data, **opts)
|
|
@@ -51,12 +53,22 @@ module Sportradar
|
|
|
51
53
|
@matches_hash.values
|
|
52
54
|
end
|
|
53
55
|
|
|
56
|
+
def competitors
|
|
57
|
+
@competitors_hash.values
|
|
58
|
+
end
|
|
59
|
+
|
|
54
60
|
def parse_schedule(data)
|
|
55
61
|
if data['schedules']
|
|
56
62
|
create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self)
|
|
57
63
|
end
|
|
58
64
|
end
|
|
59
65
|
|
|
66
|
+
def parse_competitors(data)
|
|
67
|
+
if data['season_competitors']
|
|
68
|
+
create_data(@competitors_hash, data['season_competitors'], klass: Team, api: api, competition: @competition, season: self)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
60
72
|
def api
|
|
61
73
|
@api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
62
74
|
end
|
|
@@ -78,6 +90,20 @@ module Sportradar
|
|
|
78
90
|
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
79
91
|
data
|
|
80
92
|
end
|
|
93
|
+
|
|
94
|
+
def path_competitors
|
|
95
|
+
"#{ path_base }/competitors"
|
|
96
|
+
end
|
|
97
|
+
def get_competitors
|
|
98
|
+
data = api.get_data(path_competitors).to_h
|
|
99
|
+
ingest_competitors(data)
|
|
100
|
+
end
|
|
101
|
+
def ingest_competitors(data)
|
|
102
|
+
@competitors_retrieved = true
|
|
103
|
+
update(data)
|
|
104
|
+
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
105
|
+
data
|
|
106
|
+
end
|
|
81
107
|
def queue_schedule
|
|
82
108
|
url, headers, options, timeout = api.get_request_info(path_schedule)
|
|
83
109
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
@@ -15,6 +15,7 @@ module Sportradar
|
|
|
15
15
|
@response = data
|
|
16
16
|
@id = data['id']
|
|
17
17
|
@api = opts[:api]
|
|
18
|
+
@season = opts[:season]
|
|
18
19
|
@league_group = league_group || data['league_group'] || @api&.league_group
|
|
19
20
|
|
|
20
21
|
@players_hash = {}
|
|
@@ -27,7 +28,7 @@ module Sportradar
|
|
|
27
28
|
def update(data, **opts)
|
|
28
29
|
@id = data['id'] if data['id']
|
|
29
30
|
@league_group = opts[:league_group] || data['league_group'] || @league_group
|
|
30
|
-
get_tournament_id(data, **opts)
|
|
31
|
+
# get_tournament_id(data, **opts)
|
|
31
32
|
|
|
32
33
|
if data["team"]
|
|
33
34
|
update(data["team"])
|
|
@@ -92,7 +93,7 @@ module Sportradar
|
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def path_base
|
|
95
|
-
"
|
|
96
|
+
"competitors/#{ id }"
|
|
96
97
|
end
|
|
97
98
|
|
|
98
99
|
def path_roster
|
|
@@ -143,11 +144,16 @@ module Sportradar
|
|
|
143
144
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
144
145
|
end
|
|
145
146
|
|
|
146
|
-
def
|
|
147
|
-
|
|
147
|
+
def season_id
|
|
148
|
+
@season&.id
|
|
148
149
|
end
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
|
|
151
|
+
def path_statistics(season_id = self.season_id)
|
|
152
|
+
"seasons/#{ season_id }/#{ path_base }/statistics"
|
|
153
|
+
end
|
|
154
|
+
def get_statistics(season_id = self.season_id)
|
|
155
|
+
return unless season_id
|
|
156
|
+
data = api.get_data(path_statistics(season_id)).to_h
|
|
151
157
|
ingest_statistics(data)
|
|
152
158
|
end
|
|
153
159
|
def get_season_stats(*args)
|
data/lib/sportradar/api.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sportradar-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.19.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Eggett
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -380,6 +380,7 @@ files:
|
|
|
380
380
|
- lib/sportradar/api/football/stat_pack/punts.rb
|
|
381
381
|
- lib/sportradar/api/football/stat_pack/receiving.rb
|
|
382
382
|
- lib/sportradar/api/football/stat_pack/rushing.rb
|
|
383
|
+
- lib/sportradar/api/football/stats_shim.rb
|
|
383
384
|
- lib/sportradar/api/football/team.rb
|
|
384
385
|
- lib/sportradar/api/football/venue.rb
|
|
385
386
|
- lib/sportradar/api/football/week.rb
|