gameday_api 0.5.0 → 0.5.1
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.
- data/lib/at_bat.rb +40 -0
- data/lib/batter.rb +101 -0
- data/lib/batting_appearance.rb +55 -0
- data/lib/box_score.rb +197 -0
- data/lib/cache_fetcher.rb +31 -0
- data/lib/coach.rb +16 -0
- data/lib/data_downloader.rb +231 -0
- data/lib/db_importer.rb +205 -0
- data/lib/event.rb +14 -0
- data/lib/event_log.rb +103 -0
- data/lib/game.rb +529 -0
- data/lib/game_status.rb +6 -0
- data/lib/gameday.rb +58 -0
- data/lib/gameday_fetcher.rb +245 -0
- data/lib/gameday_local_fetcher.rb +236 -0
- data/lib/gameday_parser.rb +305 -0
- data/lib/gameday_path_builder.rb +132 -0
- data/lib/gameday_remote_fetcher.rb +292 -0
- data/lib/gameday_url_builder.rb +125 -0
- data/lib/gameday_util.rb +136 -0
- data/lib/hip.rb +18 -0
- data/lib/hitchart.rb +26 -0
- data/lib/import_data.rb +8 -0
- data/lib/inning.rb +52 -0
- data/lib/line_score.rb +38 -0
- data/lib/media.rb +35 -0
- data/lib/media_highlight.rb +33 -0
- data/lib/media_mobile.rb +13 -0
- data/lib/pitch.rb +92 -0
- data/lib/pitcher.rb +131 -0
- data/lib/pitchfx_db_manager.rb +393 -0
- data/lib/pitching_appearance.rb +118 -0
- data/lib/player.rb +145 -0
- data/lib/players.rb +42 -0
- data/lib/roster.rb +61 -0
- data/lib/schedule.rb +53 -0
- data/lib/schedule_game.rb +24 -0
- data/lib/scoreboard.rb +23 -0
- data/lib/team.rb +336 -0
- metadata +42 -3
@@ -0,0 +1,292 @@
|
|
1
|
+
require 'gameday_url_builder'
|
2
|
+
|
3
|
+
class GamedayRemoteFetcher
|
4
|
+
|
5
|
+
|
6
|
+
def self.fetch(url)
|
7
|
+
resp = GamedayUtil.net_http.get_response(URI.parse(url))
|
8
|
+
case resp
|
9
|
+
when Net::HTTPSuccess
|
10
|
+
result = resp.body
|
11
|
+
else
|
12
|
+
result = nil
|
13
|
+
end
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def self.fetch_epg(year, month, day)
|
19
|
+
url = GamedayUrlBuilder.build_epg_url(year, month, day)
|
20
|
+
fetch(url)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Fetch the master scoreboard file
|
25
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/master_scoreboard.xml
|
26
|
+
def self.fetch_scoreboard(year, month, day)
|
27
|
+
url = GamedayUrlBuilder.build_scoreboard_url(year, month, day)
|
28
|
+
fetch(url)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def self.fetch_day_highlights(year, month, day)
|
33
|
+
url = GamedayUrlBuilder.build_day_highlights_url(year, month, day)
|
34
|
+
fetch(url)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Fetch the bench.xml file
|
39
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/bench.xml
|
40
|
+
def self.fetch_bench(gid)
|
41
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/bench.xml'
|
42
|
+
fetch(url)
|
43
|
+
#fetcher = CacheFetcher.new()
|
44
|
+
#return fetcher.fetch(url)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# Fetch the benchO.xml file
|
49
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/benchO.xml
|
50
|
+
def self.fetch_bencho(gid)
|
51
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/benchO.xml'
|
52
|
+
fetch(url)
|
53
|
+
#fetcher = CacheFetcher.new()
|
54
|
+
#return fetcher.fetch(url)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# Fetches the boxscore.xml file and returns its contents
|
59
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2009/month_05/day_08/gid_2009_05_08_detmlb_clemlb_1/boxscore.xml
|
60
|
+
def self.fetch_boxscore(gid)
|
61
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
62
|
+
url = GamedayUrlBuilder.build_boxscore_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
63
|
+
fetch(url)
|
64
|
+
#fetcher = CacheFetcher.new()
|
65
|
+
#return fetcher.fetch(url)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# Fetch the emailSource.xml file
|
70
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/emailSource.xml
|
71
|
+
def self.fetch_emailsource(gid)
|
72
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/emailSource.xml'
|
73
|
+
fetch(url)
|
74
|
+
#fetcher = CacheFetcher.new()
|
75
|
+
#return fetcher.fetch(url)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Fetches the eventLog.xml file and returns its contents
|
80
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_flomlb_wasmlb_1/eventLog.xml
|
81
|
+
def self.fetch_eventlog(gid)
|
82
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
83
|
+
url = GamedayUrlBuilder.build_eventlog_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
84
|
+
fetch(url)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# Fetches the game.xml file and returns its contents
|
89
|
+
def self.fetch_game_xml(gid)
|
90
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
91
|
+
url = GamedayUrlBuilder.build_game_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
92
|
+
fetch(url)
|
93
|
+
#fetcher = CacheFetcher.new()
|
94
|
+
#return fetcher.fetch(url)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def self.fetch_game_events(gid)
|
99
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
100
|
+
url = GamedayUrlBuilder.build_game_events_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
101
|
+
fetch(url)
|
102
|
+
#fetcher = CacheFetcher.new()
|
103
|
+
#return fetcher.fetch(url)
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# Fetches the gamecenter.xml file and returns its contents
|
108
|
+
def self.fetch_gamecenter_xml(gid)
|
109
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
110
|
+
url = GamedayUrlBuilder.build_gamecenter_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
111
|
+
fetch(url)
|
112
|
+
#fetcher = CacheFetcher.new()
|
113
|
+
#return fetcher.fetch(url)
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
# Fetch the gameday_Syn.xml file
|
118
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/gameday_Syn.xml
|
119
|
+
def self.fetch_gamedaysyn(gid)
|
120
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/gameday_Syn.xml'
|
121
|
+
fetch(url)
|
122
|
+
#fetcher = CacheFetcher.new()
|
123
|
+
#return fetcher.fetch(url)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# Fetch the linescore.xml file
|
128
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/linescore.xml
|
129
|
+
def self.fetch_linescore(gid)
|
130
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
131
|
+
url = GamedayUrlBuilder.build_linescore_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
132
|
+
fetch(url)
|
133
|
+
#fetcher = CacheFetcher.new()
|
134
|
+
#return fetcher.fetch(url)
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# Fetch the miniscoreboard.xml file
|
139
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/miniscoreboard.xml
|
140
|
+
def self.fetch_miniscoreboard(gid)
|
141
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/miniscoreboard.xml'
|
142
|
+
fetch(url)
|
143
|
+
#fetcher = CacheFetcher.new()
|
144
|
+
#return fetcher.fetch(url)
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
# Fetches the players.xml file and returns its contents
|
149
|
+
def self.fetch_players(gid)
|
150
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
151
|
+
url = GamedayUrlBuilder.build_players_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
152
|
+
fetch(url)
|
153
|
+
#fetcher = CacheFetcher.new()
|
154
|
+
#return fetcher.fetch(url)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
# Fetch the plays.xml file
|
159
|
+
# Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/plays.xml
|
160
|
+
def self.fetch_plays(gid)
|
161
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/plays.xml'
|
162
|
+
fetch(url)
|
163
|
+
#fetcher = CacheFetcher.new()
|
164
|
+
#return fetcher.fetch(url)
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
# Fetches the batters/(pid).xml file
|
169
|
+
def self.fetch_batter(gid, pid)
|
170
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
171
|
+
url = GamedayUrlBuilder.build_batter_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid, pid)
|
172
|
+
fetch(url)
|
173
|
+
#fetcher = CacheFetcher.new()
|
174
|
+
#return fetcher.fetch(url)
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
# Fetches the pitchers/(pid).xml file
|
179
|
+
def self.fetch_pitcher(gid, pid)
|
180
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
181
|
+
url = GamedayUrlBuilder.build_pitcher_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid, pid)
|
182
|
+
fetch(url)
|
183
|
+
#fetcher = CacheFetcher.new()
|
184
|
+
#return fetcher.fetch(url)
|
185
|
+
end
|
186
|
+
|
187
|
+
# inning/inning_X.xml
|
188
|
+
def self.fetch_inningx(gid, inning_num)
|
189
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
190
|
+
url = GamedayUrlBuilder.build_inningx_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid, inning_num)
|
191
|
+
fetch(url)
|
192
|
+
#fetcher = CacheFetcher.new()
|
193
|
+
#return fetcher.fetch(url)
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# inning/inning_Score.xml
|
198
|
+
def self.fetch_inning_scores(gid)
|
199
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
200
|
+
url = GamedayUrlBuilder.build_inning_scores_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
201
|
+
fetch(url)
|
202
|
+
#fetcher = CacheFetcher.new()
|
203
|
+
#return fetcher.fetch(url)
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
# inning/inning_hit.xml
|
208
|
+
def self.fetch_inning_hit(gid)
|
209
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
210
|
+
url = GamedayUrlBuilder.build_inning_hit_url(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
|
211
|
+
fetch(url)
|
212
|
+
#fetcher = CacheFetcher.new()
|
213
|
+
#return fetcher.fetch(url)
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
# Fetches the HTML page that lists all games for the specified date
|
218
|
+
def self.fetch_games_page(year, month, day)
|
219
|
+
url = GamedayUrlBuilder.build_day_url(year, month, day)
|
220
|
+
fetch(url)
|
221
|
+
#fetcher = CacheFetcher.new()
|
222
|
+
#return fetcher.fetch(url)
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
# Fetches the HTML page that lists all games for the specified date
|
227
|
+
def self.fetch_batters_page(gid)
|
228
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/batters/'
|
229
|
+
fetch(url)
|
230
|
+
#fetcher = CacheFetcher.new()
|
231
|
+
#return fetcher.fetch(url)
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
# Fetches the HTML page that lists all games for the specified date
|
236
|
+
def self.fetch_pitchers_page(gid)
|
237
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/pitchers/'
|
238
|
+
fetch(url)
|
239
|
+
#fetcher = CacheFetcher.new()
|
240
|
+
#return fetcher.fetch(url)
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
def self.fetch_media_highlights(gid)
|
245
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/media/highlights.xml'
|
246
|
+
fetch(url)
|
247
|
+
#fetcher = CacheFetcher.new()
|
248
|
+
#return fetcher.fetch(url)
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
def self.fetch_media_mobile(gid)
|
253
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/media/mobile.xml'
|
254
|
+
fetch(url)
|
255
|
+
#fetcher = CacheFetcher.new()
|
256
|
+
#return fetcher.fetch(url)
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
def self.fetch_onbase_linescore(gid)
|
261
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/onbase/linescore.xml'
|
262
|
+
fetch(url)
|
263
|
+
#fetcher = CacheFetcher.new()
|
264
|
+
#return fetcher.fetch(url)
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
def self.fetch_onbase_plays(gid)
|
269
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + '/onbase/plays.xml'
|
270
|
+
fetch(url)
|
271
|
+
#fetcher = CacheFetcher.new()
|
272
|
+
#return fetcher.fetch(url)
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
def self.fetch_notifications_inning(gid, inning)
|
277
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + "/notifications/notifications_#{inning}.xml"
|
278
|
+
fetch(url)
|
279
|
+
#fetcher = CacheFetcher.new()
|
280
|
+
#return fetcher.fetch(url)
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
def self.fetch_notifications_full(gid)
|
285
|
+
url = GamedayUrlBuilder.build_game_base_url(gid) + "/notifications/notifications_full.xml"
|
286
|
+
fetch(url)
|
287
|
+
#fetcher = CacheFetcher.new()
|
288
|
+
#return fetcher.fetch(url)
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'gameday'
|
2
|
+
|
3
|
+
|
4
|
+
class GamedayUrlBuilder
|
5
|
+
|
6
|
+
def self.build_game_base_url(gid)
|
7
|
+
gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
|
8
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + gameday_info['year'] + "/month_" + gameday_info['month'] + "/day_" + gameday_info['day'] + "/gid_"+gid
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def self.build_eventlog_url(year, month, day, gid)
|
13
|
+
set_date_vars(year, month, day)
|
14
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/eventLog.xml"
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def self.build_epg_url(year, month, day)
|
19
|
+
set_date_vars(year, month, day)
|
20
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/epg.xml"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.build_scoreboard_url(year, month, day)
|
25
|
+
set_date_vars(year, month, day)
|
26
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/master_scoreboard.xml"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def self.build_day_highlights_url(year, month, day)
|
31
|
+
set_date_vars(year, month, day)
|
32
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/media/highlights.xml"
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def self.build_boxscore_url(year, month, day, gid)
|
37
|
+
set_date_vars(year, month, day)
|
38
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/boxscore.xml"
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def self.build_game_url(year, month, day, gid)
|
43
|
+
set_date_vars(year, month, day)
|
44
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/game.xml"
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def self.build_game_events_url(year, month, day, gid)
|
49
|
+
set_date_vars(year, month, day)
|
50
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/game_events.xml"
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def self.build_gamecenter_url(year, month, day, gid)
|
55
|
+
set_date_vars(year, month, day)
|
56
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/gamecenter.xml"
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def self.build_linescore_url(year, month, day, gid)
|
61
|
+
set_date_vars(year, month, day)
|
62
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/linescore.xml"
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def self.build_players_url(year, month, day, gid)
|
67
|
+
set_date_vars(year, month, day)
|
68
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/players.xml"
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def self.build_batter_url(year, month, day, gid, pid)
|
73
|
+
set_date_vars(year, month, day)
|
74
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/batters/" + pid + '.xml'
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def self.build_pitcher_url(year, month, day, gid, pid)
|
79
|
+
set_date_vars(year, month, day)
|
80
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/pitchers/" + pid + '.xml'
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def self.build_inningx_url(year, month, day, gid, inning_num)
|
85
|
+
set_date_vars(year, month, day)
|
86
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/inning/inning_#{inning_num}.xml"
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def self.build_inning_scores_url(year, month, day, gid)
|
91
|
+
set_date_vars(year, month, day)
|
92
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/inning/inning_Scores.xml"
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def self.build_inning_hit_url(year, month, day, gid)
|
97
|
+
set_date_vars(year, month, day)
|
98
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_" + @@year + "/month_" + @@month + "/day_" + @@day + "/gid_"+gid+"/inning/inning_hit.xml"
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def self.build_day_url(year, month, day)
|
103
|
+
set_date_vars(year, month, day)
|
104
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_#{@@year}/month_#{@@month}/day_#{@@day}/"
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def self.build_month_url(year, month)
|
109
|
+
set_date_vars(year, month, nil)
|
110
|
+
"#{Gameday::GD2_MLB_BASE}/mlb/year_#{@@year}/month_#{@@month}/"
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def self.set_date_vars(year, month, day)
|
117
|
+
@@year = GamedayUtil.convert_digit_to_string(year.to_i)
|
118
|
+
@@month = GamedayUtil.convert_digit_to_string(month.to_i)
|
119
|
+
if day
|
120
|
+
@@day = GamedayUtil.convert_digit_to_string(day.to_i)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
end
|
data/lib/gameday_util.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
|
5
|
+
# This class provides a variety of utility methods that are used in other classes
|
6
|
+
class GamedayUtil
|
7
|
+
|
8
|
+
@@fetcher = ''
|
9
|
+
|
10
|
+
|
11
|
+
# Returns an instance of the configured fetcher, either remote or local
|
12
|
+
def self.fetcher
|
13
|
+
if @@fetcher == ''
|
14
|
+
read_config
|
15
|
+
end
|
16
|
+
if @@fetcher == 'local'
|
17
|
+
return GamedayLocalFetcher
|
18
|
+
else
|
19
|
+
return GamedayRemoteFetcher
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.set_fetcher(fetcher)
|
25
|
+
@@fetcher = fetcher
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# Parses a string with the date format of YYYYMMDD into an array
|
30
|
+
# with the following elements:
|
31
|
+
# [0] = year
|
32
|
+
# [1] = month
|
33
|
+
# [2] = day
|
34
|
+
def self.parse_date_string(date)
|
35
|
+
results = []
|
36
|
+
results << date[0..3]
|
37
|
+
results << date[4..5]
|
38
|
+
results << date[6..7]
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Converts a digit into a 2 character string, prepended with '0' if necessary
|
43
|
+
def self.convert_digit_to_string(digit)
|
44
|
+
if digit<10
|
45
|
+
return '0' + digit.to_s
|
46
|
+
else
|
47
|
+
return digit.to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Example gameday_gid = gid_2009_06_21_milmlb_detmlb_1
|
52
|
+
def self.parse_gameday_id(gameday_gid)
|
53
|
+
gameday_info = {}
|
54
|
+
gameday_info["year"] = gameday_gid[4..7]
|
55
|
+
gameday_info["month"] = gameday_gid[9..10]
|
56
|
+
gameday_info["day"] = gameday_gid[12..13]
|
57
|
+
gameday_info["visiting_team_abbrev"] = gameday_gid[15..17]
|
58
|
+
gameday_info["home_team_abbrev"] = gameday_gid[22..24]
|
59
|
+
gameday_info["game_number"] = gameday_gid[29..29]
|
60
|
+
return gameday_info
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Read configuration from gameday_config.yml file to create
|
65
|
+
# instance configuration variables.
|
66
|
+
def self.read_config
|
67
|
+
settings = YAML::load_file(File.expand_path(File.dirname(__FILE__) + "/gameday_config.yml"))
|
68
|
+
#settings = YAML::load_file(File.expand_path('gameday_config.yml'))
|
69
|
+
set_proxy_info(settings)
|
70
|
+
if @@fetcher == ''
|
71
|
+
set_fetcher(settings['fetcher'])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def self.get_connection(url)
|
77
|
+
self.read_config
|
78
|
+
begin
|
79
|
+
if !@@proxy_addr.empty?
|
80
|
+
connection = open(url, :proxy => "http://#{@@proxy_addr}:#{@@proxy_port}")
|
81
|
+
else
|
82
|
+
connection = open(url)
|
83
|
+
end
|
84
|
+
connection
|
85
|
+
rescue
|
86
|
+
puts 'Could not open connection'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def self.net_http
|
92
|
+
self.read_config
|
93
|
+
if !@@proxy_addr.empty?
|
94
|
+
return Net::HTTP::Proxy(@@proxy_addr, @@proxy_port)
|
95
|
+
else
|
96
|
+
return Net::HTTP
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def self.read_file(filename)
|
102
|
+
IO.readlines(filename,'').to_s
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def self.save_file(filename, data)
|
107
|
+
File.open(filename, 'w') {|f| f.write(data) }
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def self.is_date_valid(month, date)
|
112
|
+
if (month == 4 && date == 31) ||
|
113
|
+
(month == 6 && date == 31) ||
|
114
|
+
(month == 9 && date == 31)
|
115
|
+
return false
|
116
|
+
end
|
117
|
+
if month==4 and date<5 # start from 4/5 onward
|
118
|
+
return false
|
119
|
+
end
|
120
|
+
return true
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def self.set_proxy_info(settings)
|
127
|
+
@@proxy_addr, @@proxy_port = '', ''
|
128
|
+
if settings['proxy']
|
129
|
+
@@proxy_addr = settings['proxy']['host']
|
130
|
+
@@proxy_port = settings['proxy']['port']
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
end
|
data/lib/hip.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Hip
|
2
|
+
|
3
|
+
attr_accessor :des, :x, :y, :batter_id, :pitcher_id, :type, :team, :inning
|
4
|
+
|
5
|
+
|
6
|
+
def initialize(element)
|
7
|
+
@des = element.attributes["des"]
|
8
|
+
@des = element.attributes["x"]
|
9
|
+
@des = element.attributes["y"]
|
10
|
+
@des = element.attributes["batter"]
|
11
|
+
@des = element.attributes["pitcher"]
|
12
|
+
@des = element.attributes["type"]
|
13
|
+
@des = element.attributes["team"]
|
14
|
+
@des = element.attributes["inning"]
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
data/lib/hitchart.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'hip'
|
2
|
+
|
3
|
+
class Hitchart
|
4
|
+
|
5
|
+
attr_accessor :hips, :gid
|
6
|
+
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@hips = []
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def load_from_gid(gid)
|
14
|
+
@gid = gid
|
15
|
+
@xml_data = GamedayFetcher.fetch_inning_hit(gid)
|
16
|
+
@xml_doc = REXML::Document.new(@xml_data)
|
17
|
+
if @xml_doc.root
|
18
|
+
@xml_doc.elements.each("hitchart/hip") do |element|
|
19
|
+
hip = Hip.new(element)
|
20
|
+
@hips << hip
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
data/lib/import_data.rb
ADDED
data/lib/inning.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'at_bat'
|
2
|
+
require 'gameday_fetcher'
|
3
|
+
|
4
|
+
|
5
|
+
# This class represents a single inning of an MLB game
|
6
|
+
class Inning
|
7
|
+
|
8
|
+
attr_accessor :gid, :num, :away_team, :home_team, :top_atbats, :bottom_atbats
|
9
|
+
|
10
|
+
|
11
|
+
# loads an Inning object given a game id and an inning number
|
12
|
+
def load_from_id(gid, inning)
|
13
|
+
@top_atbats = []
|
14
|
+
@bottom_atbats = []
|
15
|
+
@gid = gid
|
16
|
+
begin
|
17
|
+
@xml_data = GamedayFetcher.fetch_inningx(gid, inning)
|
18
|
+
@xml_doc = REXML::Document.new(@xml_data)
|
19
|
+
if @xml_doc.root
|
20
|
+
@num = @xml_doc.root.attributes["num"]
|
21
|
+
@away_team = @xml_doc.root.attributes["away_team"]
|
22
|
+
@home_team = @xml_doc.root.attributes["home_team"]
|
23
|
+
set_top_ab
|
24
|
+
set_bottom_ab
|
25
|
+
end
|
26
|
+
rescue
|
27
|
+
puts "Could not load inning file for #{gid}, inning #{inning.to_s}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def set_top_ab
|
35
|
+
@xml_doc.elements.each("inning/top/atbat") { |element|
|
36
|
+
atbat = AtBat.new
|
37
|
+
atbat.init(element, @gid, @num)
|
38
|
+
@top_atbats.push atbat
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def set_bottom_ab
|
44
|
+
@xml_doc.elements.each("inning/bottom/atbat") { |element|
|
45
|
+
atbat = AtBat.new
|
46
|
+
atbat.init(element, @gid, @num)
|
47
|
+
@bottom_atbats.push atbat
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
data/lib/line_score.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
# This class contains data representing a linescore for a single game.
|
3
|
+
class LineScore
|
4
|
+
|
5
|
+
attr_accessor :xml_doc
|
6
|
+
attr_accessor :away_team_runs, :home_team_runs, :away_team_hits, :home_team_hits, :away_team_errors, :home_team_errors
|
7
|
+
attr_accessor :innings
|
8
|
+
|
9
|
+
# Initialize this instance from an XML element containing linescore data.
|
10
|
+
def init(element)
|
11
|
+
@xml_doc = element
|
12
|
+
self.away_team_runs = element.attributes["away_team_runs"]
|
13
|
+
self.away_team_hits = element.attributes["away_team_hits"]
|
14
|
+
self.away_team_errors = element.attributes["away_team_errors"]
|
15
|
+
|
16
|
+
self.home_team_runs = element.attributes["home_team_runs"]
|
17
|
+
self.home_team_hits = element.attributes["home_team_hits"]
|
18
|
+
self.home_team_errors = element.attributes["home_team_errors"]
|
19
|
+
|
20
|
+
# Set score by innings
|
21
|
+
set_innings
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def set_innings
|
26
|
+
@innings = []
|
27
|
+
@xml_doc.elements.each("inning_line_score") do |element|
|
28
|
+
score = []
|
29
|
+
score.push element.attributes["away"]
|
30
|
+
score.push element.attributes["home"]
|
31
|
+
@innings.push score
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|