greenmonster 0.3.1 → 0.3.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.
Files changed (55) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.markdown +6 -0
  3. data/README.markdown +37 -2
  4. data/doc/Athlete.html +254 -0
  5. data/doc/Gemfile.html +20 -0
  6. data/doc/Greenmonster/Generators/InstallGenerator.html +253 -0
  7. data/doc/Greenmonster/Generators.html +147 -0
  8. data/doc/Greenmonster/Parser.html +263 -0
  9. data/doc/Greenmonster/Player.html +236 -0
  10. data/doc/Greenmonster/Spider.html +169 -21
  11. data/doc/Greenmonster.html +139 -2
  12. data/doc/GreenmonsterPlayerTest.html +199 -0
  13. data/doc/GreenmonsterSpiderTest.html +57 -4
  14. data/doc/GreenmonsterTest.html +20 -0
  15. data/doc/GreenmonsterTraversalTest.html +376 -0
  16. data/doc/InstallGreenmonster.html +260 -0
  17. data/doc/Rakefile.html +20 -0
  18. data/doc/TestCreatePlayersFromGamedayXMLGame.html +266 -0
  19. data/doc/TestParsePlayersFromGamedayXMLFiles.html +307 -0
  20. data/doc/created.rid +18 -9
  21. data/doc/index.html +20 -0
  22. data/doc/js/search_index.js +1 -1
  23. data/doc/table_of_contents.html +93 -1
  24. data/greenmonster.gemspec +4 -2
  25. data/lib/generators/greenmonster/install_mlb_games_generator.rb +20 -0
  26. data/lib/generators/greenmonster/install_players_generator.rb +20 -0
  27. data/lib/generators/templates/install_greenmonster_mlb_games_migration.rb +54 -0
  28. data/lib/generators/templates/install_greenmonster_players_migration.rb +37 -0
  29. data/lib/greenmonster/model_extensions/mlb_game.rb +106 -0
  30. data/lib/greenmonster/model_extensions/mlb_probable_pitcher.rb +11 -0
  31. data/lib/greenmonster/model_extensions/player.rb +16 -0
  32. data/lib/greenmonster/parser.rb +27 -0
  33. data/lib/greenmonster/spider.rb +7 -6
  34. data/lib/greenmonster/version.rb +1 -1
  35. data/lib/greenmonster.rb +46 -0
  36. data/test/games/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/boxscore.xml +5 -0
  37. data/test/games/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/eventLog.xml +1 -0
  38. data/test/games/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/inning/inning_all.xml +1 -0
  39. data/test/games/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/inning/inning_hit.xml +1 -0
  40. data/test/games/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/linescore.xml +117 -0
  41. data/test/games/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/players.xml +56 -0
  42. data/test/games/mlb/year_2012/month_03/day_27/gid_2012_03_27_aaamlb_aabmlb_1/blank.txt +0 -0
  43. data/test/games/tst/year_2012/month_03/day_27/gid_2012_03_27_aaamlb_aabmlb_1/blank.txt +0 -0
  44. data/test/test_create_mlb_game_from_gameday_xml_game.rb +12 -0
  45. data/test/test_create_players_from_gameday_xml_game.rb +8 -0
  46. data/test/test_greenmonster.rb +3 -6
  47. data/test/test_greenmonster_player.rb +7 -0
  48. data/test/test_greenmonster_spider.rb +24 -18
  49. data/test/test_greenmonster_traversal.rb +31 -0
  50. data/test/test_helper.rb +78 -0
  51. data/test/test_line_score.rb +12 -0
  52. data/test/test_parse_mlb_probable_pitchers_from_linescore_data.rb +14 -0
  53. data/test/test_parse_players_from_gameday_xml_files.rb +21 -0
  54. data/test/test_update_mlb_game_with_linescore_data.rb +23 -0
  55. metadata +103 -7
