import Test.Tasty.HUnit ( (@?=), testCase )
import Text.XML.HXT.Core (
PU,
+ xp4Tuple,
xp11Tuple,
xp23Tuple,
xpAttr,
data MLBBoxScoreTeamSummaryXml = MLBBoxScoreTeamSummaryXml deriving (Eq, Show)
data MLBBoxScoreGameBreakdown = MLBBoxScoreGameBreakdown
-data MLBBoxScoreGameBreakdownXml = MLBBoxScoreGameBreakdownXml
+data MLBBoxScoreGameBreakdownXml =
+ MLBBoxScoreGameBreakdownXml {
+ xml_away_team :: MLBBoxScoreGameBreakdownTeamXml,
+ xml_home_team :: MLBBoxScoreGameBreakdownTeamXml }
deriving (Eq, Show)
data MLBBoxScoreHomerunStats = MLBBoxScoreHomerunStats
data MLBBoxScoreMiscellaneousGameInfoXml = MLBBoxScoreMiscellaneousGameInfoXml
deriving (Eq, Show)
+data MLBBoxScoreGameBreakdownTeamXml =
+ MLBBoxScoreGameBreakdownTeamXml {
+ xml_runs_by_innings :: [MLBBoxScoreRunsByInningsXml],
+ xml_runs :: Int,
+ xml_hits :: Int,
+ xml_errors :: Int }
+ deriving (Eq, Show)
+
+data MLBBoxScoreRunsByInningsXml =
+ MLBBoxScoreRunsByInningsXml {
+ xml_runs_by_innings_inning_number :: Int,
+ xml_runs_by_innings_runs :: Int }
+ deriving (Eq, Show)
+
+
data MLBBoxScoreMiscPitchingStats = MLBBoxScoreMiscPitchingStats
-data MLBBoxScoreMiscPitchingStatsXml = MLBBoxScoreMiscPitchingStatsXml
+data MLBBoxScoreMiscPitchingStatsXml =
+ MLBBoxScoreMiscPitchingStatsXml {
+ xml_wild_pitches :: Maybe Int,
+ xml_intentional_walks :: [MLBBoxScoreMiscPitchingStatsIntentionalWalkXml],
+ xml_hits_by_pitch :: [MLBBoxScoreMiscPitchingStatsHitByPitchXml] }
+ deriving (Eq, Show)
+
+data MLBBoxScoreMiscPitchingStatsIntentionalWalkXml =
+ MLBBoxScoreMiscPitchingStatsIntentionalWalkXml {
+ xml_iw_batter_id :: Int,
+ xml_iw_pitcher_id :: Int,
+ xml_iw_number_of_times_walked :: Int }
+ deriving (Eq, Show)
+
+data MLBBoxScoreMiscPitchingStatsHitByPitchXml =
+ MLBBoxScoreMiscPitchingStatsHitByPitchXml {
+ xml_hbp_batter_id :: Int,
+ xml_hbp_pitcher_id :: Int,
+ xml_hbp_number_of_times_hit :: Int }
deriving (Eq, Show)
--
pickle_game_breakdown :: PU MLBBoxScoreGameBreakdownXml
pickle_game_breakdown =
- xpElem "Game_Breakdown" $ xpWrap (from_tuple, to_tuple) $ xpUnit
+ xpElem "Game_Breakdown" $
+ xpWrap (from_tuple, to_tuple) $
+ xpPair pickle_away_team
+ pickle_home_team
where
- from_tuple _ = MLBBoxScoreGameBreakdownXml
- to_tuple _ = ()
+ from_tuple = uncurry MLBBoxScoreGameBreakdownXml
+ to_tuple MLBBoxScoreGameBreakdownXml{..} = (xml_away_team, xml_home_team)
+
+
+pickle_runs_by_innings :: PU MLBBoxScoreRunsByInningsXml
+pickle_runs_by_innings =
+ xpElem "Runs_By_Innings" $
+ xpWrap (from_tuple, to_tuple) $
+ xpPair (xpAttr "Inning" xpInt)
+ xpInt
+ where
+ from_tuple = uncurry MLBBoxScoreRunsByInningsXml
+ to_tuple MLBBoxScoreRunsByInningsXml{..} =
+ (xml_runs_by_innings_inning_number, xml_runs_by_innings_runs)
+
+pickle_team =
+ xpWrap (from_tuple, to_tuple) $
+ xp4Tuple (xpList pickle_runs_by_innings)
+ (xpElem "Runs" xpInt)
+ (xpElem "Hits" xpInt)
+ (xpElem "Errors" xpInt)
+ where
+ from_tuple = uncurryN MLBBoxScoreGameBreakdownTeamXml
+ to_tuple MLBBoxScoreGameBreakdownTeamXml{..} =
+ (xml_runs_by_innings, xml_runs, xml_hits, xml_errors)
+
+pickle_away_team :: PU MLBBoxScoreGameBreakdownTeamXml
+pickle_away_team =
+ xpElem "AwayTeam" pickle_team
+
+pickle_home_team :: PU MLBBoxScoreGameBreakdownTeamXml
+pickle_home_team =
+ xpElem "HomeTeam" pickle_team
pickle_homerun_stats :: PU (Maybe MLBBoxScoreHomerunStatsXml)
pickle_homerun_stats =
from_tuple _ = MLBBoxScoreHomerunStatsXml
to_tuple _ = ()
+
pickle_misc_pitching_stats :: PU MLBBoxScoreMiscPitchingStatsXml
pickle_misc_pitching_stats =
- xpElem "Misc_Pitching_Stats" $ xpWrap (from_tuple, to_tuple) $ xpUnit
+ xpElem "Misc_Pitching_Stats" $
+ xpWrap (from_tuple, to_tuple) $
+ xpTriple (xpOption $ xpElem "Wild_Pitches" xpInt)
+ pickle_intentional_walks
+ pickle_hits_by_pitch
where
- from_tuple _ = MLBBoxScoreMiscPitchingStatsXml
- to_tuple _ = ()
+ from_tuple = uncurryN MLBBoxScoreMiscPitchingStatsXml
+ to_tuple MLBBoxScoreMiscPitchingStatsXml{..} =
+ (xml_wild_pitches, xml_intentional_walks, xml_hits_by_pitch)
+
+
+pickle_intentional_walks :: PU [MLBBoxScoreMiscPitchingStatsIntentionalWalkXml]
+pickle_intentional_walks =
+ xpElem "Intentional_Walks" $ xpList $ xpElem "IW_Listing" $
+ xpWrap (from_tuple, to_tuple) $
+ xpTriple (xpElem "IW_Batter_ID" xpInt)
+ (xpElem "IW_Pitcher_ID" xpInt)
+ (xpElem "IW_Number_Of_Times_Walked" xpInt)
+ where
+ from_tuple = uncurryN MLBBoxScoreMiscPitchingStatsIntentionalWalkXml
+ to_tuple MLBBoxScoreMiscPitchingStatsIntentionalWalkXml{..} =
+ (xml_iw_batter_id, xml_iw_pitcher_id, xml_iw_number_of_times_walked)
+
+
+pickle_hits_by_pitch :: PU [MLBBoxScoreMiscPitchingStatsHitByPitchXml]
+pickle_hits_by_pitch =
+ xpElem "Hit_By_Pitch" $ xpList $ xpElem "HBP_Listing" $
+ xpWrap (from_tuple, to_tuple) $
+ xpTriple (xpElem "HBP_Batter_ID" xpInt)
+ (xpElem "HBP_Pitcher_ID" xpInt)
+ (xpElem "HBP_Number_Of_Times_Hit" xpInt)
+ where
+ from_tuple = uncurryN MLBBoxScoreMiscPitchingStatsHitByPitchXml
+ to_tuple MLBBoxScoreMiscPitchingStatsHitByPitchXml{..} =
+ (xml_hbp_batter_id, xml_hbp_pitcher_id, xml_hbp_number_of_times_hit)
+
+
pickle_miscellaneous_game_info :: PU MLBBoxScoreMiscellaneousGameInfoXml
pickle_miscellaneous_game_info =