sportradar-api 0.11.16 → 0.11.17

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: 1e3b4cb30868943236c2f7146156415f0cd11f2b
4
- data.tar.gz: 6b456bf0c86224e47b2b54eea5676805a8968503
3
+ metadata.gz: 656c13e99ac76f310f91beaf9d890b14f8072e06
4
+ data.tar.gz: 0be12daa6274862d38426cd8a835b4a08afa65f0
5
5
  SHA512:
6
- metadata.gz: 32a6b6bd9915bcd7965694822af2cf19ea78350d3a7289636c79bc06c4ad1ad0a6c86869e7013ff3dbd97dd6b933503fb05c9130c9251074eb89ab60392b101a
7
- data.tar.gz: 3b9f39f440a4e7f690ee89adf5cea73caebccd1f3b016c0a77e92e1aa8d510a0df1d80b63137d02da47c1427637d23a8706c89ae81c5aadb0e640184376e0163
6
+ metadata.gz: 14518018f128ab8c2b05cd950c06b45280669c4068a4e44178a8461dc53932f90b2a83a73600749f839772fd5623bbbbdfeaf2326bea5f0e072d08aea0cf8f25
7
+ data.tar.gz: 525855febac7015fbdc9e57f81c010c0278c8a6188a7a3c9e2fb7866eef8658f80714e6be6de1c370c7ba35586fca7d29110d426ba23b8a39a9fc3d58fdf5c4b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.11.16)
4
+ sportradar-api (0.11.17)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
@@ -22,6 +22,7 @@ require "sportradar/api/football/player"
22
22
  require "sportradar/api/football/week"
23
23
  require "sportradar/api/football/scoring"
24
24
  require "sportradar/api/football/game_stats"
25
+ require "sportradar/api/football/play_statistics"
25
26
  require "sportradar/api/football/game"
26
27
  require "sportradar/api/football/quarter"
27
28
  require "sportradar/api/football/drive"
@@ -13,6 +13,18 @@ module Sportradar
13
13
  create_data(@events_hash, data['events'], klass: Event, api: api, game: self) if data['events']
14
14
  end
15
15
 
16
+ def play_count
17
+ plays.count { |play| ['rush', 'pass'].include? play.play_type }
18
+ end
19
+
20
+ def gain
21
+ Array(plays.select { |play| ['rush', 'pass'].include? play.play_type }).sum do |play|
22
+ Array(play.players).sum do |p|
23
+ p.dig('passing', 'yds').to_i + p.dig('rushing', 'yds').to_i
24
+ end
25
+ end
26
+ end
27
+
16
28
  end
17
29
  end
18
30
  end
@@ -11,6 +11,12 @@ module Sportradar
11
11
  super
12
12
  end
13
13
 
14
+ def clock_display
15
+ if clock && quarter
16
+ quarter > 4 ? quarter_display : "#{clock} #{quarter_display}"
17
+ end
18
+ end
19
+
14
20
  def path_base
15
21
  "#{ year }/#{ type }/#{ week_number.to_s }/#{ away_alias }/#{ home_alias }"
16
22
  end
@@ -6,9 +6,12 @@ module Sportradar
6
6
 
7
7
 
8
8
  def parsed_ending
9
- @parsed_ending ||= parse_description_for_drive_end
9
+ @parsed_ending ||= search_for_drive_end
10
10
  end
11
11
 
12
+ def halftime?
13
+ @description == "End of 1st Half"
14
+ end
12
15
 
13
16
  def queue_details
14
17
  if @details
@@ -27,6 +30,30 @@ module Sportradar
27
30
 
28
31
  private
29
32
 
33
+ def search_for_drive_end
34
+ case @play_type
35
+ when 'kick'
36
+ nil
37
+ when 'rush'
38
+ # check for fumble
39
+ parse_description_for_drive_end
40
+ when 'pass'
41
+ # check for fumble/interception
42
+ parse_description_for_drive_end
43
+ when 'punt'
44
+ :punt
45
+ when 'penalty'
46
+ nil
47
+ when 'fieldgoal'
48
+ :fg
49
+ when 'extrapoint'
50
+ :pat
51
+ else
52
+ parse_description_for_drive_end
53
+ end
54
+ end
55
+
56
+ # ["kick", "rush", "pass", "punt", "penalty", nil, "fieldgoal", "extrapoint"]
30
57
  def parse_description_for_drive_end
