sportradar 0.0.2 → 0.0.3
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/README.md +2 -2
- data/lib/sportradar.rb +5 -1
- data/lib/sportradar/mlb/models/at_bat.rb +78 -0
- data/lib/sportradar/mlb/models/pitch.rb +183 -0
- data/lib/sportradar/mlb/models/pitch_outcome.rb +12 -4
- data/lib/sportradar/mlb/models/pitch_type.rb +92 -0
- data/lib/sportradar/mlb/parsers/play_by_play_parser.rb +60 -0
- data/lib/sportradar/mlb/parsers/scoring_plays_parser.rb +127 -0
- data/lib/sportradar/version.rb +1 -1
- metadata +7 -3
- data/lib/sportradar/mlb/scoring_plays.rb +0 -125
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6fd07a092b78fc00238d29f30a170a0555eea953
|
|
4
|
+
data.tar.gz: d653d2e7c3eb380a78209f836ad94ce5ad7c01e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b8877a1d311f3ab4c318f6607783ddef5e0d16551fefe41a9d721ee68ded55237b3f7d44f5223ddedc573eaf52f1ae383631283fa7f33fabfc659526d310803
|
|
7
|
+
data.tar.gz: a152c4ea1039c926d1518c79f7b9c73fd0ebf0acc50bc87c2efee9af0499f59620ecc0a146b5194795bcf1952c3e318281f12d33f4fde0cd60e8f8898f5b5719
|
data/README.md
CHANGED
|
@@ -98,14 +98,14 @@ Some helpers will call `.save` for each response as separate items.
|
|
|
98
98
|
|
|
99
99
|
#### Boxscore and Scoring Plays
|
|
100
100
|
|
|
101
|
-
* `Sportradar::Mlb::ScoringPlays.new(game_boxscore: {})`
|
|
101
|
+
* `Sportradar::Mlb::Parsers::ScoringPlays.new(game_boxscore: {})`
|
|
102
102
|
|
|
103
103
|
Given game boxscore JSON, makes it easy to get the events and runners as scoring plays and players via a set of convenience methods.
|
|
104
104
|
|
|
105
105
|
For example:
|
|
106
106
|
|
|
107
107
|
```
|
|
108
|
-
sp = Sportradar::Mlb::ScoringPlays.new(game_boxscore: g.game_boxscore)
|
|
108
|
+
sp = Sportradar::Mlb::Parsers::ScoringPlays.new(game_boxscore: g.game_boxscore)
|
|
109
109
|
|
|
110
110
|
sp.first.scoring_players
|
|
111
111
|
=> [{:player_id=>"66c43b7f-760a-446c-9f50-671915570227", :player_info=>nil, :role=>"pitcher"},
|
data/lib/sportradar.rb
CHANGED
|
@@ -15,11 +15,15 @@ require 'sportradar/client/daily_api_request'
|
|
|
15
15
|
require 'sportradar/client/client'
|
|
16
16
|
require 'sportradar/client/configuration'
|
|
17
17
|
|
|
18
|
+
require 'sportradar/mlb/models/at_bat'
|
|
19
|
+
require 'sportradar/mlb/models/pitch'
|
|
18
20
|
require 'sportradar/mlb/models/pitch_outcome'
|
|
21
|
+
require 'sportradar/mlb/models/pitch_type'
|
|
19
22
|
require 'sportradar/mlb/models/runner'
|
|
20
23
|
require 'sportradar/mlb/models/scoring_play'
|
|
21
24
|
|
|
22
|
-
require 'sportradar/mlb/
|
|
25
|
+
require 'sportradar/mlb/parsers/play_by_play_parser'
|
|
26
|
+
require 'sportradar/mlb/parsers/scoring_plays_parser'
|
|
23
27
|
|
|
24
28
|
require 'sportradar/mlb/boxscore'
|
|
25
29
|
require 'sportradar/mlb/daily_boxscore'
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Models
|
|
4
|
+
class AtBat
|
|
5
|
+
def initialize(attributes: {})
|
|
6
|
+
@attributes = attributes
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
"#{half} of #{inning}: #{description}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def description
|
|
14
|
+
attributes['description'] || ''
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def events
|
|
18
|
+
attributes['events'] || []
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def game_id
|
|
22
|
+
attributes['game_id']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def hitter_id
|
|
26
|
+
attributes['hitter_id']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def id
|
|
30
|
+
attributes['id']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def time_code
|
|
34
|
+
attributes['time_code']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def half
|
|
38
|
+
time_code['half'] || ''
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def inning
|
|
42
|
+
time_code['inning'] || 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def number
|
|
46
|
+
time_code['number'] || 0
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def sequence
|
|
50
|
+
time_code['sequence'] || 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.from_innings(game_id:, innings:)
|
|
54
|
+
[].tap do |at_bats|
|
|
55
|
+
innings.each do |inning|
|
|
56
|
+
(inning['halfs'] || []).each do |halfs|
|
|
57
|
+
(halfs['events'] || []).each do |event|
|
|
58
|
+
if event.has_key?('at_bat')
|
|
59
|
+
at_bats << new(attributes: (event['at_bat'] || {}).
|
|
60
|
+
merge('game_id' => game_id).
|
|
61
|
+
merge('time_code' => { 'number' => inning['number'],
|
|
62
|
+
'inning' => inning['sequence'],
|
|
63
|
+
'half' => halfs['half'],
|
|
64
|
+
'sequence' => inning['sequence'] }))
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
attr_reader :attributes
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Models
|
|
4
|
+
class Pitch
|
|
5
|
+
def initialize(attributes:)
|
|
6
|
+
@attributes = attributes
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
"#{pitch_name} = #{pitch_outcome}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def at_bat_balls
|
|
14
|
+
attributes['at_bat_balls'] || 0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def at_bat_outs
|
|
18
|
+
attributes['at_bat_outs'] || 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def at_bat_pitch_count
|
|
22
|
+
attributes['at_bat_pitch_count'] || 0
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def at_bat_strikes
|
|
26
|
+
attributes['at_bat_strikes'] || 0
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def pitch_count
|
|
30
|
+
attributes['pitch_count'] || 0
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def pitch_speed
|
|
34
|
+
attributes['pitch_speed'] || 0
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def pitch_type
|
|
38
|
+
attributes['pitch_type'] || ''
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def pitch_zone
|
|
42
|
+
attributes['pitch_zone'] || ''
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def at_bat_id
|
|
46
|
+
attributes['at_bat_id']
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def event_id
|
|
50
|
+
attributes['event_id']
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def game_id
|
|
54
|
+
attributes['game_id']
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def pitcher_id
|
|
58
|
+
attributes['pitcher_id']
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def pitch_outcome_type
|
|
62
|
+
attributes['pitch_outcome_type']
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def hitter_id
|
|
66
|
+
attributes['hitter_id']
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def hit_type
|
|
70
|
+
attributes['hit_type']
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def hit_location
|
|
74
|
+
attributes['hit_location']
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def pitched_at
|
|
78
|
+
attributes['pitched_at']
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def at_bat?
|
|
82
|
+
attributes['is_ab'] || false
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def at_bat_over?
|
|
86
|
+
attributes['is_ab_over'] || false
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def bunt?
|
|
90
|
+
attributes['is_bunt'] || false
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def bunt_shown?
|
|
94
|
+
attributes['is_bunt_shown'] || false
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def double_play?
|
|
98
|
+
attributes['is_double_play'] || false
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def hit?
|
|
102
|
+
attributes['is_hit'] || false
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def on_base?
|
|
106
|
+
attributes['is_on_base'] || false
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def passed_ball?
|
|
110
|
+
attributes['is_passed_ball'] || false
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def triple_play?
|
|
114
|
+
attributes['is_triple_play'] || false
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def wild_pitch?
|
|
118
|
+
attributes['is_wild_pitch'] || false
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def number
|
|
122
|
+
attributes['number'] || 0
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def inning
|
|
126
|
+
attributes['inning'] || 0
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def half
|
|
130
|
+
attributes['half'] || ''
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def sequence
|
|
134
|
+
attributes['sequence'] || 0
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def pitch_outcome
|
|
138
|
+
attributes['pitch_outcome'] || ''
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def pitch_type
|
|
142
|
+
attributes['pitch_type'] || ''
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def pitch_name
|
|
146
|
+
PitchType.new(pitch_type: pitch_type).
|
|
147
|
+
name || ''
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.from_at_bats(game_id:, at_bats: [])
|
|
151
|
+
[].tap do |pitches|
|
|
152
|
+
at_bats.each do |at_bat|
|
|
153
|
+
at_bat.events.each do |event|
|
|
154
|
+
if event['type'] == 'pitch' && event['status'] == 'official'
|
|
155
|
+
pitches << new(attributes: event['pitcher'].
|
|
156
|
+
merge('game_id' => game_id).
|
|
157
|
+
merge('at_bat_id' => at_bat.id,
|
|
158
|
+
'event_id' => event['id'],
|
|
159
|
+
'pitched_at' => event['created_at'],
|
|
160
|
+
'pitcher_id' => event['pitcher']['id'],
|
|
161
|
+
'pitch_outcome_type' => event['outcome_id'],
|
|
162
|
+
'hitter_id' => at_bat.hitter_id,
|
|
163
|
+
'hit_type' => event['hit_type'],
|
|
164
|
+
'hit_location' => event['hit_location']).
|
|
165
|
+
merge((event['count'] || {}).transform_keys { |key| key.dup.to_s.prepend('at_bat_') }).
|
|
166
|
+
merge(event['flags']).
|
|
167
|
+
merge(at_bat.time_code).
|
|
168
|
+
merge('pitch_outcome' => PitchOutcome.new(outcome: event['outcome_id']).
|
|
169
|
+
to_s).
|
|
170
|
+
except('id'))
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
|
|
179
|
+
attr_reader :attributes
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
@@ -6,13 +6,17 @@ module Sportradar
|
|
|
6
6
|
@outcome = outcome
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def
|
|
10
|
-
|
|
9
|
+
def self.all
|
|
10
|
+
new(outcome: nil).outcomes
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
def self.to_json
|
|
14
|
+
Oj.dump('pitch_outcome_types' => all)
|
|
15
|
+
end
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
def to_s
|
|
18
|
+
outcomes[outcome] || ''
|
|
19
|
+
end
|
|
16
20
|
|
|
17
21
|
def outcomes
|
|
18
22
|
{
|
|
@@ -98,6 +102,10 @@ module Sportradar
|
|
|
98
102
|
"oTT4" => "Triple - Out at Home",
|
|
99
103
|
}
|
|
100
104
|
end
|
|
105
|
+
|
|
106
|
+
private
|
|
107
|
+
|
|
108
|
+
attr_reader :outcome
|
|
101
109
|
end
|
|
102
110
|
end
|
|
103
111
|
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Models
|
|
4
|
+
class PitchType
|
|
5
|
+
def initialize(pitch_type:)
|
|
6
|
+
@pitch_type = pitch_type
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
name
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def name
|
|
14
|
+
pitch_info['type'] || ''
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def pitch_info
|
|
18
|
+
pitch_types[pitch_type] || {}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
attr_reader :pitch_type
|
|
24
|
+
|
|
25
|
+
def pitch_types
|
|
26
|
+
{
|
|
27
|
+
'FA' => {
|
|
28
|
+
'legacy_group' => 'Fastball',
|
|
29
|
+
'legacy_id' => '1.1',
|
|
30
|
+
'type' => 'Fastball',
|
|
31
|
+
},
|
|
32
|
+
'SI' => {
|
|
33
|
+
'legacy_group' => 'Fastball',
|
|
34
|
+
'legacy_id' => '1.2',
|
|
35
|
+
'type' => 'Sinker',
|
|
36
|
+
},
|
|
37
|
+
'CT' => {
|
|
38
|
+
'legacy_group' => 'Fastball',
|
|
39
|
+
'legacy_id' => '1.3',
|
|
40
|
+
'type' => 'Cutter',
|
|
41
|
+
},
|
|
42
|
+
'CU' => {
|
|
43
|
+
'legacy_group' => 'Curveball',
|
|
44
|
+
'legacy_id' => '2.1',
|
|
45
|
+
'type' => 'Curveball',
|
|
46
|
+
},
|
|
47
|
+
'SL' => {
|
|
48
|
+
'legacy_group' => 'Slider',
|
|
49
|
+
'legacy_id' => '3.1',
|
|
50
|
+
'type' => 'Slider',
|
|
51
|
+
},
|
|
52
|
+
'CH' => {
|
|
53
|
+
'legacy_group' => 'Changeup',
|
|
54
|
+
'legacy_id' => '4.1',
|
|
55
|
+
'type' => 'Changeup',
|
|
56
|
+
},
|
|
57
|
+
'KN' => {
|
|
58
|
+
'legacy_group' => 'Other',
|
|
59
|
+
'legacy_id' => '5.1',
|
|
60
|
+
'type' => 'Knuckleball',
|
|
61
|
+
},
|
|
62
|
+
'SP' => {
|
|
63
|
+
'legacy_group' => 'Other',
|
|
64
|
+
'legacy_id' => '5.2',
|
|
65
|
+
'type' => 'Splitter',
|
|
66
|
+
},
|
|
67
|
+
'SC' => {
|
|
68
|
+
'legacy_group' => 'Other',
|
|
69
|
+
'legacy_id' => '5.3',
|
|
70
|
+
'type' => 'Screwball',
|
|
71
|
+
},
|
|
72
|
+
'FO' => {
|
|
73
|
+
'legacy_group' => 'Other',
|
|
74
|
+
'legacy_id' => '5.4',
|
|
75
|
+
'type' => 'Forkball',
|
|
76
|
+
},
|
|
77
|
+
'IB' => {
|
|
78
|
+
'legacy_group' => 'Other',
|
|
79
|
+
'legacy_id' => '5.6',
|
|
80
|
+
'type' => 'Intentional Ball',
|
|
81
|
+
},
|
|
82
|
+
'PI' => {
|
|
83
|
+
'legacy_group' => 'Other',
|
|
84
|
+
'legacy_id' => '5.7',
|
|
85
|
+
'type' => 'Pitchout',
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
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'] || {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def away_team_id
|
|
18
|
+
away['id']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def home
|
|
22
|
+
game_play_by_play['home'] || {}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def innings
|
|
26
|
+
game_play_by_play['innings'] || []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def at_bats
|
|
30
|
+
Models::AtBat.from_innings(game_id: game_id, innings: innings)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def at_bat_summary
|
|
34
|
+
at_bats.map(&:to_s)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def pitches
|
|
38
|
+
Models::Pitch.from_at_bats(game_id: game_id, at_bats: at_bats)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def pitch_summary
|
|
42
|
+
pitches.map(&:to_s)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def putouts
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
attr_reader :game_play_by_play
|
|
51
|
+
|
|
52
|
+
def build_play_by_play(team_id:, event:)
|
|
53
|
+
Sportradar::Mlb::Models::PlayByPlay.new(game_id: game_id,
|
|
54
|
+
team_id: team_id,
|
|
55
|
+
event: event)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Parsers
|
|
4
|
+
class ScoringPlaysParser
|
|
5
|
+
def initialize(game_boxscore: {})
|
|
6
|
+
@game_boxscore = game_boxscore['game'] || game_boxscore
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def game_id
|
|
10
|
+
game_boxscore['id']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def away
|
|
14
|
+
game_boxscore['away'] || {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def away_team_id
|
|
18
|
+
away['id']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def home
|
|
22
|
+
game_boxscore['home'] || {}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def home_team_id
|
|
26
|
+
home['id']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def away_events
|
|
30
|
+
away['events'] || []
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def home_events
|
|
34
|
+
home['events'] || []
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def events
|
|
38
|
+
away_events + home_events
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def away_team_plays
|
|
42
|
+
away_events.map do |event|
|
|
43
|
+
build_scoring_play(team_id: away_team_id,
|
|
44
|
+
event: event)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def home_team_plays
|
|
49
|
+
home_events.map do |event|
|
|
50
|
+
build_scoring_play(team_id: home_team_id,
|
|
51
|
+
event: event)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def all
|
|
56
|
+
away_team_plays + home_team_plays
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def away_team_hitter_ids
|
|
60
|
+
away_team_plays.map(&:hitter_id).
|
|
61
|
+
uniq
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def home_team_hitter_ids
|
|
65
|
+
home_team_plays.map(&:pitcher_id).
|
|
66
|
+
uniq
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def away_team_pitcher_ids
|
|
70
|
+
away_team_plays.map(&:pitcher_id).
|
|
71
|
+
uniq
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def home_team_pitcher_ids
|
|
75
|
+
home_team_plays.map(&:pitcher_id).
|
|
76
|
+
uniq
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def away_team_runner_ids
|
|
80
|
+
away_team_plays.map(&:runner_ids).
|
|
81
|
+
flatten.
|
|
82
|
+
uniq
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def home_team_runner_ids
|
|
86
|
+
home_team_plays.map(&:runner_ids).
|
|
87
|
+
flatten.
|
|
88
|
+
uniq
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def pitcher_ids
|
|
92
|
+
all.map(&:pitcher_id)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def hitter_ids
|
|
96
|
+
all.map(&:hitter_id)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def runner_ids
|
|
100
|
+
all.map(&:runner_ids).
|
|
101
|
+
flatten.
|
|
102
|
+
uniq
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def first
|
|
106
|
+
all.
|
|
107
|
+
first
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def last
|
|
111
|
+
all.
|
|
112
|
+
last
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
attr_reader :game_boxscore
|
|
118
|
+
|
|
119
|
+
def build_scoring_play(team_id:, event:)
|
|
120
|
+
Sportradar::Mlb::Models::ScoringPlay.new(game_id: game_id,
|
|
121
|
+
team_id: team_id,
|
|
122
|
+
event: event)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
data/lib/sportradar/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.3
|
|
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-07-
|
|
12
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -180,12 +180,16 @@ files:
|
|
|
180
180
|
- lib/sportradar/mlb/injuries.rb
|
|
181
181
|
- lib/sportradar/mlb/league_hierarchy.rb
|
|
182
182
|
- lib/sportradar/mlb/league_schedule.rb
|
|
183
|
+
- lib/sportradar/mlb/models/at_bat.rb
|
|
184
|
+
- lib/sportradar/mlb/models/pitch.rb
|
|
183
185
|
- lib/sportradar/mlb/models/pitch_outcome.rb
|
|
186
|
+
- lib/sportradar/mlb/models/pitch_type.rb
|
|
184
187
|
- lib/sportradar/mlb/models/runner.rb
|
|
185
188
|
- lib/sportradar/mlb/models/scoring_play.rb
|
|
189
|
+
- lib/sportradar/mlb/parsers/play_by_play_parser.rb
|
|
190
|
+
- lib/sportradar/mlb/parsers/scoring_plays_parser.rb
|
|
186
191
|
- lib/sportradar/mlb/play_by_play.rb
|
|
187
192
|
- lib/sportradar/mlb/player_profile.rb
|
|
188
|
-
- lib/sportradar/mlb/scoring_plays.rb
|
|
189
193
|
- lib/sportradar/mlb/team_active_rosters.rb
|
|
190
194
|
- lib/sportradar/mlb/team_profile.rb
|
|
191
195
|
- lib/sportradar/mlb/team_rosters.rb
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
module Sportradar
|
|
2
|
-
module Mlb
|
|
3
|
-
class ScoringPlays
|
|
4
|
-
def initialize(game_boxscore: {})
|
|
5
|
-
@game_boxscore = game_boxscore['game'] || game_boxscore
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def game_id
|
|
9
|
-
game_boxscore['id']
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def away
|
|
13
|
-
game_boxscore['away'] || {}
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def away_team_id
|
|
17
|
-
away['id']
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def home
|
|
21
|
-
game_boxscore['home'] || {}
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def home_team_id
|
|
25
|
-
home['id']
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def away_events
|
|
29
|
-
away['events'] || []
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def home_events
|
|
33
|
-
home['events'] || []
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def events
|
|
37
|
-
away_events + home_events
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def away_team_plays
|
|
41
|
-
away_events.map do |event|
|
|
42
|
-
build_scoring_play(team_id: away_team_id,
|
|
43
|
-
event: event)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def home_team_plays
|
|
48
|
-
home_events.map do |event|
|
|
49
|
-
build_scoring_play(team_id: home_team_id,
|
|
50
|
-
event: event)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def all
|
|
55
|
-
away_team_plays + home_team_plays
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def away_team_hitter_ids
|
|
59
|
-
away_team_plays.map(&:hitter_id).
|
|
60
|
-
uniq
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def home_team_hitter_ids
|
|
64
|
-
home_team_plays.map(&:pitcher_id).
|
|
65
|
-
uniq
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def away_team_pitcher_ids
|
|
69
|
-
away_team_plays.map(&:pitcher_id).
|
|
70
|
-
uniq
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def home_team_pitcher_ids
|
|
74
|
-
home_team_plays.map(&:pitcher_id).
|
|
75
|
-
uniq
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def away_team_runner_ids
|
|
79
|
-
away_team_plays.map(&:runner_ids).
|
|
80
|
-
flatten.
|
|
81
|
-
uniq
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def home_team_runner_ids
|
|
85
|
-
home_team_plays.map(&:runner_ids).
|
|
86
|
-
flatten.
|
|
87
|
-
uniq
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def pitcher_ids
|
|
91
|
-
all.map(&:pitcher_id)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def hitter_ids
|
|
95
|
-
all.map(&:hitter_id)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def runner_ids
|
|
99
|
-
all.map(&:runner_ids).
|
|
100
|
-
flatten.
|
|
101
|
-
uniq
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def first
|
|
105
|
-
all.
|
|
106
|
-
first
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def last
|
|
110
|
-
all.
|
|
111
|
-
last
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
private
|
|
115
|
-
|
|
116
|
-
attr_reader :game_boxscore
|
|
117
|
-
|
|
118
|
-
def build_scoring_play(team_id:, event:)
|
|
119
|
-
Sportradar::Mlb::Models::ScoringPlay.new(game_id: game_id,
|
|
120
|
-
team_id: team_id,
|
|
121
|
-
event: event)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|