@@ -0,0 +1 @@
1
+ <!--Copyright 2012 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt--><hitchart><hip des="Double" x="60.24" y="121.49" batter="434658" pitcher="407793" type="H" team="A" inning="1"/><hip des="Flyout" x="126.51" y="106.43" batter="519346" pitcher="407793" type="O" team="A" inning="1"/><hip des="Error" x="63.52" y="101.02" batter="430832" pitcher="407793" type="E" team="A" inning="1"/><hip des="Groundout" x="135.54" y="151.61" batter="430832" pitcher="407793" type="O" team="A" inning="1"/><hip des="Single" x="118.47" y="106.43" batter="453056" pitcher="453344" type="H" team="H" inning="1"/><hip des="Groundout" x="100.40" y="154.62" batter="456030" pitcher="453344" type="O" team="H" inning="1"/><hip des="Flyout" x="75.30" y="102.41" batter="429665" pitcher="407793" type="O" team="A" inning="2"/><hip des="Home Run" x="60.24" y="59.24" batter="431094" pitcher="407793" type="H" team="A" inning="2"/><hip des="Double" x="93.37" y="61.24" batter="501983" pitcher="407793" type="H" team="A" inning="2"/><hip des="Single" x="142.57" y="119.48" batter="150348" pitcher="407793" type="H" team="A" inning="2"/><hip des="Pop Out" x="138.55" y="142.57" batter="434658" pitcher="407793" type="O" team="A" inning="2"/><hip des="Pop Out" x="150.60" y="134.54" batter="425903" pitcher="453344" type="O" team="H" inning="2"/><hip des="Single" x="77.31" y="129.52" batter="519346" pitcher="407793" type="H" team="A" inning="3"/><hip des="Single" x="83.33" y="101.41" batter="430832" pitcher="407793" type="H" team="A" inning="3"/><hip des="Single" x="132.53" y="102.41" batter="452252" pitcher="407793" type="H" team="A" inning="3"/><hip des="Flyout" x="95.38" y="54.22" batter="429665" pitcher="407793" type="O" team="A" inning="3"/><hip des="Single" x="116.47" y="106.43" batter="431094" pitcher="407793" type="H" team="A" inning="3"/><hip des="Double" x="206.83" y="100.40" batter="501983" pitcher="407793" type="H" team="A" inning="3"/><hip des="Flyout" x="178.71" y="105.42" batter="150040" pitcher="235095" type="O" team="A" inning="3"/><hip des="Flyout" x="90.36" y="91.37" batter="150348" pitcher="235095" type="O" team="A" inning="3"/><hip des="Groundout" x="158.63" y="165.66" batter="457454" pitcher="453344" type="O" team="H" inning="3"/><hip des="Single" x="61.24" y="100.40" batter="340192" pitcher="453344" type="H" team="H" inning="3"/><hip des="Flyout" x="169.68" y="63.25" batter="453056" pitcher="453344" type="O" team="H" inning="3"/><hip des="Flyout" x="170.68" y="122.49" batter="434658" pitcher="235095" type="O" team="A" inning="4"/><hip des="Pop Out" x="157.63" y="164.66" batter="519346" pitcher="235095" type="O" team="A" inning="4"/><hip des="Flyout" x="151.61" y="106.43" batter="430832" pitcher="235095" type="O" team="A" inning="4"/><hip des="Flyout" x="67.27" y="106.43" batter="456030" pitcher="453344" type="O" team="H" inning="4"/><hip des="Groundout" x="141.57" y="157.63" batter="408236" pitcher="453344" type="O" team="H" inning="4"/><hip des="Groundout" x="134.54" y="147.59" batter="120074" pitcher="453344" type="O" team="H" inning="4"/><hip des="Groundout" x="153.61" y="167.67" batter="452252" pitcher="235095" type="O" team="A" inning="5"/><hip des="Lineout" x="106.43" y="156.63" batter="429665" pitcher="235095" type="O" team="A" inning="5"/><hip des="Groundout" x="113.45" y="160.64" batter="431094" pitcher="235095" type="O" team="A" inning="5"/><hip des="Flyout" x="63.25" y="128.51" batter="502210" pitcher="453344" type="O" team="H" inning="5"/><hip des="Single" x="136.55" y="112.45" batter="136770" pitcher="453344" type="H" team="H" inning="5"/><hip des="Triple" x="136.55" y="37.15" batter="453056" pitcher="453344" type="H" team="H" inning="5"/><hip des="Double" x="93.37" y="119.48" batter="408236" pitcher="453344" type="H" team="H" inning="5"/><hip des="Groundout" x="133.53" y="154.62" batter="501605" pitcher="453344" type="O" team="H" inning="5"/><hip des="Double" x="214.86" y="102.41" batter="501983" pitcher="469686" type="H" team="A" inning="6"/><hip des="Bunt Groundout" x="130.52" y="192.77" batter="150040" pitcher="469686" type="O" team="A" inning="6"/><hip des="Pop Out" x="165.66" y="177.71" batter="150348" pitcher="469686" type="O" team="A" inning="6"/><hip des="Pop Out" x="125.50" y="159.64" batter="434658" pitcher="469686" type="O" team="A" inning="6"/><hip des="Groundout" x="100.40" y="175.70" batter="457454" pitcher="469802" type="O" team="H" inning="6"/><hip des="Flyout" x="174.70" y="107.43" batter="519346" pitcher="469686" type="O" team="A" inning="7"/><hip des="Groundout" x="98.39" y="169.68" batter="430832" pitcher="469686" type="O" team="A" inning="7"/><hip des="Field Error" x="40.16" y="114.46" batter="429665" pitcher="469686" type="E" team="A" inning="7"/><hip des="Groundout" x="103.41" y="171.69" batter="431094" pitcher="469686" type="O" team="A" inning="7"/><hip des="Groundout" x="103.41" y="172.69" batter="340192" pitcher="469802" type="O" team="H" inning="7"/><hip des="Single" x="127.51" y="167.67" batter="453056" pitcher="469802" type="H" team="H" inning="7"/><hip des="Single" x="137.55" y="107.43" batter="456030" pitcher="469802" type="H" team="H" inning="7"/><hip des="Groundout" x="154.62" y="169.68" batter="408236" pitcher="469802" type="O" team="H" inning="7"/><hip des="Groundout" x="158.63" y="168.67" batter="501983" pitcher="469686" type="O" team="A" inning="8"/><hip des="Single" x="66.27" y="121.49" batter="150348" pitcher="469686" type="H" team="A" inning="8"/><hip des="Double" x="128.51" y="38.15" batter="434658" pitcher="469686" type="H" team="A" inning="8"/><hip des="Single" x="112.45" y="96.39" batter="501605" pitcher="430630" type="H" team="H" inning="8"/><hip des="Double" x="59.24" y="143.57" batter="120074" pitcher="430630" type="H" team="H" inning="8"/><hip des="Triple" x="124.50" y="82.33" batter="457454" pitcher="430630" type="H" team="H" inning="8"/><hip des="Flyout" x="75.30" y="95.38" batter="136770" pitcher="430630" type="O" team="H" inning="8"/><hip des="Groundout" x="108.43" y="160.64" batter="430832" pitcher="458006" type="O" team="A" inning="9"/><hip des="Lineout" x="81.33" y="89.36" batter="429665" pitcher="458006" type="O" team="A" inning="9"/><hip des="Single" x="102.41" y="154.62" batter="431094" pitcher="458006" type="H" team="A" inning="9"/><hip des="Groundout" x="112.45" y="172.69" batter="501983" pitcher="458006" type="O" team="A" inning="9"/><hip des="Single" x="165.66" y="119.48" batter="453056" pitcher="407911" type="H" team="H" inning="9"/></hitchart>
@@ -0,0 +1,117 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><!--Copyright 2011 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt-->
2
+ <game id="2011/07/04/tormlb-bosmlb-1" venue="Fenway Park" game_pk="288186"
3
+ time="1:35"
4
+ time_zone="ET"
5
+ ampm="PM"
6
+ away_time="1:35"
7
+ away_time_zone="ET"
8
+ away_ampm="PM"
9
+ home_time="1:35"
10
+ home_time_zone="ET"
11
+ home_ampm="PM"
12
+ game_type="R"
13
+ time_aw_lg="1:35"
14
+ aw_lg_ampm="PM"
15
+ tz_aw_lg_gen="ET"
16
+ time_hm_lg="1:35"
17
+ hm_lg_ampm="PM"
18
+ tz_hm_lg_gen="ET"
19
+ venue_id="3"
20
+ scheduled_innings="9"
21
+ away_name_abbrev="TOR"
22
+ home_name_abbrev="BOS"
23
+ away_code="tor"
24
+ away_file_code="tor"
25
+ away_team_id="141"
26
+ away_team_city="Toronto"
27
+ away_team_name="Blue Jays"
28
+ away_division="E"
29
+ away_league_id="103"
30
+ away_sport_code="mlb"
31
+ home_code="bos"
32
+ home_file_code="bos"
33
+ home_team_id="111"
34
+ home_team_city="Boston"
35
+ home_team_name="Red Sox"
36
+ home_division="E"
37
+ home_league_id="103"
38
+ home_sport_code="mlb"
39
+ day="MON"
40
+ gameday_sw="P"
41
+ away_games_back="9.5"
42
+ home_games_back="1.5"
43
+ away_games_back_wildcard="8.0"
44
+ home_games_back_wildcard="-"
45
+ venue_w_chan_loc="USMA0046"
46
+ gameday_link="2011_07_04_tormlb_bosmlb_1"
47
+ away_win="42"
48
+ away_loss="44"
49
+ home_win="49"
50
+ home_loss="35"
51
+ league="AA"
52
+ top_inning="N"
53
+ inning_state=""
54
+ status="Final"
55
+ ind="F"
56
+ inning="9"
57
+ outs="3"
58
+ away_team_runs="9"
59
+ home_team_runs="7"
60
+ away_team_hits="13"
61
+ home_team_hits="11"
62
+ away_team_errors="0"
63
+ home_team_errors="2"
64
+ wrapup_link="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=wrap&amp;c_id=mlb"
65
+ home_preview_link="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=preview&amp;c_id=mlb"
66
+ away_preview_link="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=preview&amp;c_id=mlb"
67
+ preview="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=preview&amp;c_id=mlb"
68
+ tv_station="NESN, MLBN"
69
+ home_recap_link="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=recap&amp;c_id=bos"
70
+ away_recap_link="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=recap&amp;c_id=tor"
71
+ photos_link="/mlb/gameday/index.jsp?gid=2011_07_04_tormlb_bosmlb_1&amp;mode=photos">
72
+ <linescore inning="1" home_inning_runs="0" away_inning_runs="1"/>
73
+ <linescore inning="2" home_inning_runs="0" away_inning_runs="2"/>
74
+ <linescore inning="3" home_inning_runs="0" away_inning_runs="4"/>
75
+ <linescore inning="4" home_inning_runs="0" away_inning_runs="0"/>
76
+ <linescore inning="5" home_inning_runs="4" away_inning_runs="0"/>
77
+ <linescore inning="6" home_inning_runs="0" away_inning_runs="0"/>
78
+ <linescore inning="7" home_inning_runs="0" away_inning_runs="1"/>
79
+ <linescore inning="8" home_inning_runs="3" away_inning_runs="1"/>
80
+ <linescore inning="9" home_inning_runs="0" away_inning_runs="0"/>
81
+ <winning_pitcher first_name="Brandon" first="Brandon" id="453344" last_name="Morrow"
82
+ last="Morrow"
83
+ name_display_roster="Morrow"
84
+ wins="5"
85
+ losses="4"
86
+ era="4.72"
87
+ s_wins=""
88
+ s_losses=""
89
+ s_era=""/>
90
+ <losing_pitcher first_name="John" first="John" id="407793" last_name="Lackey" last="Lackey"
91
+ name_display_roster="Lackey"
92
+ wins="5"
93
+ losses="8"
94
+ era="7.47"
95
+ s_wins=""
96
+ s_losses=""
97
+ s_era=""/>
98
+ <save_pitcher first_name="Frank" first="Frank" id="407911" last_name="Francisco"
99
+ last="Francisco"
100
+ name_display_roster="Francisco, F"
101
+ wins="1"
102
+ losses="4"
103
+ era="4.81"
104
+ s_wins=""
105
+ s_losses=""
106
+ s_era=""
107
+ saves="10"/>
108
+ <game_media>
109
+ <media type="game" calendar_event_id="14-288186-2011-07-04"
110
+ start="2011-07-04T13:35:00-0400"
111
+ title="TOR @ BOS"
112
+ has_mlbtv="true"
113
+ free="NO"
114
+ media_state="media_archive"
115
+ thumbnail="http://mediadownloads.mlb.com/mlbam/preview/torbos_288186_preview.jpg"/>
116
+ </game_media>
117
+ </game>
@@ -0,0 +1,56 @@
1
+ <!--Copyright 2012 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt--><game venue="Fenway Park" date="July 4, 2011">
2
+ <team type="away" id="TOR" name="Toronto Blue Jays">
3
+ <player id="136734" first="Octavio" last="Dotel" num="29" boxname="Dotel" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="1" era="3.86"/>
4
+ <player id="150040" first="Jose" last="Molina" num="8" boxname="Molina, J" rl="R" position="C" status="A" bat_order="8" game_position="C" avg=".301" hr="2" rbi="7"/>
5
+ <player id="150348" first="John" last="McDonald" num="6" boxname="McDonald, Jo" rl="R" position="2B" status="A" bat_order="9" game_position="SS" avg=".197" hr="2" rbi="13"/>
6
+ <player id="279913" first="Corey" last="Patterson" num="16" boxname="Patterson, C" rl="R" position="LF" status="A" avg=".258" hr="6" rbi="31"/>
7
+ <player id="400010" first="Jon" last="Rauch" num="60" boxname="Rauch" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="3" era="4.11"/>
8
+ <player id="407911" first="Frank" last="Francisco" num="50" boxname="Francisco, F" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="1" losses="4" era="5.01"/>
9
+ <player id="425861" first="Shawn" last="Camp" num="57" boxname="Camp" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="1" losses="1" era="4.00"/>
10
+ <player id="429665" first="Edwin" last="Encarnacion" num="10" boxname="Encarnacion" rl="R" position="3B" status="A" bat_order="5" game_position="DH" avg=".250" hr="6" rbi="19"/>
11
+ <player id="430630" first="Jason" last="Frasor" num="54" boxname="Frasor" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="1" era="2.70"/>
12
+ <player id="430832" first="Jose" last="Bautista" num="19" boxname="Bautista" rl="R" position="RF" status="A" bat_order="3" game_position="3B" avg=".331" hr="27" rbi="56"/>
13
+ <player id="431094" first="Aaron" last="Hill" num="2" boxname="Hill, A" rl="R" position="2B" status="A" bat_order="6" game_position="2B" avg=".240" hr="3" rbi="31"/>
14
+ <player id="434658" first="Rajai" last="Davis" num="11" boxname="Davis, R" rl="R" position="CF" status="A" bat_order="1" game_position="CF" avg=".233" hr="1" rbi="17"/>
15
+ <player id="446399" first="Brett" last="Cecil" num="27" boxname="Cecil" rl="L" position="P" status="A" avg=".000" hr="0" rbi="0" wins="1" losses="3" era="7.24"/>
16
+ <player id="450317" first="J.P." last="Arencibia" num="9" boxname="Arencibia" rl="R" position="C" status="A" avg=".216" hr="12" rbi="36"/>
17
+ <player id="452252" first="Adam" last="Lind" num="26" boxname="Lind" rl="L" position="1B" status="A" bat_order="4" game_position="1B" avg=".310" hr="16" rbi="49"/>
18
+ <player id="453344" first="Brandon" last="Morrow" num="23" boxname="Morrow" rl="R" position="P" status="A" bat_order="0" game_position="P" avg=".000" hr="0" rbi="0" wins="4" losses="4" era="4.56"/>
19
+ <player id="453454" first="Mike" last="McCoy" num="18" boxname="McCoy" rl="R" position="2B" status="A" avg=".217" hr="1" rbi="4"/>
20
+ <player id="453646" first="Carlos" last="Villanueva" num="33" boxname="Villanueva" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="5" losses="1" era="3.24"/>
21
+ <player id="457456" first="Jo-Jo" last="Reyes" num="37" boxname="Reyes, Jo" rl="L" position="P" status="A" avg=".250" hr="0" rbi="0" wins="3" losses="7" era="4.85"/>
22
+ <player id="460069" first="Ricky" last="Romero" num="24" boxname="Romero, R" rl="L" position="P" status="A" avg=".167" hr="0" rbi="2" wins="7" losses="7" era="2.75"/>
23
+ <player id="469802" first="Luis" last="Perez" num="47" boxname="Perez, L" rl="L" position="P" status="A" avg=".000" hr="0" rbi="0" wins="1" losses="1" era="3.71"/>
24
+ <player id="488862" first="Yunel" last="Escobar" num="5" boxname="Escobar, Y" rl="R" position="SS" status="A" avg=".289" hr="9" rbi="29"/>
25
+ <player id="501983" first="Travis" last="Snider" num="45" boxname="Snider" rl="L" position="RF" status="A" bat_order="7" game_position="RF" avg=".184" hr="1" rbi="12"/>
26
+ <player id="519240" first="Marc" last="Rzepczynski" num="34" boxname="Rzepczynski" rl="L" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="2" era="3.12"/>
27
+ <player id="519346" first="Eric" last="Thames" num="14" boxname="Thames, E" rl="R" position="LF" status="A" bat_order="2" game_position="LF" avg=".329" hr="3" rbi="9"/>
28
+ <coach position="manager" first="John" last="Farrell" id="114023" num="52"/><coach position="batting_coach" first="Dwayne" last="Murphy" id="119551" num="41"/><coach position="pitching_coach" first="Bruce" last="Walton" id="123899" num="53"/><coach position="first_base_coach" first="Torey" last="Lovullo" id="117950" num="7"/><coach position="third_base_coach" first="Brian" last="Butterfield" id="427047" num="55"/><coach position="bench_coach" first="Don" last="Wakamatsu" id="123798" num="22"/><coach position="bullpen_coach" first="Pat" last="Hentgen" id="115797" num="41"/><coach position="bullpen_catcher" first="Alex" last="Andreopoulos" id="432938" num="61"/><coach position="coach" first="Luis" last="Rivera" id="121248" num="63"/> </team>
29
+ <team type="home" id="BOS" name="Boston Red Sox">
30
+ <player id="120074" first="David" last="Ortiz" num="34" boxname="Ortiz" rl="L" position="D" status="A" bat_order="5" game_position="DH" avg=".301" hr="17" rbi="49"/>
31
+ <player id="123660" first="Jason" last="Varitek" num="33" boxname="Varitek" rl="R" position="C" status="A" avg=".250" hr="5" rbi="17"/>
32
+ <player id="123801" first="Tim" last="Wakefield" num="49" boxname="Wakefield" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="4" losses="3" era="4.82"/>
33
+ <player id="136770" first="J.D." last="Drew" num="7" boxname="Drew, J" rl="R" position="RF" status="A" bat_order="8" game_position="RF" avg=".231" hr="4" rbi="18"/>
34
+ <player id="150021" first="Darnell" last="McDonald" num="54" boxname="McDonald, D" rl="R" position="CF" status="A" avg=".121" hr="2" rbi="6"/>
35
+ <player id="235095" first="Dan" last="Wheeler" num="35" boxname="Wheeler" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="1" losses="1" era="5.92"/>
36
+ <player id="277417" first="Josh" last="Beckett" num="19" boxname="Beckett" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="7" losses="3" era="2.12"/>
37
+ <player id="340192" first="Marco" last="Scutaro" num="10" boxname="Scutaro" rl="R" position="SS" status="A" bat_order="9" game_position="SS" avg=".267" hr="3" rbi="14"/>
38
+ <player id="407793" first="John" last="Lackey" num="41" boxname="Lackey" rl="R" position="P" status="A" bat_order="0" game_position="P" avg=".333" hr="0" rbi="1" wins="5" losses="7" era="6.81"/>
39
+ <player id="408057" first="Bobby" last="Jenks" num="52" boxname="Jenks" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="2" era="6.75"/>
40
+ <player id="408236" first="Adrian" last="Gonzalez" num="28" boxname="Gonzalez, Ad" rl="L" position="1B" status="A" bat_order="3" game_position="1B" avg=".350" hr="16" rbi="74"/>
41
+ <player id="425903" first="Kevin" last="Youkilis" num="20" boxname="Youkilis" rl="R" position="3B" status="A" bat_order="4" game_position="3B" avg=".271" hr="11" rbi="57"/>
42
+ <player id="449097" first="Jonathan" last="Papelbon" num="58" boxname="Papelbon" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="0" era="3.58"/>
43
+ <player id="450300" first="Drew" last="Sutton" num="44" boxname="Sutton" rl="R" position="3B" status="A" avg=".318" hr="0" rbi="7"/>
44
+ <player id="452657" first="Jon" last="Lester" num="31" boxname="Lester" rl="L" position="P" status="A" avg=".000" hr="0" rbi="0" wins="10" losses="4" era="3.43"/>
45
+ <player id="453056" first="Jacoby" last="Ellsbury" num="2" boxname="Ellsbury" rl="L" position="CF" status="A" bat_order="1" game_position="CF" avg=".302" hr="9" rbi="40"/>
46
+ <player id="453192" first="Andrew" last="Miller" num="30" boxname="Miller, A" rl="L" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="0" era="3.06"/>
47
+ <player id="453268" first="Daniel" last="Bard" num="51" boxname="Bard" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="1" losses="4" era="2.25"/>
48
+ <player id="456030" first="Dustin" last="Pedroia" num="15" boxname="Pedroia" rl="R" position="2B" status="A" bat_order="2" game_position="2B" avg=".278" hr="7" rbi="38"/>
49
+ <player id="457454" first="Jarrod" last="Saltalamacchia" num="39" boxname="Saltalamacchia" rl="R" position="C" status="A" bat_order="7" game_position="C" avg=".251" hr="5" rbi="21"/>
50
+ <player id="458006" first="Matt" last="Albers" num="32" boxname="Albers" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="2" losses="3" era="2.97"/>
51
+ <player id="462985" first="Franklin" last="Morales" num="46" boxname="Morales, F" rl="L" position="P" status="A" avg=".000" hr="0" rbi="0" wins="0" losses="1" era="3.86"/>
52
+ <player id="469686" first="Alfredo" last="Aceves" num="91" boxname="Aceves" rl="R" position="P" status="A" avg=".000" hr="0" rbi="0" wins="3" losses="1" era="3.75"/>
53
+ <player id="501605" first="Yamaico" last="Navarro" num="60" boxname="Navarro" rl="R" position="3B" status="A" avg=".500" hr="1" rbi="1"/>
54
+ <player id="502210" first="Josh" last="Reddick" num="16" boxname="Reddick" rl="R" position="RF" status="A" bat_order="6" game_position="LF" avg=".422" hr="1" rbi="10"/>
55
+ <coach position="manager" first="Terry" last="Francona" id="114378" num="47"/><coach position="batting_coach" first="Dave" last="Magadan" id="118132" num="29"/><coach position="pitching_coach" first="Curt" last="Young" id="124689" num="40"/><coach position="first_base_coach" first="Ron" last="Johnson" id="116622" num="50"/><coach position="third_base_coach" first="Tim" last="Bogar" id="111148" num="17"/><coach position="bench_coach" first="DeMarlo" last="Hale" id="427204" num="22"/><coach position="bullpen_coach" first="Gary" last="Tuck" id="492898" num="57"/> </team>
56
+ <umpires><umpire position="home" name="Jerry Layne" id="427299"/><umpire position="first" name="Brian Knight" id="427286"/><umpire position="second" name="Tim McClelland" id="427326"/><umpire position="third" name="Bob Davidson" id="427099"/></umpires></game>
@@ -0,0 +1,12 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class TestCreateMlbGameFromGamedayXMLGame < MiniTest::Unit::TestCase
4
+ def test_create_game_data_from_gameday_xml_game
5
+ GamedayGame.create_from_gameday_xml_game('gid_2011_07_04_tormlb_bosmlb_1')
6
+ assert_equal 1, GamedayGame.all.count
7
+ end
8
+
9
+ def test_fail_gracefully_if_game_does_not_have_data
10
+ refute GamedayGame.create_from_gameday_xml_game('gid_2011_07_04_tormlb_bosmlb_8')
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class TestCreatePlayersFromGamedayXMLGame < MiniTest::Unit::TestCase
4
+ def test_create_players_from_gameday_xml_game
5
+ Athlete.create_from_gameday_xml_game('gid_2011_07_04_tormlb_bosmlb_1')
6
+ assert_equal 50, Athlete.all.count
7
+ end
8
+ end
@@ -1,15 +1,12 @@
1
- require 'minitest/autorun'
2
- require 'greenmonster'
1
+ require './test/test_helper.rb'
3
2
 
