From 7e65dfba04f3cf7cc903f0e2a098d5461a532df1 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 14 Jan 2014 20:47:22 -0500 Subject: [PATCH] Don't bother with the three-character limit on team_id fields; Postgres doesn't care. --- src/TSN/Picklers.hs | 19 ------------------ src/TSN/XML/InjuriesDetail.hs | 19 +++++++++--------- src/TSN/XML/Odds.hs | 38 ++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/TSN/Picklers.hs b/src/TSN/Picklers.hs index d87139b..054d0f6 100644 --- a/src/TSN/Picklers.hs +++ b/src/TSN/Picklers.hs @@ -3,7 +3,6 @@ -- module TSN.Picklers ( xp_date, - xp_team_id, xp_time ) where @@ -46,21 +45,3 @@ xp_time = from_time :: UTCTime -> String from_time = formatTime defaultTimeLocale format - - --- | Parse a team_id. These are (so far!) three characters long, and --- not necessarily numeric. For simplicity, we return a 'String' --- rather than e.g. a @(Char, Char, Char)@. But unpickling will fail --- if the team_id is longer than three characters. --- -xp_team_id :: PU String -xp_team_id = - (to_team_id, from_team_id) `xpWrapMaybe` xpText - where - to_team_id :: String -> Maybe String - to_team_id s - | length s <= 3 = Just s - | otherwise = Nothing - - from_team_id :: String -> String - from_team_id = id diff --git a/src/TSN/XML/InjuriesDetail.hs b/src/TSN/XML/InjuriesDetail.hs index a225cbf..d857bda 100644 --- a/src/TSN/XML/InjuriesDetail.hs +++ b/src/TSN/XML/InjuriesDetail.hs @@ -49,7 +49,7 @@ import Text.XML.HXT.Core ( xpWrap ) -- Local imports. -import TSN.Picklers( xp_date, xp_team_id ) +import TSN.Picklers( xp_date ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.XmlImport ( XmlImport(..) ) import Xml ( FromXml(..), pickle_unpickle, unpickleable ) @@ -60,8 +60,12 @@ import Xml ( FromXml(..), pickle_unpickle, unpickleable ) -- data PlayerListing = PlayerListing { - team_id :: String, -- ^ TeamIDs are (apparently) three characters long - -- and not necessarily numeric. + team_id :: String, -- ^ TeamIDs are (apparently) three + -- characters long and not necessarily + -- numeric. Postgres imposes no performance + -- penalty on a lengthless text field, + -- so we ignore the likely upper bound of + -- three characters. player_id :: Int, date :: UTCTime, pos :: String, @@ -128,11 +132,6 @@ instance DbImport Message where mkPersist defaultCodegenConfig [groundhog| - entity: PlayerListing dbName: injuries_detail_player_listings - constructors: - - name: PlayerListing - fields: - - name: team_id - type: varchar(3) # We've only seen 3... so far. |] @@ -142,7 +141,7 @@ pickle_player_listing :: PU PlayerListing pickle_player_listing = xpElem "PlayerListing" $ xpWrap (from_tuple, to_tuple) $ - xp10Tuple (xpElem "TeamID" xp_team_id) + xp10Tuple (xpElem "TeamID" xpText) (xpElem "PlayerID" xpInt) (xpElem "Date" xp_date) (xpElem "Pos" xpText) @@ -172,7 +171,7 @@ pickle_listing :: PU Listing pickle_listing = xpElem "Listing" $ xpWrap (from_tuple, to_tuple) $ - xpTriple (xpElem "TeamID" xp_team_id) + xpTriple (xpElem "TeamID" xpText) (xpElem "FullName" xpText) (xpList pickle_player_listing) where diff --git a/src/TSN/XML/Odds.hs b/src/TSN/XML/Odds.hs index 51ef0ca..467dbcf 100644 --- a/src/TSN/XML/Odds.hs +++ b/src/TSN/XML/Odds.hs @@ -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, @@ -297,7 +314,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 +406,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 @@ -537,7 +555,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 +577,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) -- 2.44.2