sportradar-api 0.12.0 → 0.12.1
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/events/at_bat.rb +4 -0
- data/lib/sportradar/api/baseball/player.rb +6 -6
- data/lib/sportradar/api/baseball/team.rb +5 -5
- data/lib/sportradar/api/basketball/nba/player.rb +6 -2
- data/lib/sportradar/api/basketball/ncaamb/player.rb +6 -2
- data/lib/sportradar/api/basketball/team.rb +29 -18
- data/lib/sportradar/api/football/game.rb +10 -5
- data/lib/sportradar/api/football/ncaafb/drive.rb +1 -1
- data/lib/sportradar/api/football/ncaafb/quarter.rb +8 -0
- data/lib/sportradar/api/football/nfl/quarter.rb +8 -0
- data/lib/sportradar/api/football/player.rb +10 -4
- data/lib/sportradar/api/football/quarter.rb +3 -3
- data/lib/sportradar/api/football/team.rb +6 -1
- data/lib/sportradar/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b514a3e1f6532c216d3d19df5c189b45e4686f0c
|
|
4
|
+
data.tar.gz: 9c08fc98da409006c5cea61c24b8976cb3af8bde
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5058da90f72b7c8ddbf3b9172797e8684ae3e1275c2543439e44b37d462684e05b2a65400a14c02dfea087caceaf30656b35c4c2fc98d27a21c2cc82e31ffa4b
|
|
7
|
+
data.tar.gz: 64dd72c03e03dec6bfd556da1b2a677c9bbf1ddfe70add51c73fb899f8a6a64808c46e75b118e558c0034b8ed651ff9f4743571aa0c629ba7468c78c5af82c58
|
data/Gemfile.lock
CHANGED
|
@@ -2,7 +2,7 @@ module Sportradar
|
|
|
2
2
|
module Api
|
|
3
3
|
module Baseball
|
|
4
4
|
class Player < Data
|
|
5
|
-
attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :primary_position, :birth_place, :college, :height, :weight, :draft, :hitting, :pitching, :fielding, :team
|
|
5
|
+
attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :primary_position, :birth_place, :college, :height, :weight, :draft, :hitting, :pitching, :fielding, :team, :stats
|
|
6
6
|
|
|
7
7
|
def initialize(data, **opts)
|
|
8
8
|
@response = data # comment this out when done developing
|
|
@@ -62,13 +62,13 @@ module Sportradar
|
|
|
62
62
|
update_draft(data)
|
|
63
63
|
|
|
64
64
|
@team.update_player_stats(self, data['statistics'], opts[:game]) if data['statistics']
|
|
65
|
-
if stats = data['statistics']
|
|
66
|
-
@fielding = stats.dig('fielding', 'overall')
|
|
67
|
-
@pitching = stats.dig('pitching', 'overall')
|
|
68
|
-
@hitting = stats.dig('hitting', 'overall')
|
|
65
|
+
if @stats = data['statistics']
|
|
66
|
+
@fielding = @stats.dig('fielding', 'overall')
|
|
67
|
+
@pitching = @stats.dig('pitching', 'overall')
|
|
68
|
+
@hitting = @stats.dig('hitting', 'overall')
|
|
69
69
|
|
|
70
70
|
# used to be @team, lets leave as opt until it needs to go back
|
|
71
|
-
opts[:team].update_player_stats(self, stats)
|
|
71
|
+
opts[:team].update_player_stats(self, @stats)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
self
|
|
@@ -81,7 +81,7 @@ module Sportradar
|
|
|
81
81
|
create_data(@players_hash, data, klass: Player, api: api, team: self, game: game)
|
|
82
82
|
end
|
|
83
83
|
def update_player_stats(player, stats, game = nil)
|
|
84
|
-
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge
|
|
84
|
+
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge(player: player))
|
|
85
85
|
end
|
|
86
86
|
def parse_records(data)
|
|
87
87
|
@records['overall'] = Record.new(data, type: 'overall')
|
|
@@ -99,7 +99,7 @@ module Sportradar
|
|
|
99
99
|
# data retrieval
|
|
100
100
|
|
|
101
101
|
def get_roster
|
|
102
|
-
data = api.get_data(path_roster)
|
|
102
|
+
data = api.get_data(path_roster).to_h
|
|
103
103
|
ingest_roster(data)
|
|
104
104
|
end
|
|
105
105
|
def ingest_roster(data)
|
|
@@ -112,14 +112,14 @@ module Sportradar
|
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
def get_season_stats(year = Date.today.year)
|
|
115
|
-
data = api.get_data(path_season_stats(year))
|
|
115
|
+
data = api.get_data(path_season_stats(year)).to_h
|
|
116
116
|
ingest_season_stats(data)
|
|
117
117
|
end
|
|
118
118
|
def ingest_season_stats(data)
|
|
119
119
|
parse_season_stats(data)
|
|
120
120
|
end
|
|
121
|
-
def queue_season_stats
|
|
122
|
-
url, headers, options, timeout = api.get_request_info(path_season_stats)
|
|
121
|
+
def queue_season_stats(year = Date.today.year)
|
|
122
|
+
url, headers, options, timeout = api.get_request_info(path_season_stats(year))
|
|
123
123
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_season_stats)}
|
|
124
124
|
end
|
|
125
125
|
|
|
@@ -3,7 +3,7 @@ module Sportradar
|
|
|
3
3
|
module Basketball
|
|
4
4
|
class Nba
|
|
5
5
|
class Player < Data
|
|
6
|
-
attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft
|
|
6
|
+
attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :stats
|
|
7
7
|
# @all_hash = {}
|
|
8
8
|
# def self.new(data, **opts)
|
|
9
9
|
# existing = @all_hash[data['id']]
|
|
@@ -69,7 +69,11 @@ module Sportradar
|
|
|
69
69
|
@team.update_player_stats(self, data['statistics'], opts[:game]) if data['statistics']
|
|
70
70
|
if avgs = data['average']
|
|
71
71
|
@totals = data['total']
|
|
72
|
-
@averages = avgs
|
|
72
|
+
@averages = avgs
|
|
73
|
+
@stats = {
|
|
74
|
+
'total' => @totals,
|
|
75
|
+
'averages' => @averages,
|
|
76
|
+
}
|
|
73
77
|
@team.update_player_stats(self, avgs)
|
|
74
78
|
end
|
|
75
79
|
|
|
@@ -3,7 +3,7 @@ module Sportradar
|
|
|
3
3
|
module Basketball
|
|
4
4
|
class Ncaamb
|
|
5
5
|
class Player < Data
|
|
6
|
-
attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft
|
|
6
|
+
attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :stats
|
|
7
7
|
# @all_hash = {}
|
|
8
8
|
# def self.new(data, **opts)
|
|
9
9
|
# existing = @all_hash[data['id']]
|
|
@@ -71,7 +71,11 @@ module Sportradar
|
|
|
71
71
|
@team.update_player_stats(self, data['statistics'], opts[:game]) if data['statistics']
|
|
72
72
|
if avgs = data['average']
|
|
73
73
|
@totals = data['total']
|
|
74
|
-
@averages = avgs
|
|
74
|
+
@averages = avgs
|
|
75
|
+
@stats = {
|
|
76
|
+
'total' => @totals,
|
|
77
|
+
'averages' => @averages,
|
|
78
|
+
}
|
|
75
79
|
@team.update_player_stats(self, avgs)
|
|
76
80
|
end
|
|
77
81
|
|
|
@@ -84,39 +84,50 @@ module Sportradar
|
|
|
84
84
|
create_data(@players_hash, data, klass: player_class, api: api, team: self, game: game)
|
|
85
85
|
end
|
|
86
86
|
def update_player_stats(player, stats, game = nil)
|
|
87
|
-
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge
|
|
87
|
+
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge(player: player))
|
|
88
88
|
end
|
|
89
|
+
def parse_records(data)
|
|
90
|
+
@records['overall'] = Record.new(data, type: 'overall')
|
|
91
|
+
data['records'].each { |record| @records[record['record_type']] = Record.new(record, type: record['record_type']) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def parse_season_stats(data)
|
|
95
|
+
@team_stats = data.dig('own_record')
|
|
96
|
+
update(data)
|
|
97
|
+
player_data = data.dig('players')
|
|
98
|
+
create_data(@players_hash, player_data, klass: player_class, api: api, team: self)
|
|
99
|
+
data
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# data retrieval
|
|
89
104
|
|
|
90
105
|
def get_roster
|
|
91
|
-
data = api.get_data(path_roster)
|
|
106
|
+
data = api.get_data(path_roster).to_h
|
|
92
107
|
ingest_roster(data)
|
|
93
108
|
end
|
|
94
109
|
def ingest_roster(data)
|
|
95
110
|
update(data)
|
|
96
111
|
data
|
|
97
112
|
end
|
|
113
|
+
def queue_roster
|
|
114
|
+
url, headers, options, timeout = api.get_request_info(path_roster)
|
|
115
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_roster)}
|
|
116
|
+
end
|
|
98
117
|
|
|
99
|
-
def get_season_stats
|
|
100
|
-
data = api.get_data(path_season_stats)
|
|
118
|
+
def get_season_stats(year = Date.today.year)
|
|
119
|
+
data = api.get_data(path_season_stats(year)).to_h
|
|
101
120
|
ingest_season_stats(data)
|
|
102
121
|
end
|
|
103
122
|
def ingest_season_stats(data)
|
|
104
123
|
parse_season_stats(data)
|
|
105
124
|
end
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
data['records'].each { |record| @records[record['record_type']] = Record.new(record, type: record['record_type']) }
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def parse_season_stats(data)
|
|
113
|
-
@team_stats = data.dig('own_record')
|
|
114
|
-
update(data)
|
|
115
|
-
player_data = data.dig('players')
|
|
116
|
-
create_data(@players_hash, player_data, klass: player_class, api: api, team: self)
|
|
117
|
-
data
|
|
125
|
+
def queue_season_stats
|
|
126
|
+
url, headers, options, timeout = api.get_request_info(path_season_stats)
|
|
127
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_season_stats)}
|
|
118
128
|
end
|
|
119
129
|
|
|
130
|
+
# url path helpers
|
|
120
131
|
def path_base
|
|
121
132
|
"teams/#{ id }"
|
|
122
133
|
end
|
|
@@ -126,8 +137,8 @@ module Sportradar
|
|
|
126
137
|
def path_roster
|
|
127
138
|
"#{ path_base }/profile"
|
|
128
139
|
end
|
|
129
|
-
def path_season_stats
|
|
130
|
-
"#{ path_base_stats }/statistics"
|
|
140
|
+
def path_season_stats(year)
|
|
141
|
+
"#{ path_base_stats(year) }/statistics"
|
|
131
142
|
end
|
|
132
143
|
|
|
133
144
|
end
|
|
@@ -159,8 +159,8 @@ module Sportradar
|
|
|
159
159
|
@score.merge!(score)
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
-
def update_drives(data)
|
|
163
|
-
create_data(@drives_hash, data, klass: drive_class, api: api, game: self)
|
|
162
|
+
def update_drives(data, **opts)
|
|
163
|
+
create_data(@drives_hash, data, klass: drive_class, api: api, game: self, **opts)
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
def leading_team_id
|
|
@@ -173,7 +173,7 @@ module Sportradar
|
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
def current_possession_team_id
|
|
176
|
-
drives.
|
|
176
|
+
drives.last&.team_id
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
def next_possession_team_id
|
|
@@ -209,10 +209,15 @@ module Sportradar
|
|
|
209
209
|
@pbp ||= quarters
|
|
210
210
|
end
|
|
211
211
|
|
|
212
|
-
def
|
|
212
|
+
def drives_with_events
|
|
213
213
|
@drives_hash.values
|
|
214
214
|
end
|
|
215
215
|
|
|
216
|
+
def drives
|
|
217
|
+
drives_with_events.grep(Sportradar::Api::Football::Drive)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
|
|
216
221
|
def plays
|
|
217
222
|
drives.flat_map(&:plays).compact
|
|
218
223
|
end
|
|
@@ -371,7 +376,7 @@ module Sportradar
|
|
|
371
376
|
def ingest_pbp(data)
|
|
372
377
|
data = data
|
|
373
378
|
update(data, source: :pbp)
|
|
374
|
-
create_data(@quarters_hash, data[period_key], klass: quarter_class, identifier:
|
|
379
|
+
create_data(@quarters_hash, data[period_key], klass: quarter_class, identifier: quarter_class.period_index, api: api, game: self) if data[period_key]
|
|
375
380
|
check_newness(:pbp, plays.last&.description)
|
|
376
381
|
check_newness(:score, @score)
|
|
377
382
|
@pbp = @quarters_hash.values
|
|
@@ -9,7 +9,7 @@ module Sportradar
|
|
|
9
9
|
def update(data, **opts)
|
|
10
10
|
super.tap {
|
|
11
11
|
if opts[:game]
|
|
12
|
-
game_drives = opts[:game].drives
|
|
12
|
+
game_drives = opts[:game].drives
|
|
13
13
|
@sequence = (game_drives.index(self) || game_drives.size) + 1
|
|
14
14
|
end
|
|
15
15
|
}
|
|
@@ -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
|
|
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
|
|
6
6
|
|
|
7
7
|
def initialize(data, **opts)
|
|
8
8
|
@response = data
|
|
@@ -62,10 +62,16 @@ module Sportradar
|
|
|
62
62
|
# update_injuries(data)
|
|
63
63
|
# update_draft(data)
|
|
64
64
|
|
|
65
|
-
if stats = data['statistics']
|
|
66
|
-
@totals = stats
|
|
65
|
+
if @stats = data['statistics']
|
|
66
|
+
@totals = @stats
|
|
67
67
|
# binding.pry
|
|
68
|
-
@team.update_player_stats(self, stats.dup, opts[:game])
|
|
68
|
+
@team.update_player_stats(self, @stats.dup, opts[:game])
|
|
69
|
+
elsif @stats = data['games_played']
|
|
70
|
+
@stats = data.dup
|
|
71
|
+
%w[id name jersey reference position].each do |useless_key|
|
|
72
|
+
@stats.delete(useless_key)
|
|
73
|
+
end
|
|
74
|
+
@totals = @stats
|
|
69
75
|
else
|
|
70
76
|
@totals = {}
|
|
71
77
|
end
|
|
@@ -6,7 +6,7 @@ module Sportradar
|
|
|
6
6
|
|
|
7
7
|
def initialize(data, **opts)
|
|
8
8
|
@response = data
|
|
9
|
-
@id = data[
|
|
9
|
+
@id = data[self.class.period_index]
|
|
10
10
|
@api = opts[:api]
|
|
11
11
|
|
|
12
12
|
@drives_hash = {}
|
|
@@ -24,7 +24,7 @@ module Sportradar
|
|
|
24
24
|
@away_info = data["away"]
|
|
25
25
|
|
|
26
26
|
if data['pbp']
|
|
27
|
-
opts[:game].update_drives(data['pbp'])
|
|
27
|
+
opts[:game].update_drives(data['pbp'], quarter: self)
|
|
28
28
|
create_data(@drives_hash, data['pbp'], klass: drive_class, api: api, quarter: self)
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -32,7 +32,7 @@ module Sportradar
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def overtime?
|
|
35
|
-
@number > 4
|
|
35
|
+
(@sequence || @number) > 4
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def drives
|
|
@@ -87,7 +87,7 @@ module Sportradar
|
|
|
87
87
|
create_data(@players_hash, data, klass: player_class, api: api, team: self, game: game)
|
|
88
88
|
end
|
|
89
89
|
def update_player_stats(player, stats, game = nil)
|
|
90
|
-
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge
|
|
90
|
+
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge(player: player))
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def get_roster
|
|
@@ -98,6 +98,11 @@ module Sportradar
|
|
|
98
98
|
update(data)
|
|
99
99
|
data
|
|
100
100
|
end
|
|
101
|
+
def queue_roster
|
|
102
|
+
url, headers, options, timeout = api.get_request_info(path_roster)
|
|
103
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_roster)}
|
|
104
|
+
end
|
|
105
|
+
|
|
101
106
|
|
|
102
107
|
def get_season_stats(year = default_year)
|
|
103
108
|
data = api.get_data(path_season_stats(year)).to_h
|
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.12.
|
|
4
|
+
version: 0.12.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Eggett
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|