4
- class GreenmonsterTest < MiniTest::Unit::TestCase
5
- def setup
6
- end
7
-
3
+ class GreenmonsterTest < MiniTest::Unit::TestCase
8
4
  def test_set_games_folder_location
9
5
  Greenmonster.set_games_folder('./test_greenmonster_folder')
10
6
  assert_equal './test_greenmonster_folder', Greenmonster.games_folder.to_s
11
7
  end
12
8
 
13
9
  def teardown
10
+ Greenmonster.set_games_folder('./test/games')
14
11
  end
15
12
  end
@@ -0,0 +1,7 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class GreenmonsterPlayerTest < MiniTest::Unit::TestCase
4
+ def test_to_s
5
+ assert_equal "Roy Hobbs", Athlete.new({:first => 'Roy', :last => 'Hobbs'}).to_s
6
+ end
7
+ end
@@ -1,5 +1,4 @@
1
- require 'minitest/autorun'
2
- require 'greenmonster'
1
+ require './test/test_helper.rb'
3
2
 
4
3
  class GreenmonsterSpiderTest < MiniTest::Unit::TestCase
5
4
  def setup
@@ -28,6 +27,18 @@ class GreenmonsterSpiderTest < MiniTest::Unit::TestCase
28
27
  assert_equal 400023, Nokogiri::XML(open(paths[:localGameFolder] + 'inning/inning_all.xml')).search("atbat").first.attribute('batter').value.to_i
