sportradar 0.0.1 → 0.0.2
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 +122 -4
- data/lib/sportradar.rb +8 -0
- data/lib/sportradar/mlb/models/pitch_outcome.rb +104 -0
- data/lib/sportradar/mlb/models/runner.rb +59 -0
- data/lib/sportradar/mlb/models/scoring_play.rb +166 -0
- data/lib/sportradar/mlb/scoring_plays.rb +125 -0
- data/lib/sportradar/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1f3fa66ced94299bc569c3795968b49dc74c375
|
|
4
|
+
data.tar.gz: e4494583fb6d9ed659501121a7f012017d0586eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 22e3e0a3382d81b641d4e4aaf3f884396a4f5346ea7ac82273d131ec636237136f25f486c69494dea51fcc1576894fea2b0a21083455fe7ad5e65e94dd367b61
|
|
7
|
+
data.tar.gz: 1046595d90d3ee7320f3ff5b80e149211474f692329f11e3a799eb1a1efd4383c0f45909953d816eb9dfb41377ca9b68f3c4f11d7c680c922c9d22da9378741d
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Sportradar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Simple API client for [Sportradar API](http://developer.sportradar.us/).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Currently supports [Major League Baseball API](http://developer.sportradar.us/docs/MLB_API) endpoints.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -32,6 +32,124 @@ SPORTRADAR_API_KEY_MLB=YOUR_API_KEY
|
|
|
32
32
|
SPORTRADAR_API_KEY_NBA=YOUR_API_KEY
|
|
33
33
|
SPORTRADAR_API_KEY_NFL=YOUR_API_KEY
|
|
34
34
|
SPORTRADAR_API_KEY_NHL=YOUR_API_KEY
|
|
35
|
+
SPORTRADAR_FILE_PATH=/path/to/save/responses
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`SPORTRADAR_ACCESS_LEVEL` is `t` or 'p'
|
|
39
|
+
|
|
40
|
+
### Console
|
|
41
|
+
|
|
42
|
+
`bin/console`
|
|
43
|
+
|
|
44
|
+
### Baseball/MLB
|
|
45
|
+
|
|
46
|
+
Defaults to and supports API version 5 only.
|
|
47
|
+
|
|
48
|
+
#### API Requests
|
|
49
|
+
|
|
50
|
+
* `Sportradar::Mlb::Boxscore.new(event_id: '<game_guid>').fetch`
|
|
51
|
+
* `Sportradar::Mlb::DailyBoxscore.new(date: Date.today).fetch`
|
|
52
|
+
* `Sportradar::Mlb::DailyGameSummary.new(date: Date.today).fetch`
|
|
53
|
+
* `Sportradar::Mlb::DailyPlayByPlay.new(date: Date.today).fetch`
|
|
54
|
+
* `Sportradar::Mlb::DailySchedule.new(date: Date.today).fetch`
|
|
55
|
+
* `Sportradar::Mlb::DailySummary.new(date: Date.today).fetch`
|
|
56
|
+
* `Sportradar::Mlb::GameSummary.new(event_id: '<game_guid>').fetch`
|
|
57
|
+
* `Sportradar::Mlb::Glossary.new().fetch`
|
|
58
|
+
* `Sportradar::Mlb::Injuries.new().fetch`
|
|
59
|
+
* `Sportradar::Mlb::LeagueHierarchy.new().fetch`
|
|
60
|
+
* `Sportradar::Mlb::LeagueSchedule.new(year: '2016', interval_type: <reg|pre|pst>).fetch`
|
|
61
|
+
* `Sportradar::Mlb::PlayByPlay.new(event_id: '<game_guid>').fetch`
|
|
62
|
+
* `Sportradar::Mlb::PlayerProfile.new(player_id: '<player_guid>').fetch`
|
|
63
|
+
* `Sportradar::Mlb::TeamActiveRosters.new().fetch`
|
|
64
|
+
* `Sportradar::Mlb::TeamProfile.new(player_id: '<team_guid>').fetch`
|
|
65
|
+
* `Sportradar::Mlb::TeamRosters.new().fetch`
|
|
66
|
+
* `Sportradar::Mlb::Venues.new().fetch`
|
|
67
|
+
|
|
68
|
+
Note: `.save` vs `.fetch` will store in the path specified in `SPORTRADAR_FILE_PATH`. However, you need to have a directory created for each request within that path.
|
|
69
|
+
|
|
70
|
+
For example:
|
|
71
|
+
|
|
72
|
+
* `boxscore`
|
|
73
|
+
* `daily_boxscore`
|
|
74
|
+
* `daily_game_summary`
|
|
75
|
+
* `daily_play_by_play`
|
|
76
|
+
* `daily_schedule`
|
|
77
|
+
* `daily_summary`
|
|
78
|
+
* `game_summary`
|
|
79
|
+
* `glossary`
|
|
80
|
+
* `injuries`
|
|
81
|
+
* `league_hierarchy`
|
|
82
|
+
* `league_schedule`
|
|
83
|
+
* `play_by_play`
|
|
84
|
+
* `player_profile`
|
|
85
|
+
* `team_active_rosters`
|
|
86
|
+
* `team_profile`
|
|
87
|
+
* `team_rosters`
|
|
88
|
+
* `venues`
|
|
89
|
+
|
|
90
|
+
#### Bulk Saves
|
|
91
|
+
|
|
92
|
+
Some helpers will call `.save` for each response as separate items.
|
|
93
|
+
|
|
94
|
+
* `Sportradar::Mlb::DailyGameSummary.new(date: Date.today).perform`
|
|
95
|
+
* `Sportradar::Mlb::DailyPlayByPlay.new(date: Date.today).perform`
|
|
96
|
+
|
|
97
|
+
### Model Helpers
|
|
98
|
+
|
|
99
|
+
#### Boxscore and Scoring Plays
|
|
100
|
+
|
|
101
|
+
* `Sportradar::Mlb::ScoringPlays.new(game_boxscore: {})`
|
|
102
|
+
|
|
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
|
+
|
|
105
|
+
For example:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
sp = Sportradar::Mlb::ScoringPlays.new(game_boxscore: g.game_boxscore)
|
|
109
|
+
|
|
110
|
+
sp.first.scoring_players
|
|
111
|
+
=> [{:player_id=>"66c43b7f-760a-446c-9f50-671915570227", :player_info=>nil, :role=>"pitcher"},
|
|
112
|
+
{:player_id=>"e1633ff9-8c46-4698-9bea-3eecd478fa94", :player_info=>nil, :role=>"hitter"},
|
|
113
|
+
{:player_id=>"e1633ff9-8c46-4698-9bea-3eecd478fa94",
|
|
114
|
+
:player_info=>
|
|
115
|
+
#<Sportradar::Mlb::Models::Runner:0x007fabc82ba748
|
|
116
|
+
@runner=
|
|
117
|
+
{"id"=>"e1633ff9-8c46-4698-9bea-3eecd478fa94",
|
|
118
|
+
"starting_base"=>0,
|
|
119
|
+
"first_name"=>"Kristopher",
|
|
120
|
+
"last_name"=>"Bryant",
|
|
121
|
+
"preferred_name"=>"Kris",
|
|
122
|
+
"jersey_number"=>"17"}>,
|
|
123
|
+
:role=>"runner"}]
|
|
124
|
+
|
|
125
|
+
sp.runner_ids
|
|
126
|
+
=> ["e1633ff9-8c46-4698-9bea-3eecd478fa94",
|
|
127
|
+
"898c62b6-95bf-4973-a435-c6cb42a52158",
|
|
128
|
+
"6ef878e2-1f2d-4855-a250-2ec7c97f961c",
|
|
129
|
+
"9baf07d4-b1cb-4494-8c95-600d9e8de1a9",
|
|
130
|
+
"084d2514-9ffb-414e-ae16-3bc690aaad51",
|
|
131
|
+
"8ec56596-5b8b-41f8-88a7-384f20b8b6a7"]
|
|
132
|
+
|
|
133
|
+
sp.first.runner_ids
|
|
134
|
+
=> ["e1633ff9-8c46-4698-9bea-3eecd478fa94"]
|
|
135
|
+
|
|
136
|
+
sp.first.inning_label
|
|
137
|
+
=> "Top of 1st"
|
|
138
|
+
|
|
139
|
+
sp.first.scoring_method
|
|
140
|
+
=> "Homerun"
|
|
141
|
+
|
|
142
|
+
sp.away_team_hitter_ids
|
|
143
|
+
=> ["e1633ff9-8c46-4698-9bea-3eecd478fa94", "57f0a40f-e0f5-4e76-bd59-b8c4de7a680c"]
|
|
144
|
+
|
|
145
|
+
sp.home_team_pitcher_ids
|
|
146
|
+
=> ["1a574c70-eb33-4202-ab97-548645a4d15e", "29e9830d-b31a-4246-998c-6ca6f5a73ee8"]
|
|
147
|
+
|
|
148
|
+
sp.home_team_runner_ids
|
|
149
|
+
=> ["6ef878e2-1f2d-4855-a250-2ec7c97f961c",
|
|
150
|
+
"9baf07d4-b1cb-4494-8c95-600d9e8de1a9",
|
|
151
|
+
"084d2514-9ffb-414e-ae16-3bc690aaad51",
|
|
152
|
+
"8ec56596-5b8b-41f8-88a7-384f20b8b6a7"]
|
|
35
153
|
```
|
|
36
154
|
|
|
37
155
|
## Development
|
|
@@ -42,10 +160,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
42
160
|
|
|
43
161
|
## Contributing
|
|
44
162
|
|
|
45
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
163
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/stattleship/sportradar.
|
|
46
164
|
|
|
47
165
|
|
|
48
166
|
## License
|
|
49
167
|
|
|
50
|
-
|
|
168
|
+
None.
|
|
51
169
|
|
data/lib/sportradar.rb
CHANGED
|
@@ -15,6 +15,12 @@ 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/pitch_outcome'
|
|
19
|
+
require 'sportradar/mlb/models/runner'
|
|
20
|
+
require 'sportradar/mlb/models/scoring_play'
|
|
21
|
+
|
|
22
|
+
require 'sportradar/mlb/scoring_plays'
|
|
23
|
+
|
|
18
24
|
require 'sportradar/mlb/boxscore'
|
|
19
25
|
require 'sportradar/mlb/daily_boxscore'
|
|
20
26
|
require 'sportradar/mlb/daily_schedule'
|
|
@@ -33,4 +39,6 @@ require 'sportradar/mlb/team_profile'
|
|
|
33
39
|
require 'sportradar/mlb/team_rosters'
|
|
34
40
|
require 'sportradar/mlb/venues'
|
|
35
41
|
|
|
42
|
+
Oj.default_options = {}
|
|
43
|
+
|
|
36
44
|
Dotenv.load
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Models
|
|
4
|
+
class PitchOutcome
|
|
5
|
+
def initialize(outcome:)
|
|
6
|
+
@outcome = outcome
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
outcomes[outcome] || ''
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
attr_reader :outcome
|
|
16
|
+
|
|
17
|
+
def outcomes
|
|
18
|
+
{
|
|
19
|
+
"aBK" => "Balk",
|
|
20
|
+
"aCI" => "Catcher Interference",
|
|
21
|
+
"aD" => "Double",
|
|
22
|
+
"aDAD3" => "Double - Adv 3rd",
|
|
23
|
+
"aDAD4" => "Double - Adv Home",
|
|
24
|
+
"aFCAD2" => "Fielders Choice - Adv 2nd",
|
|
25
|
+
"aFCAD3" => "Fielders Choice - Adv 3rd",
|
|
26
|
+
"aFCAD4" => "Fielders Choice - Adv Home",
|
|
27
|
+
"aHBP" => "Hit By Pitch",
|
|
28
|
+
"aHR" => "Homerun",
|
|
29
|
+
"aKLAD1" => "Strike Looking - Adv 1st",
|
|
30
|
+
"aKLAD2" => "Strike Looking - Adv 2nd",
|
|
31
|
+
"aKLAD3" => "Strike Looking - Adv 3rd",
|
|
32
|
+
"aKLAD4" => "Strike Looking - Adv Home",
|
|
33
|
+
"aKSAD1" => "Strike Swinging - Adv 1st",
|
|
34
|
+
"aKSAD2" => "Strike Swinging - Adv 2nd",
|
|
35
|
+
"aKSAD3" => "Strike Swinging - Adv 3rd",
|
|
36
|
+
"aKSAD4" => "Strike Swinging - Adv Home",
|
|
37
|
+
"aROE" => "Reached On Error",
|
|
38
|
+
"aROEAD2" => "Reached On Error - Adv 2nd",
|
|
39
|
+
"aROEAD3" => "Reached On Error - Adv 3rd",
|
|
40
|
+
"aROEAD4" => "Reached On Error - Adv Home",
|
|
41
|
+
"aS" => "Single",
|
|
42
|
+
"aSAD2" => "Single - Adv 2nd",
|
|
43
|
+
"aSAD3" => "Single - Adv 3rd",
|
|
44
|
+
"aSAD4" => "Single - Adv Home",
|
|
45
|
+
"aSBAD1" => "Sacrifice Bunt - Adv 1st",
|
|
46
|
+
"aSBAD2" => "Sacrifice Bunt - Adv 2nd",
|
|
47
|
+
"aSBAD3" => "Sacrifice Bunt - Adv 3rd",
|
|
48
|
+
"aSBAD4" => "Sacrifice Bunt - Adv Home",
|
|
49
|
+
"aSFAD1" => "Sacrifice Fly - Adv 1st",
|
|
50
|
+
"aSFAD2" => "Sacrifice Fly - Adv 2nd",
|
|
51
|
+
"aSFAD3" => "Sacrifice Fly - Adv 3rd",
|
|
52
|
+
"aSFAD4" => "Sacrifice Fly - Adv Home",
|
|
53
|
+
"aT" => "Triple",
|
|
54
|
+
"aTAD4" => "Triple - Adv Home",
|
|
55
|
+
"bB" => "Ball",
|
|
56
|
+
"bDB" => "Dirt Ball",
|
|
57
|
+
"bIB" => "iBall",
|
|
58
|
+
"bPO" => "Pitchout",
|
|
59
|
+
"kF" => "Foul Ball",
|
|
60
|
+
"kFT" => "Foul Tip",
|
|
61
|
+
"kKL" => "Strike Looking",
|
|
62
|
+
"kKS" => "Strike Swinging",
|
|
63
|
+
"oBI" => "Batter Interference",
|
|
64
|
+
"oDT3" => "Double - Out at 3rd",
|
|
65
|
+
"oDT4" => "Double - Out at Home",
|
|
66
|
+
"oFC" => "Fielders Choice",
|
|
67
|
+
"oFCT2" => "Fielders Choice - Out at 2nd",
|
|
68
|
+
"oFCT3" => "Fielders Choice - Out at 3rd",
|
|
69
|
+
"oFCT4" => "Fielders Choice - Out at Home",
|
|
70
|
+
"oFO" => "Fly Out",
|
|
71
|
+
"oGO" => "Ground Out",
|
|
72
|
+
"oKLT1" => "Strike Looking - Out at 1st",
|
|
73
|
+
"oKLT2" => "Strike Looking - Out at 2nd",
|
|
74
|
+
"oKLT3" => "Strike Looking - Out at 3rd",
|
|
75
|
+
"oKLT4" => "Strike Looking - Out at Home",
|
|
76
|
+
"oKST1" => "Strike Swinging - Out at 1st",
|
|
77
|
+
"oKST2" => "Strike Swinging - Out at 2nd",
|
|
78
|
+
"oKST3" => "Strike Swinging - Out at 3rd",
|
|
79
|
+
"oKST4" => "Strike Swinging - Out at Home",
|
|
80
|
+
"oLO" => "Line Out",
|
|
81
|
+
"oOBB" => "Out of Batters Box",
|
|
82
|
+
"oOP" => "Out on Appeal",
|
|
83
|
+
"oPO" => "Pop Out",
|
|
84
|
+
"oROET2" => "Reached On Error - Out at 2nd",
|
|
85
|
+
"oROET3" => "Reached On Error - Out at 3rd",
|
|
86
|
+
"oROET4" => "Reached On Error - Out at Home",
|
|
87
|
+
"oSB" => "Sacrifice Bunt",
|
|
88
|
+
"oSBT2" => "Sacrifice Bunt - Out at 2nd",
|
|
89
|
+
"oSBT3" => "Sacrifice Bunt - Out at 3rd",
|
|
90
|
+
"oSBT4" => "Sacrifice Bunt - Out at Home",
|
|
91
|
+
"oSF" => "Sacrifice Fly",
|
|
92
|
+
"oSFT2" => "Sacrifice Fly - Out at 2nd",
|
|
93
|
+
"oSFT3" => "Sacrifice Fly - Out at 3rd",
|
|
94
|
+
"oSFT4" => "Sacrifice Fly - Out at Home",
|
|
95
|
+
"oST2" => "Single - Out at 2nd",
|
|
96
|
+
"oST3" => "Single - Out at 3rd",
|
|
97
|
+
"oST4" => "Single - Out at Home",
|
|
98
|
+
"oTT4" => "Triple - Out at Home",
|
|
99
|
+
}
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Models
|
|
4
|
+
class Runner
|
|
5
|
+
def initialize(runner: {})
|
|
6
|
+
@runner = runner
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def id
|
|
10
|
+
runner['id']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def first_name
|
|
14
|
+
runner['first_name']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def jersey_number
|
|
18
|
+
runner['jersey_number']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def last_name
|
|
22
|
+
runner['last_name']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def preferred_name
|
|
26
|
+
runner['preferred_name']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def starting_base
|
|
30
|
+
runner['starting_base']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def starting_base_name
|
|
34
|
+
if starting_base
|
|
35
|
+
if starting_base == 0
|
|
36
|
+
'Home'
|
|
37
|
+
else
|
|
38
|
+
"#{ActiveSupport::Inflector.ordinalize(starting_base)} base"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def starting_base_label
|
|
44
|
+
if starting_base
|
|
45
|
+
if starting_base == 0
|
|
46
|
+
'HP'
|
|
47
|
+
else
|
|
48
|
+
"#{starting_base}B"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
attr_reader :runner
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Mlb
|
|
3
|
+
module Models
|
|
4
|
+
class ScoringPlay
|
|
5
|
+
def initialize(game_id:, team_id:, event:)
|
|
6
|
+
@game_id = game_id
|
|
7
|
+
@team_id = team_id
|
|
8
|
+
@event = event
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def id
|
|
12
|
+
event['id']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def hitter_id
|
|
16
|
+
event['hitter_id']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def hitter_outcome
|
|
20
|
+
event['hitter_outcome']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def inning
|
|
24
|
+
event['inning']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def oridinal_inning
|
|
28
|
+
ActiveSupport::Inflector.ordinalize(inning)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def inning_half
|
|
32
|
+
event['inning_half']
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def inning_half_label
|
|
36
|
+
case inning_half
|
|
37
|
+
when 'B'
|
|
38
|
+
'Bottom of'
|
|
39
|
+
when 'T'
|
|
40
|
+
'Top of'
|
|
41
|
+
else
|
|
42
|
+
''
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def inning_label
|
|
47
|
+
if inning
|
|
48
|
+
"#{inning_half_label} #{oridinal_inning}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def pitcher_id
|
|
53
|
+
event['pitcher_id']
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def runners
|
|
57
|
+
(event['runners'] || []).map do |runner|
|
|
58
|
+
Runner.new(runner: runner)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def runner_ids
|
|
63
|
+
(runners || []).map(&:id)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def play_type
|
|
67
|
+
event['type']
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def pitch?
|
|
71
|
+
play_type == 'pitch'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def period_number
|
|
75
|
+
inning
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def points
|
|
79
|
+
runners.count
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def scored_at
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def scoring_conversion
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def scoring_conversion_points
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def scoring_method
|
|
92
|
+
PitchOutcome.new(outcome: hitter_outcome).
|
|
93
|
+
to_s
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def scoring_how
|
|
97
|
+
play_type
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def scoring_type
|
|
101
|
+
hitter_outcome
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def time_code
|
|
105
|
+
"#{inning_half}#{inning}"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def period_seconds
|
|
109
|
+
0
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def empty_net
|
|
113
|
+
false
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def conversion
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def conversion_points
|
|
120
|
+
0
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def yards
|
|
124
|
+
0
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def pitcher_role
|
|
128
|
+
{
|
|
129
|
+
player_id: pitcher_id,
|
|
130
|
+
player_info: nil,
|
|
131
|
+
role: 'pitcher',
|
|
132
|
+
}
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def hitter_role
|
|
136
|
+
{
|
|
137
|
+
player_id: hitter_id,
|
|
138
|
+
player_info: nil,
|
|
139
|
+
role: 'hitter',
|
|
140
|
+
}
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def runner_roles
|
|
144
|
+
runners.map do |runner|
|
|
145
|
+
{
|
|
146
|
+
player_id: runner.id,
|
|
147
|
+
player_info: runner,
|
|
148
|
+
role: 'runner',
|
|
149
|
+
}
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def scoring_players
|
|
154
|
+
[
|
|
155
|
+
pitcher_role,
|
|
156
|
+
hitter_role,
|
|
157
|
+
runner_roles,
|
|
158
|
+
].compact.
|
|
159
|
+
flatten
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
attr_reader :event, :game_id, :team_id
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
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.2
|
|
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-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -180,8 +180,12 @@ 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/pitch_outcome.rb
|
|
184
|
+
- lib/sportradar/mlb/models/runner.rb
|
|
185
|
+
- lib/sportradar/mlb/models/scoring_play.rb
|
|
183
186
|
- lib/sportradar/mlb/play_by_play.rb
|
|
184
187
|
- lib/sportradar/mlb/player_profile.rb
|
|
188
|
+
- lib/sportradar/mlb/scoring_plays.rb
|
|
185
189
|
- lib/sportradar/mlb/team_active_rosters.rb
|
|
186
190
|
- lib/sportradar/mlb/team_profile.rb
|
|
187
191
|
- lib/sportradar/mlb/team_rosters.rb
|