X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FOdds.hs;h=67ddbd4c2b52c5ac234abf0e1180a99c487a1f67;hb=49d528dc6b0a7b79ae17990872fdd7f58b80abc7;hp=51ef0cabc5a003475d5de4e4a667c832ad70ed4c;hpb=df558b9603fa5156cf64de856f0be89f396c6deb;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Odds.hs b/src/TSN/XML/Odds.hs index 51ef0ca..67ddbd4 100644 --- a/src/TSN/XML/Odds.hs +++ b/src/TSN/XML/Odds.hs @@ -27,7 +27,7 @@ where -- System imports. import Control.Monad ( forM_, join ) -import Data.Time ( UTCTime ) +import Data.Time ( UTCTime(..) ) import Data.Tuple.Curry ( uncurryN ) import Database.Groundhog ( (=.), @@ -62,7 +62,7 @@ import Text.XML.HXT.Core ( import TSN.Codegen ( tsn_codegen_config ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) -import TSN.Picklers ( xp_date, xp_team_id, xp_time ) +import TSN.Picklers ( xp_date, xp_time ) import TSN.XmlImport ( XmlImport(..) ) import Xml ( FromXml(..), pickle_unpickle, unpickleable ) @@ -124,7 +124,12 @@ instance XmlImport OddsGameCasinoXml -- data OddsGameTeam = OddsGameTeam { - db_team_id :: String, -- ^ The home/away team IDs are 3 characters + db_team_id :: String, -- ^ The home/away team IDs are + -- three characters but Postgres + -- imposes no performance penalty + -- on lengthless text fields, so + -- we ignore the probable upper + -- bound of three characters. db_abbr :: String, db_team_name :: String } deriving (Eq, Show) @@ -134,7 +139,14 @@ data OddsGameTeam = -- data OddsGameHomeTeamXml = OddsGameHomeTeamXml { - xml_home_team_id :: String, -- ^ These are three-character IDs. + xml_home_team_id :: String, -- ^ The home/away team IDs + -- are three characters but + -- Postgres imposes no + -- performance penalty on + -- lengthless text fields, + -- so we ignore the probable + -- upper bound of three + -- characters. xml_home_rotation_number :: Int, xml_home_abbr :: String, xml_home_team_name :: String, @@ -168,7 +180,12 @@ instance XmlImport OddsGameHomeTeamXml where -- data OddsGameAwayTeamXml = OddsGameAwayTeamXml { - xml_away_team_id :: String, -- ^ These are 3 character IDs. + xml_away_team_id :: String, -- ^ The home/away team IDs are + -- three characters but Postgres + -- imposes no performance penalty + -- on lengthless text fields, so + -- we ignore the probable upper + -- bound of three characters xml_away_rotation_number :: Int, xml_away_abbr :: String, xml_away_team_name :: String, @@ -240,8 +257,7 @@ data OddsGameLine = data OddsGame = OddsGame { db_game_id :: Int, - db_game_date :: UTCTime, - db_game_time :: UTCTime, + db_game_time :: UTCTime, -- ^ Contains both the date and time. db_game_away_team_rotation_number :: Int, db_game_home_team_rotation_number :: Int } deriving (Eq, Show) @@ -251,8 +267,8 @@ data OddsGame = data OddsGameXml = OddsGameXml { xml_game_id :: Int, - xml_game_date :: UTCTime, - xml_game_time :: UTCTime, + xml_game_date :: UTCTime, -- ^ Contains only the date + xml_game_time :: UTCTime, -- ^ Contains only the time xml_game_away_team :: OddsGameAwayTeamXml, xml_game_home_team :: OddsGameHomeTeamXml, xml_game_over_under :: OddsGameOverUnderXml } @@ -278,10 +294,14 @@ instance FromXml OddsGameXml where from_xml OddsGameXml{..} = OddsGame { db_game_id = xml_game_id, - db_game_date = xml_game_date, - db_game_time = xml_game_time, + + db_game_time = UTCTime + (utctDay xml_game_date) -- Take the day part from one, + (utctDayTime xml_game_time), -- the time from the other. + db_game_away_team_rotation_number = (xml_away_rotation_number xml_game_away_team), + db_game_home_team_rotation_number = (xml_home_rotation_number xml_game_home_team) } @@ -297,7 +317,11 @@ data Odds = Odds { db_sport :: String, db_title :: String, - db_line_time :: String } + db_line_time :: String -- ^ We don't parse these as a 'UTCTime' + -- because their timezones are ambiguous + -- (and the date is less than useful when + -- it might be off by an hour). + } -- | Map 'Odds' to their children 'OddsGame's. @@ -385,9 +409,6 @@ mkPersist tsn_codegen_config [groundhog| dbName: odds_games_teams constructors: - name: OddsGameTeam - fields: - - name: db_team_id - type: varchar(3) # We've only seen 3, so far... uniques: - name: unique_odds_games_team type: constraint @@ -413,11 +434,27 @@ mkPersist tsn_codegen_config [groundhog| fields: - name: odds_OddsGame0 # Default created by mkNormalFieldName dbName: odds_id + reference: + onDelete: cascade - name: odds_OddsGame1 # Default created by mkNormalFieldName dbName: odds_games_id + reference: + onDelete: cascade - entity: OddsGame_OddsGameTeam dbName: odds_games__odds_games_teams + constructors: + - name: OddsGame_OddsGameTeam + fields: + - name: ogogt_odds_games_id + reference: + onDelete: cascade + - name: ogogt_away_team_id + reference: + onDelete: cascade + - name: ogogt_home_team_id + reference: + onDelete: cascade |] instance DbImport Message where @@ -537,7 +574,7 @@ pickle_home_team = xpElem "HomeTeam" $ xpWrap (from_tuple, to_tuple) $ xp5Tuple - (xpElem "HomeTeamID" xp_team_id) + (xpElem "HomeTeamID" xpText) (xpElem "HomeRotationNumber" xpInt) (xpElem "HomeAbbr" xpText) (xpElem "HomeTeamName" xpText) @@ -559,7 +596,7 @@ pickle_away_team = xpElem "AwayTeam" $ xpWrap (from_tuple, to_tuple) $ xp5Tuple - (xpElem "AwayTeamID" xp_team_id) + (xpElem "AwayTeamID" xpText) (xpElem "AwayRotationNumber" xpInt) (xpElem "AwayAbbr" xpText) (xpElem "AwayTeamName" xpText) @@ -652,7 +689,7 @@ odds_tests = -- | If we unpickle something and then pickle it, we should wind up --- with the same thing we started with. WARNING: succeess of this +-- with the same thing we started with. WARNING: success of this -- test does not mean that unpickling succeeded. -- test_pickle_of_unpickle_is_identity :: TestTree