29
28
  end
30
29
 
30
+ def test_copy_gameday_xml_downloads_file_when_it_has_bad_encoding
31
+ paths = {
32
+ :localGameFolder => "#{@local_test_data_location}/mlb/year_2012/month_04/day_10/gid_2012_04_10_arimlb_sdnmlb_1/",
33
+ :mlbGameFolder => "http://gd2.mlb.com/components/game/mlb/year_2012/month_04/day_10/gid_2012_04_10_arimlb_sdnmlb_1/"
34
+ }
35
+ FileUtils.mkdir_p paths[:localGameFolder] + 'inning'
36
+
37
+ Greenmonster::Spider.copy_gameday_xml('inning_all.xml',paths)
38
+
39
+ assert_equal 11, Nokogiri::XML(open(paths[:localGameFolder] + '/inning/inning_all.xml')).search("inning").count
40
+ end
41
+
31
42
  def test_pull_day
32
43
  Greenmonster::Spider.pull_day({:print_games => false, :games_folder => @local_test_data_location, :date => Date.new(2011,6,7)})
33
44
 
@@ -51,37 +62,33 @@ class GreenmonsterSpiderTest < MiniTest::Unit::TestCase
51
62
  end
52
63
 
53
64
  def test_pull_non_mlb_sport_code_games
