sportradar 0.0.9 → 0.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c0abeead357c8e0c280dd654b0e89bc3e3d4b0a
4
- data.tar.gz: 25e340119ea4c0bc2e5f0d8acf40cdd8a1ed99c6
3
+ metadata.gz: ad27a4a77ec5c04a10b227338f99e7be5d0f806e
4
+ data.tar.gz: 878f668271b9d63a62c6c5ce6bc1e0a150d85446
5
5
  SHA512:
6
- metadata.gz: b15be914bc977ea7e03edb0c50b3518a9fdf1086144c7bfe13ad89f21a3cfa379094b8ef67fd5a7653f4f84e9a58e8ca8d800a1a578cec30eca2c4165015b02b
7
- data.tar.gz: 8dd02722d3433811bf3b77371ffacd178711e0c7b9a698e2cbe28ec1af8095b3da7965e602232518fd2d5093a4af583747853a4cdca79fd72d56342f1514ae5b
6
+ metadata.gz: 8f586e5cfe745e9e108f6bc9fc424e2ff8b8339155663145ce0f86fd66a5967451d3adda6758bbd0fb6396c65774daaf58e1c77b43430c2b16b55aef818afe30
7
+ data.tar.gz: f9c9723b2884974ebea27cafe4123d4cab0bc2b71dac2daad5ef64d15d68f142e30a9e4d7c7be713669f6e5ae67bae322cc90ccefff41f1e4a6dc70c6bf7bb92
data/README.md CHANGED
@@ -14,7 +14,7 @@ Currently supports
14
14
  Add this line to your application's Gemfile:
15
15
 
16
16
  ```ruby
17
- gem 'sportradar', '>= 0.0.9'
17
+ gem 'sportradar', '>= 0.0.11'
18
18
  ```
19
19
 
20
20
  And then execute:
@@ -137,6 +137,7 @@ Defaults to and supports NFL Classic API feed version 1 only (not Official).
137
137
  away_team_abbreviation: 'PIT',
138
138
  home_team_abbreviation: 'NE',
