sportradar-api 0.11.20 → 0.11.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34039ffb330d2d2a183c38371c0eaa1775b58740
4
- data.tar.gz: 748df417602e1d813f5cc1f2d943e4091ae65fcb
3
+ metadata.gz: 0ad1a37c66ad02b3ecb3dc79ed67c9f8546b5748
4
+ data.tar.gz: 79a57f892f9249f5faffc0e6700d3a840d202273
5
5
  SHA512:
6
- metadata.gz: 39f0da60a89d80b56fde095ce1a95d4f17ff4ba82fc5bf74091a74f071fb1be03e79e9a564b44643d9cbba1e4d557336fbed2d8c256435662d180dd1a8669332
7
- data.tar.gz: 939cf4cba13e644a547799d8998831c8b58d6fb42328426ea50ea1e9970fe1ddc58c6ea7bf93c89f08d921b5b1d481522fd49800f2a1f39f46f66e0f2cf19645
6
+ metadata.gz: 79862e808daca8162ac909386162449ce08a62f02ce39a1a0bab2696862af6a05130314ccf42506e454454770c5e4dbfa520c16c7a6ddc520d46bb2707265019
7
+ data.tar.gz: 87577c225c22692da349f485222271fe1fc3574308aecbc1fd77299411b52cd224726d7a642ffe9f9a396de422164cb5bbe52fcb9c35de3b41ea6d0a68341e78
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.11.20)
4
+ sportradar-api (0.11.21)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
@@ -50,6 +50,9 @@ require "sportradar/api/football/nfl/week"
50
50
  require "sportradar/api/football/nfl/division"
51
51
  require "sportradar/api/football/nfl/conference"
52
52
  require "sportradar/api/football/nfl/team"
53
+ require "sportradar/api/football/nfl/league_depth_chart"
54
+ require "sportradar/api/football/nfl/team_depth_chart"
55
+ require "sportradar/api/football/nfl/depth_chart"
53
56
  require "sportradar/api/football/nfl/game"
54
57
  require "sportradar/api/football/nfl/quarter"
55
58
  require "sportradar/api/football/nfl/drive"
@@ -14,10 +14,12 @@ module Sportradar
14
14
  @season = opts[:year]
15
15
  @type = opts[:type]
16
16
 
17
- @conferences_hash = {}
18
- @weeks_hash = {}
19
- @games_hash = {}
20
- @teams_hash = {}
17
+ @conferences_hash = {}
18
+ @weeks_hash = {}
19
+ @depth_charts_hash = {}
20
+ # @injuries_hash = {}
21
+ @games_hash = {}
22
+ @teams_hash = {}
21
23
 
22
24
  end
23
25
 
@@ -58,6 +60,11 @@ module Sportradar
58
60
 
59
61
  self
60
62
  end
63
+
64
+ def weekly_depth_charts(week_number)
65
+ @depth_charts_hash[week_number] ||= get_weekly_depth_charts(week_number)
66
+ end
67
+
61
68
  def weeks
62
69
  @weeks_hash.values
63
70
  end
@@ -150,9 +157,12 @@ module Sportradar
150
157
  def path_weekly_schedule(nfl_season_week)
151
158
  "games/#{season_year}/#{nfl_season}/#{nfl_season_week}/schedule"
152
159
  end
153
- # def path_rankings(nfl_season_week, poll_name = 'AP25')
154
- # "polls/#{poll_name}/#{season_year}/#{nfl_season_week}/rankings"
155
- # end
160
+ def path_weekly_depth_charts(nfl_season_week)
161
+ "seasontd/#{season_year}/#{nfl_season}/#{nfl_season_week}/depth_charts"
162
+ end
163
+ def path_weekly_depth_injuries(nfl_season_week)
164
+ "seasontd/#{season_year}/#{nfl_season}/#{nfl_season_week}/injuries"
165
+ end
156
166
  def path_standings
157
167
  "seasontd/#{season_year}/standings"
158
168
  end
@@ -192,6 +202,21 @@ module Sportradar
192
202
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_weekly_schedule)}
193
203
  end
194
204
 
205
+ ## weekly depth charts
206
+ private def get_weekly_depth_charts(nfl_season_week = 1)
207
+ data = api.get_data(path_weekly_depth_charts(nfl_season_week)).to_h
208
+ ingest_weekly_depth_charts(data)
209
+ end
210
+
211
+ private def ingest_weekly_depth_charts(data)
212
+ LeagueDepthChart.new(data, api: api)
213
+ end
214
+
215
+ # def queue_weekly_depth_charts(nfl_season_week = 1)
216
+ # url, headers, options, timeout = api.get_request_info(path_weekly_depth_charts(nfl_season_week))
217
+ # {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_weekly_depth_charts)}
218
+ # end
219
+
195
220
  ## hierarchy
196
221
  def get_hierarchy
197
222
  data = api.get_data(path_hierarchy).to_h
@@ -291,3 +316,7 @@ res2 = nfl.get_weekly_schedule;
291
316
  nfl = Marshal.load(File.binread('nfl.bin'));
292
317
  File.binwrite('nfl.bin', Marshal.dump(nfl))
293
318
 