54
- Greenmonster::Spider.pull_day({:sport_code => 'aaa', :print_games => false, :games_folder => @local_test_data_location, :date => Date.new(2011,9,1)})
65
+ Greenmonster::Spider.pull_day({:sport_code => 'asx', :print_games => false, :games_folder => @local_test_data_location, :date => Date.new(2011,9,12)})
55
66
 
56
- assert_equal 13, Dir.entries(@local_test_data_location + '/aaa/year_2011/month_09/day_01/').count
67
+ assert_equal 4, Dir.entries(@local_test_data_location + '/asx/year_2011/month_09/day_12/').count
57
68
  %w(linescore.xml boxscore.xml players.xml eventLog.xml inning).each do |f|
58
- assert Dir.entries(@local_test_data_location + '/aaa/year_2011/month_09/day_01/gid_2011_09_01_albaaa_mrbaaa_1/').include? f
69
+ assert Dir.entries(@local_test_data_location + '/asx/year_2011/month_09/day_12/gid_2011_09_12_staasx_aubasx_1/').include? f
59
70
  end
60
71
  end
61
72
 
62
73
  def test_pull_games_prior_to_2008
63
74
  Greenmonster::Spider.pull_game('gid_2007_04_15_detmlb_tormlb_1', {:games_folder => @local_test_data_location, :print_games => false})
