import TSN.Codegen (
tsn_codegen_config )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
-import TSN.Picklers ( xp_date_padded, xp_time, xp_time_stamp )
+import TSN.Picklers ( xp_date_padded, xp_tba_time, xp_time_stamp )
import TSN.Team ( FromXmlFkTeams(..), Team(..) )
import TSN.XmlImport ( XmlImport(..), XmlImportFkTeams(..) )
import Xml (
db_away_team_id :: DefaultKey Team,
db_home_team_id :: DefaultKey Team,
db_game_id :: Int,
- db_game_time :: UTCTime, -- ^ Contains both the date and time.
+ db_game_time :: Maybe UTCTime, -- ^ Contains both the date and time.
db_away_team_rotation_number :: Maybe Int,
db_home_team_rotation_number :: Maybe Int,
db_away_team_starter_id :: Maybe Int,
OddsGameXml {
xml_game_id :: Int,
xml_game_date :: UTCTime, -- ^ Contains only the date
- xml_game_time :: UTCTime, -- ^ Contains only the time
+ xml_game_time :: Maybe UTCTime, -- ^ Contains only the time
xml_away_team :: OddsGameTeamXml,
xml_home_team :: OddsGameTeamXml,
xml_over_under :: OddsGameOverUnderXml }
db_home_team_id = fk_home,
db_game_id = xml_game_id,
- 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_time = make_game_time xml_game_date xml_game_time,
db_away_team_rotation_number =
(xml_team_rotation_number xml_away_team),
-- so we combine the two maybes with join.
db_home_team_starter_name = join
(xml_starter_name <$> xml_team_starter xml_home_team) }
+ where
+ -- | Construct the database game time from the XML \<Game_Date\>
+ -- and \<Game_Time\> elements. The \<Game_Time\> elements
+ -- sometimes have a value of \"TBA\"; in that case, we don't
+ -- want to pretend that we know the time by setting it to
+ -- e.g. midnight, so instead we make the entire date/time
+ -- Nothing.
+ make_game_time :: UTCTime -> Maybe UTCTime -> Maybe UTCTime
+ make_game_time _ Nothing = Nothing
+ make_game_time d (Just t) = Just $ UTCTime (utctDay d) (utctDayTime t)
-- | This lets us insert the XML representation 'OddsGameXml' directly.
xp6Tuple
(xpElem "GameID" xpInt)
(xpElem "Game_Date" xp_date_padded)
- (xpElem "Game_Time" xp_time)
+ (xpElem "Game_Time" xp_tba_time)
pickle_away_team
pickle_home_team
pickle_over_under
"test/xml/Odds_XML-league-name.xml",
check "pickle composed with unpickle is the identity (missing starters)"
- "test/xml/Odds_XML-missing-starters.xml" ]
+ "test/xml/Odds_XML-missing-starters.xml",
+
+ check "pickle composed with unpickle is the identity (TBA game time)"
+ "test/xml/Odds_XML-tba-game-time.xml"]
where
check desc path = testCase desc $ do
(expected, actual) <- pickle_unpickle pickle_message path
"test/xml/Odds_XML-league-name.xml",
check "unpickling succeeds (missing starters)"
- "test/xml/Odds_XML-missing-starters.xml" ]
+ "test/xml/Odds_XML-missing-starters.xml",
+
+ check "unpickling succeeds (TBA game time)"
+ "test/xml/Odds_XML-tba-game-time.xml" ]
where
check desc path = testCase desc $ do
actual <- unpickleable path pickle_message
check "deleting odds deleted its children (missing starters)"
"test/xml/Odds_XML-missing-starters.xml"
7 -- 5 casinos, 2 teams
+ ,
+ check "deleting odds deleted its children (TBA game time)"
+ "test/xml/Odds_XML-tba-game-time.xml"
+ 119 -- 5 casinos, 114 teams
]
where
check desc path expected = testCase desc $ do