31
58
  parsed_ending = case @description
32
59
  when /intercepted/i
@@ -40,6 +67,8 @@ module Sportradar
40
67
  :punt
41
68
  when /Field Goal is No Good. blocked/i
42
69
  :fg
70
+ when /Field Goal is No Good/i
71
+ :fg
43
72
  # when missed field goal
44
73
  when /Field Goal is Good/i
45
74
  :fg
@@ -58,3 +87,7 @@ module Sportradar
58
87
  end
59
88
  end
60
89
  end
90
+
91
+ __END__
92
+
93
+ {"id"=>"694bb030-be6c-4b6f-a77d-1ea103749463", "game"=>"b3dca62c-f306-4fb8-9856-808e7b42a89f", "type"=>"pass", "official"=>true, "clock"=>":29", "quarter"=>3, "controller"=>"FLA", "updated"=>"2015-08-12T17:03:19+00:00", "formation"=>"Shotgun", "direction"=>"Right", "distance"=>"Short", "summary"=>"6-J.Driskel complete to 11-D.Robinson. 11-D.Robinson runs 9 yards for a touchdown.", "start_situation"=>{"team"=>"FLA", "side"=>"KEN", "yard_line"=>9, "down"=>2, "yfd"=>9}, "end_situation"=>{"team"=>"FLA", "side"=>"KEN", "yard_line"=>2}, "advancements"=>[{"type"=>"progression", "sequence"=>1, "team"=>"FLA", "from"=>{"side"=>"KEN", "yard_line"=>9}, "to"=>{"side"=>"KEN", "yard_line"=>0}}], "score"=>{"type"=>"touchdown", "points"=>6, "team"=>"FLA"}, "players"=>[{"id"=>"55bf8c60-6953-4d83-9982-7e38ff867130", "name"=>"Jeff Driskel", "jersey"=>6, "position"=>"QB", "team"=>"FLA", "passing"=>{"att"=>1, "cmp"=>1, "yds"=>9, "sk"=>0, "sk_yds"=>0, "td"=>1, "int"=>0, "fd"=>1, "sfty"=>0, "rz_att"=>1}}, {"id"=>"9252aab2-b175-4e2f-974d-dc7f6f8c3b3a", "name"=>"Demarcus Robinson", "jersey"=>11, "position"=>"WR", "team"=>"FLA", "receiving"=>{"tar"=>1, "rec"=>1, "yds"=>9, "yac"=>9, "td"=>1, "fum"=>0, "fd"=>1, "rz_tar"=>1}}]}
@@ -2,7 +2,7 @@ module Sportradar
2
2
  module Api
3
3
  module Football
4
4
  class Play < Data
5
- attr_accessor :response, :id, :sequence, :reference, :clock, :home_points, :away_points, :type, :play_clock, :wall_clock, :start_situation, :end_situation, :description, :alt_description, :statistics, :score, :scoring_play, :team_id, :player_id, :play_type
5
+ attr_accessor :response, :id, :sequence, :reference, :clock, :home_points, :away_points, :type, :play_clock, :wall_clock, :start_situation, :end_situation, :description, :alt_description, :statistics, :score, :scoring_play, :team_id, :player_id, :play_type, :players
6
6
 
7
7
  def initialize(data, **opts)
8
8
  @response = data
@@ -43,10 +43,11 @@ module Sportradar
43
43
  @participants = data["participants"] if data["participants"]
44
44
  @play_type = data["play_type"] if data["play_type"]
45
45
  @sequence = data["sequence"] if data["sequence"]
46
+ @players = data["players"] if data["players"]
46
47
 
47
48
  @details = data["details"].gsub('.json', '') if data["details"]
48
49
 
49
- # @statistics = Sportradar::Api::Nfl::PlayStatistics.new data["statistics"] if data["statistics"]
50
+ @statistics = Sportradar::Api::Football::PlayStatistics.new(data['statistics']) if data['statistics']
50
51
  # parse_player if @statistics
51
52
  @wall_clock = data["wall_clock"]
52
53
 