64
-
65
75
  assert_equal 12, Dir.entries(@local_test_data_location + '/mlb/year_2007/month_04/day_15/gid_2007_04_15_detmlb_tormlb_1/inning/').count
66
76
  end
67
77
 
68
78
  def test_pull_all_sport_codes_for_day
69
- Greenmonster::Spider.pull_day({:all_sport_codes => true, :print_games => false, :games_folder => @local_test_data_location, :date => Date.new(2011,7,1)})
70
-
71
- assert_equal 9, Dir.entries(@local_test_data_location).count
79
+ Greenmonster::Spider.pull_day({:all_sport_codes => true, :print_games => false, :games_folder => @local_test_data_location, :date => Date.new(2011,9,13)})
80
+ assert_equal 8, Dir.entries(@local_test_data_location).count
72
81
  end
73
82
 
74
83
  def test_pull_days
75
- Greenmonster::Spider.pull_days((Date.new(2011,8,4)..Date.new(2011,8,5)), {:print_games => false, :games_folder => @local_test_data_location})
76
-
77
- assert_equal 4, Dir.entries(@local_test_data_location + '/mlb/year_2011/month_08/').count
78
- assert_equal 17, Dir.entries(@local_test_data_location + '/mlb/year_2011/month_08/day_05').count
84
+ Greenmonster::Spider.pull_days((Date.new(2011,10,9)..Date.new(2011,10,10)), {:print_games => false, :games_folder => @local_test_data_location})
85
+ assert_equal 4, Dir.entries(@local_test_data_location + '/mlb/year_2011/month_10/').count
86
+ assert_equal 6, Dir.entries(@local_test_data_location + '/mlb/year_2011/month_10/day_09').count
79
87
  end