319
+ nfl = Sportradar::Api::Football::Nfl.new
320
+ nfl.season = 2016
321
+ res = nfl.get_weekly_depth_charts
322
+ dc = nfl.instance_variable_get(:@depth_charts_hash)
@@ -0,0 +1,53 @@
1
+ module Sportradar
2
+ module Api
3
+ module Football
4
+ class Nfl
5
+ class DepthChart < Data
6
+ include Enumerable
7
+ attr_accessor :response, :chart
8
+
9
+ def initialize(data)
10
+ generate_chart(data)
11
+ end
12
+
13
+ def team(number)
14
+ teams[number]
15
+ end
16
+
17
+ def each
18
+ populate_teams
19
+ teams.each { |team| yield team }
20
+ end
21
+
22
+ private
23
+
24
+ def teams
25
+ @teams ||= populate_teams
26
+ end
27
+
28
+ def populate_teams
29
+ (1..3).each_with_object({}) do |i, hash|
30
+ hash[i] = generate_team(i)
31
+ end
32
+ end
33
+
34
+ def generate_team(number)
35
+ @chart.each_with_object({}) do |(pos_name, groups), memo|
36
+ memo[pos_name] = groups[number]
37
+ end
38
+ end
39
+
40
+ def generate_chart(data)
41
+ @chart = data.each_with_object({}) do |hash, memo|
42
+ position = hash['position']
43
+ players = position['players'].map { |h| Sportradar::Api::Football::Nfl::Player.new(h) }
44
+ memo[position['name']] = players.group_by(&:depth)
45
+ # binding.pry
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,41 @@
1
+ module Sportradar
2
+ module Api
3
+ module Football
4
+ class Nfl
5
+ class LeagueDepthChart < Data
6
+ include Enumerable
7
+ attr_accessor :response, :week_number, :charts
8
+
9
+ def initialize(data, **opts)
10
+ @response = data
11
+ @charts_hash = {}
12
+
13
+ update(data, **opts)
14
+ end
15
+
16
+ def update(data, **opts)
17
+ @week = data['week']
18
+ @week_number = data.dig('week', 'sequence')
19
+ create_data(@charts_hash, data["teams"], klass: TeamDepthChart, api: opts[:api])
20
+
21
+ self
22
+ end
23
+
24
+ def charts
25
+ @charts_hash.values
26
+ end
27
+
28
+ # id is preferred search, but we allow for team abbreviation too
29
+ def team(id = nil, abbrev: nil)
30
+ charts.detect { |chart| chart.team_id == id || chart.abbrev == abbrev }
31
+ end
32
+
33
+ def each
34
+ self.charts.each { |chart| yield chart }
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ module Sportradar
2
+ module Api
3
+ module Football
4
+ class Nfl
5
+ class TeamDepthChart < Data
6
+ include Enumerable
7
+ attr_accessor :response, :season, :team_id, :abbrev
8
+ alias :id :team_id
9
+
10
+ # data.keys => ["offense", "defense", "special_teams", "name", "market", "alias", "id"]
11
+ def initialize(data, **opts)
12
+ @response = data
13
+ @team_id = data['id']
14
+ @abbrev = data['alias']
15
+ end
16
+
17
+ def offense
18
+ @offense ||= DepthChart.new(response['offense']) if response['offense']
19
+ end
20
+
21
+ def defense
22
+ @defense ||= DepthChart.new(response['defense']) if response['defense']
23
+ end
24
+
25
+ def special_teams
26
+ @special_teams ||= DepthChart.new(response['special_teams']) if response['special_teams']
27
+ end
28
+
29
+ def each
30
+ [:offense, :defense, :special_teams].each { |type| yield type, send(type) }
31
+ end
32
+
33
+ # These aren't ever used, but handy if you need to invoke for testing
34
+ # private
35
+
36
+ # def set_charts
37
+ # [offense, defense, special_teams]
38
+ # end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -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, :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
6
6
 
7
7
  def initialize(data, **opts)
8
8
  @response = data
@@ -54,6 +54,7 @@ module Sportradar
54
54
  @updated = data['updated'] if data['updated'] # "2016-07-08T12:11:59+00:00",
55
55
 
56
56
 
57
+ @depth = data['depth'] if data['depth']
57
58
  @games_started = data['games_started'] if data['games_started']
58
59
  @games_played = data['games_played'] if data['games_played']
59
60
  # NCAA specific below
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.11.20"
3
+ VERSION = "0.11.21"
4
4
  end
5
5
  end
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.11.20
4
+ version: 0.11.21
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-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -366,14 +366,17 @@ files:
366
366
  - lib/sportradar/api/football/nfl.rb
367
367
  - lib/sportradar/api/football/nfl/api.rb
368
368
  - lib/sportradar/api/football/nfl/conference.rb
369
+ - lib/sportradar/api/football/nfl/depth_chart.rb
369
370
  - lib/sportradar/api/football/nfl/division.rb
370
371
  - lib/sportradar/api/football/nfl/drive.rb
371
372
  - lib/sportradar/api/football/nfl/event.rb
372
373
  - lib/sportradar/api/football/nfl/game.rb
374
+ - lib/sportradar/api/football/nfl/league_depth_chart.rb
373
375
  - lib/sportradar/api/football/nfl/play.rb
374
376
  - lib/sportradar/api/football/nfl/player.rb
375
377
  - lib/sportradar/api/football/nfl/quarter.rb
376
378
  - lib/sportradar/api/football/nfl/team.rb
379
+ - lib/sportradar/api/football/nfl/team_depth_chart.rb
377
380
  - lib/sportradar/api/football/nfl/week.rb
378
381
  - lib/sportradar/api/football/play.rb
379
382
  - lib/sportradar/api/football/play_statistics.rb