@@ -0,0 +1,313 @@
1
+ module Sportradar
2
+ module Api
3
+ module Football
4
+ class PlayStatistics < Data
5
+ attr_accessor :response, :kick, :return, :rush, :defense, :receive, :punt, :penalty, :pass, :first_down, :field_goal, :extra_point, :defense, :down_conversion
6
+ def initialize(data)
7
+ data = [data] if data.is_a?(Hash)
8
+ @response = data
9
+ data.each do |hash|
10
+ begin
11
+ klass = self.class.stat_type_classes[hash['stat_type']] || MiscStatistics
12
+ instance_variable_set("@#{hash['stat_type']}", klass.new(hash))
13
+ rescue => e
14
+ binding.pry
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.stat_type_classes
20
+ stat_type_classes ||= {
21
+ 'kick' => PlayKickStatistics,
22
+ 'return' => PlayReturnStatistics,
23
+ 'rush' => PlayRushStatistics,
24
+ 'fumble' => PlayFumbleStatistics,
25
+ 'defense' => PlayDefenseStatistics,
26
+ 'receive' => PlayReceiveStatistics,
27
+ 'punt' => PlayPuntStatistics,
28
+ 'penalty' => PlayPenaltyStatistics,
29
+ 'pass' => PlayPassingStatistics,
30
+ 'first_down' => PlayFirstDownStatistics,
31
+ 'field_goal' => PlayFieldGoalStatistics,
32
+ 'extra_point' => PlayExtraPointStatistics,
33
+ 'down_conversion' => PlayDownConversionStatistics,
34
+ 'conversion' => ConversionStatistics,
35
+ 'block' => BlockStatistics,
36
+ 'misc' => MiscStatistics,
37
+ }.freeze
38
+ end
39
+ end
40
+
41
+ class MiscStatistics < Data
42
+ attr_reader :team, :player, :yards
43
+ def initialize(data)
44
+ @yards = data['yards']
45
+ @team = OpenStruct.new(data['team']) if data['team']
46
+ @player = OpenStruct.new(data['player']) if data['player']
47
+ end
48
+ end
49
+
50
+ class BlockStatistics < Data
51
+ attr_reader :team, :player, :block, :category
52
+ def initialize(data)
53
+ @category = data['category']
54
+ @block = data['block']
55
+ @team = OpenStruct.new(data['team']) if data['team']
56
+ @player = OpenStruct.new(data['player']) if data['player']
57
+ end
58
+ end
59
+
60
+ class PlayDownConversionStatistics < Data
61
+ attr_accessor :attempt, :complete, :down, :nullified, :team
62
+ def initialize(data)
63
+ @attempt = data['attempt']
64
+ @complete = data['complete']
65
+ @down = data['down']
66
+ @team = OpenStruct.new(data['team']) if data['team']
67
+ @nullified = data['nullified']
68
+ end
69
+
70
+ def nullified?
71
+ @nullified.to_s == 'true'
72
+ end
73
+ end
74
+
75
+ class PlayDefenseStatistics < Data
76
+ attr_accessor :ast_tackle, :interception, :int_yards, :nullified, :pass_defended, :primary, :qb_hit, :sack, :sack_yards, :tlost, :tlost_yards, :team, :player, :tackle, :int_touchdown
77
+ def initialize(data)
78
+ @ast_tackle = data['ast_tackle']
79
+ @interception = data['interception']
80
+ @int_yards = data['int_yards']
81
+ @int_touchdown = data['int_touchdown']
82
+ @nullified = data['nullified']
83
+ @pass_defended = data['pass_defended']
84
+ @primary = data['primary']
85
+ @qb_hit = data['qb_hit']
86
+ @sack = data['sack']
87
+ @sack_yards = data['sack_yards']
88
+ @tlost = data['tlost']
89
+ @tlost_yards = data['tlost_yards']
90
+ @tackle = data['tackle']
91
+ @team = OpenStruct.new(data['team']) if data['team']
92
+ @player = OpenStruct.new(data['player']) if data['player']
93
+ @nullified = data['nullified']
94
+ end
95
+
96
+ def nullified?
97
+ @nullified.to_s == 'true'
98
+ end
99
+ end
100
+
101
+ class PlayExtraPointStatistics < Data
102
+ attr_accessor :attempt, :nullified
103
+ def initialize(data)
104
+ @attempt = data['attempt']
105
+ @nullified = data['nullified']
106
+ end
107
+
108
+ def nullified?
109
+ @nullified.to_s == 'true'
110
+ end
111
+ end
112
+
113
+ class PlayFieldGoalStatistics < Data
114
+ attr_accessor :attempt, :att_yards, :missed, :yards, :nullified, :blocked, :team, :player
115
+ def initialize(data)
116
+ @attempt = data['attempt']
117
+ @att_yards = data['att_yards']
118
+ @missed = data['missed']
119
+ @blocked = data['blocked']
120
+ @yards = data['yards']
121
+ @nullified = data['nullified']
122
+ @team = OpenStruct.new(data['team']) if data['team']
123
+ @player = OpenStruct.new(data['player']) if data['player']
124
+ end
125
+
126
+ def nullified?
127
+ @nullified.to_s == 'true'
128
+ end
129
+ end
130
+
131
+ class PlayFirstDownStatistics < Data
132
+ attr_accessor :category, :nullified, :team
133
+ def initialize(data)
134
+ @category = data['category']
135
+ @team = OpenStruct.new(data['team']) if data['team']
136
+ @nullified = data['nullified']
137
+ end
138
+
139
+ def nullified?
140
+ @nullified.to_s == 'true'
141
+ end
142
+ end
143
+
144
+ class PlayPassingStatistics < Data
145
+ attr_accessor :attempt, :att_yards, :complete, :firstdown, :goaltogo, :inside_20, :interception, :sack, :sack_yards, :touchdown, :yards, :nullified, :team, :player
146
+ def initialize(data)
147
+ @attempt = data['attempt']
148
+ @att_yards = data['att_yards']
149
+ @complete = data['complete']
150
+ @firstdown = data['firstdown']
151
+ @goaltogo = data['goaltogo']
152
+ @inside_20 = data['inside_20']
153
+ @interception = data['interception']
154
+ @sack = data['sack']
155
+ @sack_yards = data['sack_yards']
156
+ @touchdown = data['touchdown']
157
+ @yards = data['yards']
158
+ @team = OpenStruct.new(data['team']) if data['team']
159
+ @player = OpenStruct.new(data['player']) if data['player']
160
+ @nullified = data['nullified']
161
+ end
162
+
163
+ def nullified?
164
+ @nullified.to_s == 'true'
165
+ end
166
+ end
167
+
168
+ class PlayPenaltyStatistics < Data
169
+ attr_accessor :penalty, :yards, :nullified, :team, :player
170
+ def initialize(data)
171
+ @penalty = data['penalty'] if data['penalty']
172
+ @yards = data['yards'] if data['yards']
173
+ @team = OpenStruct.new(data['team']) if data['team']
174
+ @player = OpenStruct.new(data['player']) if data['player']
175
+ @nullified = data['nullified']
176
+ end
177
+
178
+ def nullified?
179
+ @nullified.to_s == 'true'
180
+ end
181
+ end
182
+
183
+ class PlayPuntStatistics < Data
184
+ attr_accessor :attempt, :downed, :faircatch, :inside_20, :out_of_bounds, :touchback, :yards, :nullified, :team, :player
185
+ def initialize(data)
186
+ data = data.first if data.is_a?(Array)
187
+ @attempt = data['attempt']
188
+ @downed = data['downed']
189
+ @inside_20 = data['inside_20']
190
+ @out_of_bounds = data['out_of_bounds']
191
+ @touchback = data['touchback']
192
+ @yards = data['yards']
193
+ @team = OpenStruct.new(data['team']) if data['team']
194
+ @player = OpenStruct.new(data['player']) if data['player']
195
+ @nullified = data['nullified']
196
+ end
197
+
198
+ def nullified?
199
+ @nullified.to_s == 'true'
200
+ end
201
+ end
202
+
203
+ class PlayReceiveStatistics < Data
204
+ attr_accessor :firstdown, :goaltogo, :inside_20, :reception, :target, :touchdown, :yards, :yards_after_catch, :nullified, :team, :player
205
+ def initialize(data)
206
+ @firstdown = data['firstdown']
207
+ @goaltogo = data['goaltogo']
208
+ @inside_20 = data['inside_20']
209
+ @reception = data['reception']
210
+ @target = data['target']
211
+ @touchdown = data['touchdown']
212
+ @yards = data['yards']
213
+ @yards_after_catch = data['yards_after_catch']
214
+ @team = OpenStruct.new(data['team']) if data['team']
215
+ @player = OpenStruct.new(data['player']) if data['player']
216
+ @nullified = data['nullified']
217
+ end
218
+
219
+ def nullified?
220
+ @nullified.to_s == 'true'
221
+ end
222
+ end
223
+
224
+ class PlayFumbleStatistics < Data
225
+ attr_reader :own_rec, :own_rec_yards, :forced, :team, :player
226
+ def initialize(data)
227
+ @own_rec = data['own_rec']
228
+ @own_rec_yards = data['own_rec_yards']
229
+ @forced = data['forced']
230
+
231
+ @team = OpenStruct.new(data['team']) if data['team']
232
+ @player = OpenStruct.new(data['player']) if data['player']
233
+ end
234
+ end
235
+
236
+ class PlayRushStatistics < Data
237
+ attr_accessor :attempt, :firstdown, :tlost, :tlost_yards, :yards, :inside_20, :goal_to_go, :team, :player, :nullified, :touchdown
238
+ def initialize(data)
239
+ @attempt = data['attempt']
240
+ @firstdown = data['firstdown']
241
+ @goal_to_go = data['goal_to_go']
242
+ @inside_20 = data['inside_20']
243
+ @tlost = data['tlost']
244
+ @tlost_yards = data['tlost_yards']
245
+ @touchdown = data['touchdown']
246
+ @yards = data['yards']
247
+
248
+ @team = OpenStruct.new(data['team']) if data['team']
249
+ @player = OpenStruct.new(data['player']) if data['player']
250
+ @nullified = data['nullified']
251
+ end
252
+
253
+ def nullified?
254
+ @nullified.to_s == 'true'
255
+ end
256
+ end
257
+
258
+
259
+ class PlayKickStatistics < Data
260
+ attr_accessor :attempt, :yards, :gross_yards, :touchback, :team, :player, :endzone, :inside_20, :nullified
261
+ def initialize(data)
262
+ @endzone = data['endzone']
263
+ @inside_20 = data['inside_20']
264
+ @attempt = data['attempt']
265
+ @yards = data['yards']
266
+ @gross_yards = data['gross_yards']
267
+ @touchback = data['touchback']
268
+ @team = OpenStruct.new(data['team']) if data['team']
269
+ @player = OpenStruct.new(data['player']) if data['player']
270
+ @nullified = data['nullified']
271
+ end
272
+
273
+ def nullified?
274
+ @nullified.to_s == 'true'
275
+ end
276
+ end
277
+
278
+ class ConversionStatistics < Data
279
+ attr_reader :stat_type, :attempt, :complete, :category, :player, :team
280
+ def initialize(data)
281
+ @stat_type = data['stat_type']
282
+ @attempt = data['attempt']
283
+ @complete = data['complete']
284
+ @category = data['category']
285
+ @player = data['player']
286
+ @team = data['team']
287
+ end
288
+ end
289
+
290
+ class PlayReturnStatistics < Data
291
+ attr_accessor :category, :downed, :faircatch, :out_of_bounds, :return, :touchback, :yards, :team, :nullified, :player, :touchdown
292
+ def initialize(data)
293
+ @category = data['category']
294
+ @downed = data['downed']
295
+ @faircatch = data['faircatch']
296
+ @out_of_bounds = data['out_of_bounds']
297
+ @return = data['return']
298
+ @touchback = data['touchback']
299
+ @touchdown = data['touchdown']
300
+ @yards = data['yards']
301
+ @team = OpenStruct.new(data['team']) if data['team']
302
+ @player = OpenStruct.new(data['player']) if data['player']
303
+ @nullified = data['nullified']
304
+ end
305
+
306
+ def nullified?
307
+ @nullified.to_s == 'true'
308
+ end
309
+ end
310
+
311
+ end
312
+ end
313
+ end
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.11.16"
3
+ VERSION = "0.11.17"
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.16
4
+ version: 0.11.17
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-16 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -376,6 +376,7 @@ files:
376
376
  - lib/sportradar/api/football/nfl/team.rb
377
377
  - lib/sportradar/api/football/nfl/week.rb
378
378
  - lib/sportradar/api/football/play.rb
379
+ - lib/sportradar/api/football/play_statistics.rb
379
380
  - lib/sportradar/api/football/player.rb
380
381
  - lib/sportradar/api/football/quarter.rb
381
382
  - lib/sportradar/api/football/record.rb