80
88
 
81
89
  def test_pull_day_with_default_folder_location
82
- Greenmonster.set_games_folder(@local_test_data_location)
90
+ Greenmonster.set_games_folder @local_test_data_location
83
91
  Greenmonster::Spider.pull_day({:date => Date.new(2011,7,4), :print_games => false})
84
-
85
92
  assert_equal 288186, Nokogiri::XML(open(@local_test_data_location + '/mlb/year_2011/month_07/day_04/gid_2011_07_04_tormlb_bosmlb_1/boxscore.xml')).search('boxscore').first.attribute('game_pk').value.to_i
86
93
  end
87
94
 
@@ -97,17 +104,16 @@ class GreenmonsterSpiderTest < MiniTest::Unit::TestCase
97
104
 
98
105
  def test_local_file_not_created_if_remote_file_does_not_exist
99
106
  Greenmonster::Spider.pull_game('gid_2011_07_01_xxxmlb_yyymlb_1', {:games_folder => @local_test_data_location, :print_games => false})
100
-
101
107
  assert_equal 3, Dir.entries(@local_test_data_location + '/mlb/year_2011/month_07/day_01/gid_2011_07_01_xxxmlb_yyymlb_1').count
102
108
  end
103
109
 
104
110
  def test_sport_code_argument_as_array
105
- Greenmonster::Spider.pull_day({:date => Date.new(2011,8,1), :sport_code => ['mlb','rok'], :print_games => false, :games_folder => @local_test_data_location})
106
-
111
+ Greenmonster::Spider.pull_day({:date => Date.new(2011,9,16), :sport_code => ['mlb','rok'], :print_games => false, :games_folder => @local_test_data_location})
107
112
  assert_equal 4, Dir.entries(@local_test_data_location).count
108
113
  end
109
114
 
110
115
  def teardown
111
116
  FileUtils.remove_dir @local_test_data_location
117
+ Greenmonster.set_games_folder('./test/games')
112
118
  end
113
119
  end
