X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FOdds.hs;h=3aef4f1d8503329c06c644c92cd1026649a6fb5b;hb=71e4436c45b1694fbc550d5cfc2a0cde216610f6;hp=eb017d8131678e2bebd29621bdf4d83a9ebd6c6d;hpb=6ed05f33ffaa8b000d36ab3f5ab62eed4022d27a;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Odds.hs b/src/TSN/XML/Odds.hs index eb017d8..3aef4f1 100644 --- a/src/TSN/XML/Odds.hs +++ b/src/TSN/XML/Odds.hs @@ -51,6 +51,7 @@ import Text.XML.HXT.Core ( import TSN.Codegen ( tsn_codegen_config ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) +import TSN.Picklers ( xp_team_id ) import TSN.XmlImport ( XmlImport(..) ) import Xml ( FromXml(..), pickle_unpickle, unpickleable ) @@ -102,7 +103,7 @@ instance XmlImport OddsGameCasinoXml data OddsGameHomeTeamXml = OddsGameHomeTeamXml { - xml_home_team_id :: Int, + xml_home_team_id :: String, -- ^ These are three-character IDs. xml_home_rotation_number :: Int, xml_home_abbr :: String, xml_home_team_name :: String, @@ -121,7 +122,7 @@ instance XmlImport OddsGameHomeTeamXml where data OddsGameTeam = OddsGameTeam { - db_team_id :: Int, + db_team_id :: String, -- ^ The home/away team IDs are 3 characters db_abbr :: String, db_team_name :: String } deriving (Eq, Show) @@ -136,7 +137,7 @@ data OddsGame_OddsGameTeam = data OddsGameAwayTeamXml = OddsGameAwayTeamXml { - xml_away_team_id :: Int, + xml_away_team_id :: String, -- ^ These are 3 character IDs. xml_away_rotation_number :: Int, xml_away_abbr :: String, xml_away_team_name :: String, @@ -297,6 +298,9 @@ mkPersist tsn_codegen_config [groundhog| dbName: odds_games_teams constructors: - name: OddsGameTeam + fields: + - name: db_team_id + type: varchar(3) uniques: - name: unique_odds_games_team type: constraint @@ -430,7 +434,7 @@ pickle_home_team = xpElem "HomeTeam" $ xpWrap (from_tuple, to_tuple) $ xp5Tuple - (xpElem "HomeTeamID" xpInt) + (xpElem "HomeTeamID" xp_team_id) (xpElem "HomeRotationNumber" xpInt) (xpElem "HomeAbbr" xpText) (xpElem "HomeTeamName" xpText) @@ -451,7 +455,7 @@ pickle_away_team = xpElem "AwayTeam" $ xpWrap (from_tuple, to_tuple) $ xp5Tuple - (xpElem "AwayTeamID" xpInt) + (xpElem "AwayTeamID" xp_team_id) (xpElem "AwayRotationNumber" xpInt) (xpElem "AwayAbbr" xpText) (xpElem "AwayTeamName" xpText) @@ -541,8 +545,14 @@ test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests" [ check "pickle composed with unpickle is the identity" "test/xml/Odds_XML.xml", + check "pickle composed with unpickle is the identity (non-int team_id)" + "test/xml/Odds_XML-noninteger-team-id.xml", + check "pickle composed with unpickle is the identity (positive(+) line)" - "test/xml/Odds_XML-positive-line.xml" ] + "test/xml/Odds_XML-positive-line.xml", + + check "pickle composed with unpickle is the identity (large file)" + "test/xml/Odds_XML-largefile.xml" ] where check desc path = testCase desc $ do (expected, actual) <- pickle_unpickle pickle_message path @@ -554,8 +564,14 @@ test_unpickle_succeeds = testGroup "unpickle tests" [ check "unpickling succeeds" "test/xml/Odds_XML.xml", + check "unpickling succeeds (non-int team_id)" + "test/xml/Odds_XML-noninteger-team-id.xml", + check "unpickling succeeds (positive(+) line)" - "test/xml/Odds_XML-positive-line.xml" ] + "test/xml/Odds_XML-positive-line.xml", + + check "unpickling succeeds (large file)" + "test/xml/Odds_XML-largefile.xml" ] where check desc path = testCase desc $ do actual <- unpickleable path pickle_message