139
139
  play_id: '4788eac3-c59e-4f82-94ef-d449ac6d6fca').fetch`
140
+ * `Sportradar::Nfl::PlaySummary.new(details: '/2016/REG/1/NE/ARI/plays/4c578712-3589-416c-90aa-76064830fa7e.json').fetch`
140
141
  * `Sportradar::Nfl::Boxscore.new(week: 1,
141
142
  year: 2015,
142
143
  away_team_abbreviation: 'PIT',
@@ -724,7 +725,25 @@ Curveball = Ball
724
725
  Fastball = Foul Ball
725
726
  Fastball = Ball
726
727
  Curveball = Strike Swinging
728
+
727
729
  ```
730
+ #### Football Play by Play
731
+
732
+ * `Sportradar::Nfl::Parsers::PlayByPlayParser.new(game_play_by_play: {})`
733
+
734
+ Given game NFL Play by Play JSON, makes it easy to get the drives, quarters, and plays via a set of convenience methods.
735
+
736
+ * quarters - game, number, drives
737
+
738
+ * drives - game, quarter, clock, team, plays
739
+
740
+ * plays - game, drive, team, participants, summary, yardage, etc.
741
+
742
+ #### Play Summary Model
743
+
744
+ Given game NFL Play Summary JSON, makes it easy to get at the start and end situations, players, scroing info for each play summmary.
745
+
746
+ * `Sportradar::Nfl::Models::PlaySummary.new(attributes: {})`
728
747
 
729
748
  ## Development
730
749
 
@@ -0,0 +1,89 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+
5
+ # NOTE: This data structure isn't techincially a single drive as due to the way
6
+ # Sportradar structures the play by play data and how it will be parsed
7
+ # a drive could be separated into two sets of info and plays by a TV timeout or
8
+ # the end of the quarter. The data/drive will continue using the same drive id
9
+ # in subsequent action data.
10
+ #
11
+ # Therefore, it would be incorrect to count the number of plays in the drive
12
+ # to get the play count.
13
+ #
14
+ # In addition, the drive data can contain actions/plays for other teams, such as
15
+ # when one team kicks off, then a tvtimeout, then the offensive team has their first play.
16
+ #
17
+ # To get the offensive plays, you need to compare the drive's team with the play's side.
18
+
19
+ class Drive
20
+ def initialize(quarter:, attributes:)
21
+ @quarter = quarter
22
+ @attributes = attributes
23
+ end
24
+
25
+ def to_s
26
+ "#{quarter.to_s} #{clock}"
27
+ end
28
+
29
+ def game_id
30
+ quarter.game_id
31
+ end
32
+
33
+ def quarter
34
+ @quarter
35
+ end
36
+
37
+ def quarter_number
38
+ @quarter.number
39
+ end
40
+
41
+ def clock
42
+ @attributes['clock'] || '0'
43
+ end
44
+
45
+ def id
46
+ @attributes['id']
47
+ end
48
+
49
+ def team
50
+ @attributes['team']
51
+ end
52
+
53
+ def type
54
+ @attributes['type']
55
+ end
56
+
57
+ def actions
58
+ @actions ||= @attributes.dig('actions') || []
59
+ end
60
+
61
+ def plays
62
+ @plays || build_plays || []
63
+ end
64
+
65
+ def events
66
+ @events || build_events || []
67
+ end
68
+
69
+ private
70
+
71
+ def build_plays
72
+ actions.each_with_object([]) do |action, _plays|
73
+ if action['type'] == 'play'
74
+ _plays << Models::Play.new(drive: self, attributes: action)
75
+ end
76
+ end
77
+ end
78
+
79
+ def build_events
80
+ actions.each_with_object([]) do |action, _events|
81
+ if action['type'] != 'play'
82
+ _events << Models::Event.new(drive: self, attributes: action)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,56 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+ class Event
5
+ def initialize(drive:, attributes:)
6
+ @drive = drive
7
+ @attributes = attributes
8
+ end
9
+
10
+ def to_s
11
+ event_type
12
+ end
13
+
14
+ def team
15
+ @drive.team
16
+ end
17
+
18
+ def drive_id
19
+ @drive.id
20
+ end
21
+
22
+ def quarter
23
+ @drive.quarter
24
+ end
25
+
26
+ def quarter_number
27
+ quarter.number
28
+ end
29
+
30
+ def clock
31
+ @attributes['clock'] || '0'
32
+ end
33
+
34
+ def id
35
+ @attributes['id']
36
+ end
37
+
38
+ def sequence
39
+ @attributes['sequence'] || 0
40
+ end
41
+
42
+ def event_type
43
+ @attributes['event_type']
44
+ end
45
+
46
+ def type
47
+ @attributes['type']
48
+ end
49
+
50
+ def updated_at
51
+ @attributes['updated']
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,108 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+ class Play
5
+ def initialize(drive:, attributes:)
6
+ @drive = drive
7
+ @attributes = attributes
8
+ end
9
+
10
+ def to_s
11
+ summary
12
+ end
13
+
14
+ def game_id
15
+ @drive.game_id
16
+ end
17
+
18
+ def team
19
+ @drive.team
20
+ end
21
+
22
+ def drive_id
23
+ @drive.id
24
+ end
25
+
26
+ def quarter
27
+ @drive.quarter
28
+ end
29
+
30
+ def quarter_number
31
+ quarter.number
32
+ end
33
+
34
+ def clock
35
+ @attributes['clock']
36
+ end
37
+
38
+ def id
39
+ @attributes['id']
40
+ end
41
+
42
+ def details
43
+ @attributes['details']
44
+ end
45
+
46
+ def down
47
+ @attributes['down']
48
+ end
49
+
50
+ def participants
51
+ @attributes['participants']
52
+ end
53
+
54
+ def play_type
55
+ @attributes['play_type']
56
+ end
57
+
58
+ def sequence
59
+ @attributes['sequence']
60
+ end
61
+
62
+ def side
63
+ @attributes['side']
64
+ end
65
+
66
+ def summary
67
+ @attributes['summary']
68
+ end
69
+
70
+ def type
71
+ @attributes['type']
72
+ end
73
+
74
+ def updated_at
75
+ @attributes['updated']
76
+ end
77
+
78
+ def yard_line
79
+ @attributes['yard_line']
80
+ end
81
+
82
+ def yards_to_first_down
83
+ @attributes['yfd']
84
+ end
85
+
86
+ def direction
87
+ @attributes['direction']
88
+ end
89
+
90
+ def distance
91
+ @attributes['distance']
92
+ end
93
+
94
+ def formation
95
+ @attributes['formation']
96
+ end
97
+
98
+ def official?
99
+ @attributes['official']
100
+ end
101
+
102
+ def sequence
103
+ @attributes['sequence']
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,60 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+ class PlayAdvancement
5
+ def initialize(play:, attributes:)
6
+ @play = play
7
+ @attributes = attributes
8
+ end
9
+
10
+ def to_s
11
+ [
12
+ type,
13
+ from_side_team,
14
+ from_yard_line,
15
+ to_side_team,
16
+ to_yard_line,
17
+ yards
18
+ ].compact.
19
+ join(' ')
20
+ end
21
+
22
+ def id
23
+ @play.id
24
+ end
25
+
26
+ def sequence
27
+ @attributes['sequence']
28
+ end
29
+
30
+ def type
31
+ @attributes['type']
32
+ end
33
+
34
+ def team
35
+ @attributes['team']
36
+ end
37
+
38
+ def yards
39
+ @attributes['yards']
40
+ end
41
+
42
+ def from_side_team
43
+ @attributes.dig('from', 'side')
44
+ end
45
+
46
+ def from_yard_line
47
+ @attributes.dig('from', 'yard_line')
48
+ end
49
+
50
+ def to_side_team
51
+ @attributes.dig('to', 'side')
52
+ end
53
+
54
+ def to_yard_line
55
+ @attributes.dig('to', 'yard_line')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,531 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+ class PlayPlayerStat
5
+ def initialize(play:, attributes:)
6
+ @play = play
7
+ @attributes = attributes
8
+ end
9
+
10
+ def to_s
11
+ [
12
+ team,
13
+ name,
14
+ position,
15
+ stats,
16
+ ].join(' ')
17
+ end
18
+
19
+ def play_id
20
+ @play.id
21
+ end
22
+
23
+ def player_id
24
+ @attributes.dig('id')
25
+ end
26
+
27
+ def jersey
28
+ @attributes.dig('jersey')
29
+ end
30
+
31
+ def name
32
+ @attributes.dig('name')
33
+ end
34
+
35
+ def position
36
+ @attributes.dig('position')
37
+ end
38
+
39
+ def team
40
+ @attributes.dig('team')
41
+ end
42
+
43
+ def stats
44
+ {
45
+ 'blocked_field_goal_return_returns' => blocked_field_goal_return_returns,
46
+ 'blocked_field_goal_return_touchdown' => blocked_field_goal_return_touchdown,
47
+ 'blocked_field_goal_return_yards' => blocked_field_goal_return_yards,
48
+ 'blocked_punt_return_returns' => blocked_punt_return_returns,
49
+ 'blocked_punt_return_touchdown' => blocked_punt_return_touchdown,
50
+ 'blocked_punt_return_yards' => blocked_punt_return_yards,
51
+ 'defense_assist' => defense_assist,
52
+ 'defense_category' => defense_category,
53
+ 'defense_forced_fumble' => defense_forced_fumble,
54
+ 'defense_interception' => defense_interception,
55
+ 'defense_interception_touchdown' => defense_interception_touchdown,
56
+ 'defense_interception_yards' => defense_interception_yards,
57
+ 'defense_sack' => defense_sack,
58
+ 'defense_sack_yards' => defense_sack_yards,
59
+ 'defense_safety' => defense_safety,
60
+ 'defense_tackle' => defense_tackle,
61
+ 'defense_tackle_lost' => defense_tackle_lost,
62
+ 'extra_point_attempt' => extra_point_attempt,
63
+ 'extra_point_blocked' => extra_point_blocked,
64
+ 'extra_point_made' => extra_point_made,
65
+ 'field_goal_attempt' => field_goal_attempt,
66
+ 'field_goal_attempt_yards' => field_goal_attempt_yards,
67
+ 'field_goal_blocked' => field_goal_blocked,
68
+ 'field_goal_made' => field_goal_made,
69
+ 'field_goal_return' => field_goal_return,
70
+ 'field_goal_return_returns' => field_goal_return_returns,
71
+ 'field_goal_return_touchdown' => field_goal_return_touchdown,
72
+ 'field_goal_return_yards' => field_goal_return_yards,
73
+ 'field_goal_yards' => field_goal_yards,
74
+ 'fumble_category' => fumble_category,
75
+ 'fumble_fumble' => fumble_fumble,
76
+ 'fumble_lost' => fumble_lost,
77
+ 'fumble_out_of_bounds' => fumble_out_of_bounds,
78
+ 'fumble_return_category' => fumble_return_category,
79
+ 'fumble_return_opp_recovered' => fumble_return_opp_recovered,
80
+ 'fumble_return_own_recovered' => fumble_return_own_recovered,
81
+ 'fumble_return_returned' => fumble_return_returned,
82
+ 'fumble_return_touchdown' => fumble_return_touchdown,
83
+ 'fumble_return_yards' => fumble_return_yards,
84
+ 'kick_return_fair_catch' => kick_return_fair_catch,
85
+ 'kick_return_returns' => kick_return_returns,
86
+ 'kick_return_touchdown' => kick_return_touchdown,
87
+ 'kick_return_yards' => kick_return_yards,
88
+ 'kickoffs_endzone' => kickoffs_endzone,
89
+ 'kickoffs_inside_20' => kickoffs_inside_20,
90
+ 'kickoffs_kicks' => kickoffs_kicks,
91
+ 'kickoffs_net_yards' => kickoffs_net_yards,
92
+ 'kickoffs_returned' => kickoffs_returned,
93
+ 'kickoffs_touchback' => kickoffs_touchback,
94
+ 'kickoffs_yards' => kickoffs_yards,
95
+ 'passing_attempt' => passing_attempt,
96
+ 'passing_completion' => passing_completion,
97
+ 'passing_first_down' => passing_first_down,
98
+ 'passing_interception' => passing_interception,
99
+ 'passing_red_zone_attempt' => passing_red_zone_attempt,
100
+ 'passing_sacked' => passing_sacked,
101
+ 'passing_sacked_for_yards' => passing_sacked_for_yards,
102
+ 'passing_safety' => passing_safety,
103
+ 'passing_touchdown' => passing_touchdown,
104
+ 'passing_yards' => passing_yards,
105
+ 'penalty_abbreviation' => penalty_abbreviation,
106
+ 'penalty_first_down' => penalty_first_down,
107
+ 'penalty_yards' => penalty_yards,
108
+ 'punt_return_fair_catch' => punt_return_fair_catch,
109
+ 'punt_return_returned' => punt_return_returns,
110
+ 'punt_return_touchdown' => punt_return_touchdown,
111
+ 'punt_return_yards' => punt_return_yards,
112
+ 'punting_blocked' => punting_blocked,
113
+ 'punting_inside_20' => punting_inside_20,
114
+ 'punting_net_yards' => punting_net_yards,
115
+ 'punting_punts' => punting_punts,
116
+ 'punting_returned' => punting_returned,
117
+ 'punting_safety' => punting_safety,
118
+ 'punting_touchback' => punting_touchback,
119
+ 'punting_yards' => punting_yards,
120
+ 'receiving_first_down' => receiving_first_down,
121
+ 'receiving_fumble' => receiving_fumble,
122
+ 'receiving_reception' => receiving_reception,
123
+ 'receiving_red_zone_target' => receiving_red_zone_target,
124
+ 'receiving_target' => receiving_target,
125
+ 'receiving_touchdown' => receiving_touchdown,
126
+ 'receiving_yards' => receiving_yards,
127
+ 'receiving_yards_after_catch' => receiving_yards_after_catch,
128
+ 'rushing_first_down' => rushing_first_down,
129
+ 'rushing_fumble' => rushing_fumble,
130
+ 'rushing_red_zone_attempt' => rushing_red_zone_attempt,
131
+ 'rushing_rush' => rushing_rush,
132
+ 'rushing_safety' => rushing_safety,
133
+ 'rushing_touchdown' => rushing_touchdown,
134
+ 'rushing_yards' => rushing_yards,
135
+ 'two_point_conversion_attempt' => two_point_conversion_attempt,
136
+ 'two_point_conversion_failed' => two_point_conversion_failed,
137
+ 'two_point_conversion_made' => two_point_conversion_made,
138
+ 'two_point_conversion_pass' => two_point_conversion_pass,
139
+ 'two_point_conversion_rececption' => two_point_conversion_rececption,
140
+ 'two_point_conversion_rush' => two_point_conversion_rush,
141
+
142
+ }.compact
143
+ end
144
+
145
+ def defense_assist
146
+ @attributes.dig('defense', 'ast')
147
+ end
148
+
149
+ def defense_category
150
+ @attributes.dig('defense', 'category')
151
+ end
152
+
153
+ def defense_forced_fumble
154
+ @attributes.dig('defense', 'fum')
155
+ end
156
+
157
+ def defense_interception
158
+ @attributes.dig('defense', 'int')
159
+ end
160
+
161
+ def defense_interception_touchdown
162
+ @attributes.dig('defense', 'int_td')
163
+ end
164
+
165
+ def defense_interception_yards
166
+ @attributes.dig('defense', 'int_yds')
167
+ end
168
+
169
+ def defense_sack
170
+ @attributes.dig('defense', 'sack')
171
+ end
172
+
173
+ def defense_sack_yards
174
+ @attributes.dig('defense', 'yds')
175
+ end
176
+
177
+ def defense_safety
178
+ @attributes.dig('defense', 'sfty')
179
+ end
180
+
181
+ def defense_tackle
182
+ @attributes.dig('defense', 'tackle')
183
+ end
184
+
185
+ def defense_tackle_lost
186
+ @attributes.dig('defense', 'tlost')
187
+ end
188
+
189
+ def rushing_rush
190
+ @attributes.dig('rushing', 'att')
191
+ end
192
+
193
+ def rushing_first_down
194
+ @attributes.dig('rushing', 'fd')
195
+ end
196
+
197
+ def rushing_fumble
198
+ @attributes.dig('rushing', 'fum')
199
+ end
200
+
201
+ def rushing_red_zone_attempt
202
+ @attributes.dig('rushing', 'rz_att')
203
+ end
204
+
205
+ def rushing_safety
206
+ @attributes.dig('rushing', 'sfty')
207
+ end
208
+
209
+ def rushing_touchdown
210
+ @attributes.dig('rushing', 'td')
211
+ end
212
+
213
+ def rushing_yards
214
+ @attributes.dig('rushing', 'yds')
215
+ end
216
+
217
+ def field_goal_attempt
218
+ @attributes.dig('field_goal', 'att')
219
+ end
220
+
221
+ def field_goal_attempt_yards
222
+ @attributes.dig('field_goal', 'att_yds')
223
+ end
224
+
225
+ def field_goal_blocked
226
+ @attributes.dig('field_goal', 'blk')
227
+ end
228
+
229
+ def field_goal_made
230
+ @attributes.dig('field_goal', 'made')
231
+ end
232
+
233
+ def field_goal_return
234
+ @attributes.dig('field_goal', 'ret')
235
+ end
236
+
237
+ def field_goal_yards
238
+ @attributes.dig('field_goal', 'yds')
239
+ end
240
+
241
+ def passing_attempt
242
+ @attributes.dig('passing', 'att')
243
+ end
244
+
245
+ def passing_completion
246
+ @attributes.dig('passing', 'cmp')
247
+ end
248
+
249
+ def passing_first_down
250
+ @attributes.dig('passing', 'fd')
251
+ end
252
+
253
+ def passing_interception
254
+ @attributes.dig('passing', 'int')
255
+ end
256
+
257
+ def passing_red_zone_attempt
258
+ @attributes.dig('passing', 'rz_att')
259
+ end
260
+
261
+ def passing_safety
262
+ @attributes.dig('passing', 'sfty')
263
+ end
264
+
265
+ def passing_sacked
266
+ @attributes.dig('passing', 'sk')
267
+ end
268
+
269
+ def passing_sacked_for_yards
270
+ @attributes.dig('passing', 'sk_yds')
271
+ end
272
+
273
+ def passing_touchdown
274
+ @attributes.dig('passing', 'td')
275
+ end
276
+
277
+ def passing_yards
278
+ @attributes.dig('passing', 'yds')
279
+ end
280
+
281
+ def penalty_abbreviation
282
+ @attributes.dig('penalty', 'abbr')
283
+ end
284
+
285
+ def penalty_first_down
286
+ @attributes.dig('penalty', 'fd')
287
+ end
288
+
289
+ def penalty_yards
290
+ @attributes.dig('penalty', 'yds')
291
+ end
292
+
293
+ def receiving_first_down
294
+ @attributes.dig('receiving', 'fd')
295
+ end
296
+
297
+ def receiving_fumble
298
+ @attributes.dig('receiving', 'fum')
299
+ end
300
+
301
+ def receiving_reception
302
+ @attributes.dig('receiving', 'rec')
303
+ end
304
+
305
+ def receiving_red_zone_target
306
+ @attributes.dig('receiving', 'rz_tar')
307
+ end
308
+
309
+ def receiving_target
310
+ @attributes.dig('receiving', 'tar')
311
+ end
312
+
313
+ def receiving_touchdown
314
+ @attributes.dig('receiving', 'td')
315
+ end
316
+
317
+ def receiving_yards_after_catch
318
+ @attributes.dig('receiving', 'yac')
319
+ end
320
+
321
+ def receiving_yards
322
+ @attributes.dig('receiving', 'yds')
323
+ end
324
+
325
+ def extra_point_attempt
326
+ @attributes.dig('extra_point', 'att')
327
+ end
328
+
329
+ def extra_point_blocked
330
+ @attributes.dig('extra_point', 'blk')
331
+ end
332
+
333
+ def extra_point_made
334
+ @attributes.dig('extra_point', 'made')
335
+ end
336
+
337
+ def kickoffs_endzone
338
+ @attributes.dig('kickoffs', 'endzone')
339
+ end
340
+
341
+ def kickoffs_inside_20
342
+ @attributes.dig('kickoffs', 'in20')
343
+ end
344
+
345
+ def kickoffs_kicks
346
+ @attributes.dig('kickoffs', 'kicks')
347
+ end
348
+
349
+ def kickoffs_net_yards
350
+ @attributes.dig('kickoffs', 'net_yds')
351
+ end
352
+
353
+ def kickoffs_returned
354
+ @attributes.dig('kickoffs', 'ret')
355
+ end
356
+
357
+ def kickoffs_touchback
358
+ @attributes.dig('kickoffs', 'tb')
359
+ end
360
+
361
+ def kickoffs_yards
362
+ @attributes.dig('kickoffs', 'yds')
363
+ end
364
+
365
+ def punting_blocked
366
+ @attributes.dig('punting', 'blk')
367
+ end
368
+
369
+ def punting_inside_20
370
+ @attributes.dig('punting', 'in20')
371
+ end
372
+
373
+ def punting_net_yards
374
+ @attributes.dig('punting', 'net_yds')
375
+ end
376
+
377
+ def punting_punts
378
+ @attributes.dig('punting', 'punts')
379
+ end
380
+
381
+ def punting_returned
382
+ @attributes.dig('punting', 'ret')
383
+ end
384
+
385
+ def punting_safety
386
+ @attributes.dig('punting', 'sfty')
387
+ end
388
+
389
+ def punting_touchback
390
+ @attributes.dig('punting', 'tb')
391
+ end
392
+
393
+ def punting_yards
394
+ @attributes.dig('punting', 'yds')
395
+ end
396
+
397
+ def punt_return_fair_catch
398
+ @attributes.dig('punt_return', 'fc')
399
+ end
400
+
401
+ def punt_return_returns
402
+ @attributes.dig('punt_return', 'returns')
403
+ end
404
+
405
+ def punt_return_touchdown
406
+ @attributes.dig('punt_return', 'td')
407
+ end
408
+
409
+ def punt_return_yards
410
+ @attributes.dig('punt_return', 'yds')
411
+ end
412
+
413
+ def fumble_category
414
+ @attributes.dig('fumble', 'category')
415
+ end
416
+
417
+ def fumble_fumble
418
+ @attributes.dig('fumble', 'fum')
419
+ end
420
+
421
+ def fumble_lost
422
+ @attributes.dig('fumble', 'lost')
423
+ end
424
+
425
+ def fumble_out_of_bounds
426
+ @attributes.dig('fumble', 'oob')
427
+ end
428
+
429
+ def fumble_return_category
430
+ @attributes.dig('fumble_return', 'category')
431
+ end
432
+
433
+ def fumble_return_opp_recovered
434
+ @attributes.dig('fumble_return', 'opp_rec')
435
+ end
436
+
437
+ def fumble_return_own_recovered
438
+ @attributes.dig('fumble_return', 'own_rec')
439
+ end
440
+
441
+ def fumble_return_returned
442
+ @attributes.dig('fumble_return', 'returns')
443
+ end
444
+
445
+ def fumble_return_touchdown
446
+ @attributes.dig('fumble_return', 'td')
447
+ end
448
+
449
+ def fumble_return_yards
450
+ @attributes.dig('fumble_return', 'yds')
451
+ end
452
+
453
+ def two_point_conversion_attempt
454
+ @attributes.dig('two_point_conversion', 'att')
455
+ end
456
+
457
+ def two_point_conversion_failed
458
+ @attributes.dig('two_point_conversion', 'failed')
459
+ end
460
+
461
+ def two_point_conversion_made
462
+ @attributes.dig('two_point_conversion', 'made')
463
+ end
464
+
465
+ def two_point_conversion_pass
466
+ @attributes.dig('two_point_conversion', 'pass')
467
+ end
468
+
469
+ def two_point_conversion_rececption
470
+ @attributes.dig('two_point_conversion', 'rec')
471
+ end
472
+
473
+ def two_point_conversion_rush
474
+ @attributes.dig('two_point_conversion', 'rush')
475
+ end
476
+
477
+ def blocked_field_goal_return_returns
478
+ @attributes.dig('blocked_field_goal_return', 'returns')
479
+ end
480
+
481
+ def blocked_field_goal_return_yards
482
+ @attributes.dig('blocked_field_goal_return', 'yds')
483
+ end
484
+
485
+ def blocked_field_goal_return_touchdown
486
+ @attributes.dig('blocked_field_goal_return', 'td')
487
+ end
488
+
489
+ def blocked_punt_return_returns
490
+ @attributes.dig('blocked_punt_return', 'returns')
491
+ end
492
+
493
+ def blocked_punt_return_yards
494
+ @attributes.dig('blocked_punt_return', 'yds')
495
+ end
496
+
497
+ def blocked_punt_return_touchdown
498
+ @attributes.dig('blocked_punt_return', 'td')
499
+ end
500
+
501
+ def field_goal_return_returns
502
+ @attributes.dig('field_goal_return', 'returns')
503
+ end
504
+
505
+ def field_goal_return_yards
506
+ @attributes.dig('field_goal_return', 'yds')
507
+ end
508
+
509
+ def field_goal_return_touchdown
510
+ @attributes.dig('field_goal_return', 'td')
511
+ end
512
+
513
+ def kick_return_returns
514
+ @attributes.dig('kick_return', 'returns')
515
+ end
516
+
517
+ def kick_return_yards
518
+ @attributes.dig('kick_return', 'yds')
519
+ end
520
+
521
+ def kick_return_fair_catch
522
+ @attributes.dig('kick_return', 'fc')
523
+ end
524
+
525
+ def kick_return_touchdown
526
+ @attributes.dig('kick_return', 'td')
527
+ end
528
+ end
529
+ end
530
+ end
531
+ end
@@ -0,0 +1,115 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+ class PlaySummary < Play
5
+ def initialize(attributes:)
6
+ @attributes = attributes
7
+ end
8
+
9
+ def to_s
10
+ summary
11
+ end
12
+
13
+ def game_id
14
+ @attributes['game']
15
+ end
16
+
17
+ def team
18
+ controller
19
+ end
20
+
21
+ def quarter_number
22
+ @attributes['quarter']
23
+ end
24
+
25
+ def controller
26
+ @attributes['controller']
27
+ end
28
+
29
+ def players
30
+ @attributes['players']
31
+ end
32
+
33
+ def end_situation_down
34
+ @attributes.dig('end_situation', 'down')
35
+ end
36
+
37
+ def end_situation_side
38
+ @attributes.dig('end_situation', 'side')
39
+ end
40
+
41
+ def end_situation_team
42
+ @attributes.dig('end_situation', 'team')
43
+ end
44
+
45
+ def end_situation_yard_line
46
+ @attributes.dig('end_situation', 'yard_line')
47
+ end
48
+
49
+ def end_situation_yards_to_first_down
50
+ @attributes.dig('end_situation', 'yfd')
51
+ end
52
+
53
+ def start_situation_down
54
+ @attributes.dig('start_situation', 'down')
55
+ end
56
+
57
+ def start_situation_side
58
+ @attributes.dig('start_situation', 'side')
59
+ end
60
+
61
+ def start_situation_team
62
+ @attributes.dig('start_situation', 'team')
63
+ end
64
+
65
+ def start_situation_yard_line
66
+ @attributes.dig('start_situation', 'yard_line')
67
+ end
68
+
69
+ def start_situation_yards_to_first_down
70
+ @attributes.dig('start_situation', 'yfd')
71
+ end
72
+
73
+ def scoring_team
74
+ @attributes.dig('score', 'team')
75
+ end
76
+
77
+ def score_type
78
+ @attributes.dig('score', 'type')
79
+ end
80
+
81
+ def points_scored
82
+ @attributes.dig('score', 'points')
83
+ end
84
+
85
+ def advancements
86
+ @advancements ||= (@attributes['advancements'] || []).
87
+ each_with_object([]) do |attributes, _advancements|
88
+ _advancements << PlayAdvancement.new(play: self, attributes: attributes)
89
+ end
90
+ end
91
+
92
+ def has_advancements?
93
+ advancements.count > 0
94
+ end
95
+
96
+ def player_stats
97
+ @player_stats ||= (@attributes['players'] || []).
98
+ each_with_object([]) do |attributes, _player_stats|
99
+ _player_stats << PlayPlayerStat.new(play: self, attributes: attributes)
100
+ end
101
+ end
102
+
103
+ def has_player_stats?
104
+ player_stats.count > 0
105
+ end
106
+
107
+ def is_current_drive_team?
108
+ if controller && team
109
+ controller == team
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,46 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Models
4
+ class Quarter
5
+ def initialize(game_id:, attributes:)
6
+ @game_id = game_id
7
+ @attributes = attributes
8
+ end
9
+
10
+ def to_s
11
+ "Quarter #{number}"
12
+ end
13
+
14
+ def abbreviation
15
+ "Q#{number}"
16
+ end
17
+
18
+ def game_id
19
+ @game_id
20
+ end
21
+
22
+ def number
23
+ @attributes['number'] || 0
24
+ end
25
+
26
+ def pbp
27
+ @attributes['pbp']
28
+ end
29
+
30
+ def drives
31
+ @drives ||= build_drives
32
+ end
33
+
34
+ private
35
+
36
+ def build_drives
37
+ pbp.each_with_object([]) do |event, _drives|
38
+ if event['type'] == 'drive'
39
+ _drives << Models::Drive.new(quarter: self, attributes: event)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,57 @@
1
+ module Sportradar
2
+ module Nfl
3
+ module Parsers
4
+ class PlayByPlayParser
5
+ def initialize(game_play_by_play: {})
6
+ @game_play_by_play = game_play_by_play['game'] || game_play_by_play
7
+ end
8
+
9
+ def game_id
10
+ game_play_by_play['id']
11
+ end
12
+
13
+ def away
14
+ game_play_by_play['away_team'] || {}
15
+ end
16
+
17
+ def away_team_id
18
+ away['id']
19
+ end
20
+
21
+ def home
22
+ game_play_by_play['home_team'] || {}
23
+ end
24
+
25
+ def quarters
26
+ @quarters ||= build_quarters || []
27
+ end
28
+
29
+ def has_quarters?
30
+ quarters.count > 0
31
+ end
32
+
33
+ def drives
34
+ (quarters || []).map(&:drives).flatten
35
+ end
36
+
37
+ def plays
38
+ (drives || []).map(&:plays)
39
+ end
40
+
41
+ def events
42
+ (drives || []).map(&:events)
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :game_play_by_play
48
+
49
+ def build_quarters
50
+ game_play_by_play.
51
+ dig('quarters').
52
+ map { |attributes| Models::Quarter.new(game_id: game_id, attributes: attributes) }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,42 @@
1
+ module Sportradar
2
+ module Nfl
3
+ class PlaySummaries < Sportradar::Nfl::PlayByPlay
4
+ def self.perform(year: nil,
5
+ interval_type: nil,
6
+ week: 1,
7
+ away_team_abbreviation:,
8
+ home_team_abbreviation:)
9
+ new(year: year,
10
+ interval_type: interval_type,
11
+ week: week,
12
+ away_team_abbreviation: away_team_abbreviation,
13
+ home_team_abbreviation: home_team_abbreviation).perform
14
+ end
15
+
16
+ def perform
17
+ (quarters || []).each do |quarter|
18
+ (quarter['pbp'] || []).each do |pbp|
19
+ (pbp['actions'] || []).each do |action|
20
+ next unless action['type'] == 'play'
21
+
22
+ PlaySummary.new(week: @week,
23
+ year: @year,
24
+ interval_type: @interval_type,
25
+ away_team_abbreviation: @away_team_abbreviation,
26
+ home_team_abbreviation: @home_team_abbreviation,
27
+ play_id: action['id']).save
28
+ end
29
+ end
30
+ end
31
+
32
+ nil
33
+ end
34
+
35
+ private
36
+
37
+ def quarters
38
+ fetch['quarters'] || []
39
+ end
40
+ end
41
+ end
42
+ end
@@ -4,24 +4,32 @@ module Sportradar
4
4
  def initialize(year: nil,
5
5
  interval_type: nil,
6
6
  week: 1,
7
- away_team_abbreviation:,
8
- home_team_abbreviation:,
9
- play_id:)
7
+ away_team_abbreviation: nil,
8
+ home_team_abbreviation: nil,
9
+ play_id: nil,
10
+ details: nil)
10
11
  super(year: year,
11
12
  interval_type: interval_type,
12
13
  week: week,
13
14
  away_team_abbreviation: away_team_abbreviation,
14
15
  home_team_abbreviation: home_team_abbreviation)
15
16
  @play_id = play_id
17
+ @details = details
18
+
19
+ raise ArgumentError.new('A play_id or details path is required.') unless play_id || details
16
20
  end
17
21
 
18
22
  def path
19
- "#{game_path}/plays/#{play_id}.json"
23
+ if details
24
+ details
25
+ else
26
+ "#{game_path}/plays/#{play_id}.json"
27
+ end
20
28
  end
21
29
 
22
30
  private
23
31
 
24
- attr_reader :play_id
32
+ attr_reader :play_id, :details
25
33
  end
26
34
  end
27
35
  end
@@ -1,3 +1,3 @@
1
1
  module Sportradar
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.11'
3
3
  end
data/lib/sportradar.rb CHANGED
@@ -56,7 +56,16 @@ require 'sportradar/nba/league_hierarchy'
56
56
  require 'sportradar/nba/league_schedule'
57
57
  require 'sportradar/nba/play_by_play'
58
58
 
59
+ require 'sportradar/nfl/models/quarter'
60
+ require 'sportradar/nfl/models/drive'
61
+ require 'sportradar/nfl/models/event'
62
+ require 'sportradar/nfl/models/play'
63
+ require 'sportradar/nfl/models/play_player_stat'
64
+ require 'sportradar/nfl/models/play_advancement'
65
+ require 'sportradar/nfl/models/play_summary'
66
+
59
67
  require 'sportradar/nfl/parsers/boxscore_parser'
68
+ require 'sportradar/nfl/parsers/play_by_play_parser'
60
69
 
61
70
  require 'sportradar/nfl/league_hierarchy'
62
71
  require 'sportradar/nfl/league_schedule'
@@ -73,6 +82,7 @@ require 'sportradar/nfl/game_statistics'
73
82
  require 'sportradar/nfl/game_summary'
74
83
  require 'sportradar/nfl/play_by_play'
75
84
  require 'sportradar/nfl/play_summary'
85
+ require 'sportradar/nfl/play_summaries'
76
86
  require 'sportradar/nfl/boxscore'
77
87
  require 'sportradar/nfl/extended_boxscore'
78
88
  require 'sportradar/nfl/weekly_boxscore'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportradar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stattleship
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-09-04 00:00:00.000000000 Z
12
+ date: 2016-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -213,8 +213,17 @@ files:
213
213
  - lib/sportradar/nfl/game_summary.rb
214
214
  - lib/sportradar/nfl/league_hierarchy.rb
215
215
  - lib/sportradar/nfl/league_schedule.rb
216
+ - lib/sportradar/nfl/models/drive.rb
217
+ - lib/sportradar/nfl/models/event.rb
218
+ - lib/sportradar/nfl/models/play.rb
219
+ - lib/sportradar/nfl/models/play_advancement.rb
220
+ - lib/sportradar/nfl/models/play_player_stat.rb
221
+ - lib/sportradar/nfl/models/play_summary.rb
222
+ - lib/sportradar/nfl/models/quarter.rb
216
223
  - lib/sportradar/nfl/parsers/boxscore_parser.rb
224
+ - lib/sportradar/nfl/parsers/play_by_play_parser.rb
217
225
  - lib/sportradar/nfl/play_by_play.rb
226
+ - lib/sportradar/nfl/play_summaries.rb
218
227
  - lib/sportradar/nfl/play_summary.rb
219
228
  - lib/sportradar/nfl/rankings.rb
220
229
  - lib/sportradar/nfl/season_statistics.rb