@@ -0,0 +1,31 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class GreenmonsterTraversalTest < MiniTest::Unit::TestCase
4
+ def test_traverse_dates_across_range
5
+ assert_equal (Date.new(2012,4,15)..Date.new(2012,4,30)), Greenmonster.traverse_dates(Date.new(2012,4,15)..Date.new(2012,4,30)) {|g,a| g}
6
+ end
7
+
8
+ def test_traverse_dates_with_no_range
9
+ assert_block do
10
+ Greenmonster.traverse_dates do |d,a|
11
+ d == Date.today
12
+ end
13
+ end
14
+ end
15
+
16
+ def test_traverse_folders_for_date
17
+ assert_block do
18
+ Greenmonster.traverse_folders_for_date(Date.new(2012,3,27), {:true_test => true, :false_test => false}) do |g,a|
19
+ g == 'gid_2012_03_27_aaamlb_aabmlb_1' and a == {:true_test => true, :false_test => false}
20
+ end
21
+ end
22
+ end
23
+
24
+ def test_traverse_folders_for_non_mlb_sport_code
25
+ assert_block do
26
+ Greenmonster.traverse_folders_for_date(Date.new(2012,3,27), {:sport_code => 'tst'}) do |g,a|
27
+ g == 'gid_2012_03_27_aaatst_aabtst_1'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,78 @@
1
+ require "sqlite3"
2
+ require "supermodel"
3
+ require 'minitest/autorun'
4
+ require 'greenmonster'
5
+
6
+ ActiveRecord::Base.establish_connection(
7
+ :adapter => 'sqlite3',
8
+ :database => './test/test.db'
9
+ )
10
+
11
+ class CreateSchema < ActiveRecord::Migration
12
+ def self.up
13
+ create_table :athletes, :force => true do |t|
14
+ t.string :first
15
+ t.string :last
16
+ end
17
+
18
+ create_table :gameday_games, :force => true do |t|
19
+ t.date "date"
20
+ t.datetime "created_at"
21
+ t.datetime "updated_at"
22
+ t.string "away_division"
23
+ t.string "home_division"
24
+ t.string "game_id"
25
+ t.string "game_location"
26
+ t.integer "game_num"
27
+ t.integer "game_pk"
28
+ t.string "game_status", :limit => 2
29
+ t.datetime "game_time"
30
+ t.boolean "game_time_is_tbd"
31
+ t.integer "game_time_offset_eastern"
32
+ t.integer "game_time_offset_local"
33
+ t.string "game_type", :limit => 1
34
+ t.string "game_venue"
35
+ t.boolean "is_suspension_resumption"
36
+ t.boolean "mlbtv"
37
+ t.string "preview"
38
+ t.integer "resumptionTime", :limit => 8
39
+ t.datetime "scheduledTime"
40
+ t.string "sport_code", :limit => 3
41
+ t.integer "venue_id"
42
+ t.string "video_uri"
43
+ t.string "wrapup"
44
+ t.boolean "game_dh"
45
+ t.integer "away_team_id"
46
+ t.integer "home_team_id"
47
+ t.integer "away_league_id"
48
+ t.integer "home_league_id"
49
+ t.string "away_sport_code"
50
+ t.string "home_sport_code"
51
+ t.integer "last_event_processed"
52
+ end
53
+
54
+ create_table :probable_pitchers, :force => true do |t|
55
+ t.integer "game_pk"
56
+ t.date "date"
57
+ t.integer "player_id"
58
+ t.string "side"
59
+ end
60
+ end
61
+ end
62
+
63
+ CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
64
+
65
+ class Athlete < ActiveRecord::Base
66
+ include Greenmonster::Player
67
+ end
68
+
69
+ class GamedayGame < ActiveRecord::Base
70
+ include Greenmonster::MlbGame
71
+ end
72
+
73
+ class ProbablePitcher < ActiveRecord::Base
74
+ include Greenmonster::MlbProbablePitcher
75
+ end
76
+
77
+ Greenmonster.set_games_folder('./test/games')
78
+ FileUtils.mkdir_p Greenmonster.games_folder
@@ -0,0 +1,12 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class TestLineScore < MiniTest::Unit::TestCase
4
+ def test_load_line_score
5
+ linescore = Greenmonster::Parser.load_line_score('gid_2011_07_04_tormlb_bosmlb_1')
6
+ assert_equal 288186, linescore.attribute('game_pk').value.to_i
7
+ end
8
+
9
+ def test_load_line_score_returns_false_on_failure
10
+ refute Greenmonster::Parser.load_line_score('gid_2011_07_04_tormlb_bosmlb_7')
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class ParseMlbProbablePitchersFromLinescoreDataTest < MiniTest::Unit::TestCase
4
+ def test_create_probable_pitcher
5
+ node = nil
6
+
7
+ a = ProbablePitcher.create_from_gameday_xml(node)
8
+
9
+ assert_equal ProbablePitcher, a.class
10
+ assert_equal 000000, a.player_id
11
+ assert_equal 'a', a.side
12
+ assert_equal 111111, a.game_pk
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class TestParsePlayersFromGamedayXMLFiles < MiniTest::Unit::TestCase
4
+ def test_parse_players_from_game
5
+ players = []
6
+ Greenmonster::Parser.extract_players_from_game('gid_2011_07_04_tormlb_bosmlb_1') do |p|
7
+ players << p
8
+ end
9
+ players.sort!{|x,y| x[:id] <=> y[:id]}
10
+
11
+ assert_equal 50, players.count
12
+ end
13
+
14
+ def test_player_ids_stored_as_integers
15
+ players = []
16
+ Greenmonster::Parser.extract_players_from_game('gid_2011_07_04_tormlb_bosmlb_1') do |p|
17
+ players << p
18
+ end
19
+ assert players.first[:id].kind_of? Integer
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class TestUpdateMlbGameWithLinescore < MiniTest::Unit::TestCase
4
+ def test_update_with_linescore_data
5
+ g = GamedayGame.new
6
+ g.update_with_line_score_data(Greenmonster::Parser.load_line_score('gid_2011_07_04_tormlb_bosmlb_1'))
7
+
8
+ assert_equal 288186, g.game_pk
9
+ assert_equal 111, g.home_team_id
10
+ assert_equal 141, g.away_team_id
11
+ assert_equal 1, g.game_num
12
+ assert_equal '20110704tormlbbosmlb1', g.game_id
13
+ assert_equal Date.new(2011,7,4), g.date
14
+ assert_equal 'F', g.game_status
15
+ assert_equal Time.new(2011,7,4,13,35), g.game_time
16
+ assert_equal 'R', g.game_type
17
+ assert_equal 'Fenway Park', g.game_venue
18
+ assert_equal 3, g.venue_id
19
+ assert_equal 'mlb', g.sport_code
20
+ assert_equal 103, g.home_league_id
21
+ assert_equal 103, g.away_league_id
22
+ end
23
+ end