1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE QuasiQuotes #-}
5 {-# LANGUAGE RecordWildCards #-}
6 {-# LANGUAGE TemplateHaskell #-}
7 {-# LANGUAGE TypeFamilies #-}
9 -- | Parse TSN XML for the DTD \"Odds_XML.dtd\". Each document
10 -- contains a root element \<message\> that contains a bunch of
11 -- other... disorganized... information.
18 -- * WARNING: these are private but exported to silence warnings
19 OddsCasinoConstructor(..),
21 OddsGameConstructor(..),
22 OddsGameLineConstructor(..) )
26 import Control.Applicative ( (<$>) )
27 import Control.Monad ( forM_, join )
28 import Data.Time ( UTCTime(..) )
29 import Data.Tuple.Curry ( uncurryN )
30 import Database.Groundhog (
38 silentMigrationLogger,
40 import Database.Groundhog.Core ( DefaultKey )
41 import Database.Groundhog.Generic ( runDbConn )
42 import Database.Groundhog.Sqlite ( withSqliteConn )
43 import Database.Groundhog.TH (
46 import Test.Tasty ( TestTree, testGroup )
47 import Test.Tasty.HUnit ( (@?=), testCase )
48 import Text.Read ( readMaybe )
49 import Text.XML.HXT.Core (
64 import TSN.Codegen ( tsn_codegen_config )
65 import TSN.Database ( insert_or_select )
66 import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
67 import TSN.Picklers ( xp_date_padded, xp_tba_time, xp_time_stamp )
68 import TSN.Team ( FromXmlFkTeams(..), Team(..) )
69 import TSN.XmlImport ( XmlImport(..), XmlImportFkTeams(..) )
79 -- | The DTD to which this module corresponds. Used to invoke dbimport.
89 -- * OddsGameCasino/OddsGameCasinoXml
92 -- | The casinos should have their own table, but the lines don't
93 -- belong in that table (there is a separate table for
94 -- 'OddsGameLine' which associates the two).
96 -- We drop the \"Game\" prefix because the casinos really aren't
97 -- children of the games; the XML just makes it seem that way.
101 casino_client_id :: Int,
102 casino_name :: String }
106 -- | The home/away lines are 'Double's, but the over/under lines are
107 -- textual. If we want to use one data type for both, we have to go
108 -- with a 'String' and then attempt to 'read' a 'Double' later when we
109 -- go to insert the thing.
111 -- The client_id and name shouldn't really be optional, but TSN has
112 -- started to send us empty casinos:
114 -- \<Casino ClientID=\"\" Name=\"\"\>\</Casino\>
116 -- We need to parse these, but we'll silently drop them during the
119 data OddsGameCasinoXml =
121 xml_casino_client_id :: Maybe Int,
122 xml_casino_name :: Maybe String,
123 xml_casino_line :: Maybe String }
127 -- | Try to get a 'Double' out of the 'xml_casino_line' which is a
128 -- priori textual (because it might be an over/under line).
130 home_away_line :: OddsGameCasinoXml -> Maybe Double
131 home_away_line = join . (fmap readMaybe) . xml_casino_line
135 instance ToDb OddsGameCasinoXml where
136 -- | The database representation of an 'OddsGameCasinoXml' is an
137 -- 'OddsCasino'. When our XML representation is missing a
138 -- client_id or a name, we want to ignore it. So in that case,
139 -- when we convert to the database type, we want 'Nothing'.
141 type Db OddsGameCasinoXml = Maybe OddsCasino
144 instance FromXml OddsGameCasinoXml where
145 -- | We convert from XML to the database by dropping the
146 -- 'xml_casino_line' field. If either the 'xml_casino_client_id'
147 -- or 'xml_casino_name' is missing ('Nothing'), we'll return
150 from_xml (OddsGameCasinoXml Nothing _ _) = Nothing
151 from_xml (OddsGameCasinoXml _ Nothing _) = Nothing
153 from_xml (OddsGameCasinoXml (Just c) (Just n) _) =
154 Just OddsCasino { casino_client_id = c, casino_name = n }
158 -- * OddsGameTeamXml / OddsGameTeamStarterXml
160 -- | The XML representation of a \"starter\". It contains both an ID
161 -- and a name. The ID does not appear to be optional, but the name
162 -- can be absent. When the name is absent, the ID has always been
163 -- set to \"0\". This occurs even though the entire starter element
164 -- is optional (see 'OddsGameTeamXml' below).
166 data OddsGameTeamStarterXml =
167 OddsGameTeamStarterXml {
168 xml_starter_id :: Int,
169 xml_starter_name :: Maybe String }
173 -- | The XML representation of a \<HomeTeam\> or \<AwayTeam\>, as
174 -- found in \<Game\>s. We can't use the 'Team' representation
175 -- directly because there are some other fields we need to parse.
177 data OddsGameTeamXml =
179 xml_team_id :: String, -- ^ The home/away team IDs
180 -- are three characters but
181 -- Postgres imposes no
182 -- performance penalty on
183 -- lengthless text fields,
184 -- so we ignore the probable
185 -- upper bound of three
187 xml_team_rotation_number :: Maybe Int,
188 xml_team_abbr :: String,
189 xml_team_name :: String,
190 xml_team_starter :: Maybe OddsGameTeamStarterXml,
191 xml_team_casinos :: [OddsGameCasinoXml] }
194 instance ToDb OddsGameTeamXml where
195 -- | The database representation of an 'OddsGameTeamXml' is an
198 type Db OddsGameTeamXml = Team
200 instance FromXml OddsGameTeamXml where
201 -- | We convert from XML to the database by dropping the lines and
202 -- rotation number (which are specific to the games, not the teams
205 from_xml OddsGameTeamXml{..} =
207 team_id = xml_team_id,
208 abbreviation = Just xml_team_abbr,
209 name = Just xml_team_name }
211 -- | This allows us to insert the XML representation
212 -- 'OddsGameTeamXml' directly.
214 instance XmlImport OddsGameTeamXml where
219 -- * OddsGameOverUnderXml
221 -- | XML representation of the over/under. A wrapper around a bunch of
224 newtype OddsGameOverUnderXml =
225 OddsGameOverUnderXml { xml_casinos :: [OddsGameCasinoXml] }
231 -- | This database representation of the casino lines can't be
232 -- constructed from the one in the XML. The casinos within
233 -- Game-\>HomeTeam, Game-\>AwayTeam, and Game-\>Over_Under are all more or
234 -- less the same. We don't need a bajillion different tables to
235 -- store that, just one tying the casino/game pair to the three
238 -- The one small difference between the over/under casinos and the
239 -- home/away ones is that the home/away lines are all 'Double's, but
240 -- the over/under lines appear to be textual.
244 ogl_odds_games_id :: DefaultKey OddsGame,
245 ogl_odds_casinos_id :: DefaultKey OddsCasino,
246 ogl_over_under :: Maybe String,
247 ogl_away_line :: Maybe Double,
248 ogl_home_line :: Maybe Double }
251 -- * OddsGame/OddsGameXml
253 -- | Database representation of a game. We retain the rotation number
254 -- of the home/away teams, since those are specific to the game and
259 db_odds_id :: DefaultKey Odds,
260 db_away_team_id :: DefaultKey Team,
261 db_home_team_id :: DefaultKey Team,
263 db_game_time :: Maybe UTCTime, -- ^ Contains both the date and time.
264 db_away_team_rotation_number :: Maybe Int,
265 db_home_team_rotation_number :: Maybe Int,
266 db_away_team_starter_id :: Maybe Int,
267 db_away_team_starter_name :: Maybe String,
268 db_home_team_starter_id :: Maybe Int,
269 db_home_team_starter_name :: Maybe String }
272 -- | XML representation of an 'OddsGame'.
277 xml_game_date :: UTCTime, -- ^ Contains only the date
278 xml_game_time :: Maybe UTCTime, -- ^ Contains only the time
279 xml_away_team :: OddsGameTeamXml,
280 xml_home_team :: OddsGameTeamXml,
281 xml_over_under :: OddsGameOverUnderXml }
284 -- | Pseudo-field that lets us get the 'OddsGameCasinoXml's out of
287 xml_over_under_casinos :: OddsGameXml -> [OddsGameCasinoXml]
288 xml_over_under_casinos = xml_casinos . xml_over_under
291 instance ToDb OddsGameXml where
292 -- | The database representation of an 'OddsGameXml' is an
295 type Db OddsGameXml = OddsGame
298 instance Child OddsGameXml where
299 -- | Each 'OddsGameXml' is contained in an 'Odds'. In other words
300 -- the foreign key for 'OddsGame' points to an 'Odds'.
302 type Parent OddsGameXml = Odds
305 instance FromXmlFkTeams OddsGameXml where
306 -- | To convert from the XML representation to the database one, we
307 -- drop the casino lines, but retain the home/away rotation
308 -- numbers and the starters. The foreign keys to 'Odds' and the
309 -- home/away teams are passed in.
311 from_xml_fk_teams fk fk_away fk_home OddsGameXml{..} =
314 db_away_team_id = fk_away,
315 db_home_team_id = fk_home,
316 db_game_id = xml_game_id,
318 db_game_time = make_game_time xml_game_date xml_game_time,
320 db_away_team_rotation_number =
321 (xml_team_rotation_number xml_away_team),
323 db_home_team_rotation_number =
324 (xml_team_rotation_number xml_home_team),
326 db_away_team_starter_id =
327 (xml_starter_id <$> xml_team_starter xml_away_team),
329 -- Sometimes the starter element is present but the name isn't,
330 -- so we combine the two maybes with join.
331 db_away_team_starter_name = join
332 (xml_starter_name <$> xml_team_starter xml_away_team),
334 db_home_team_starter_id =
335 (xml_starter_id <$> xml_team_starter xml_home_team),
337 -- Sometimes the starter element is present but the name isn't,
338 -- so we combine the two maybes with join.
339 db_home_team_starter_name = join
340 (xml_starter_name <$> xml_team_starter xml_home_team) }
342 -- | Construct the database game time from the XML \<Game_Date\>
343 -- and \<Game_Time\> elements. The \<Game_Time\> elements
344 -- sometimes have a value of \"TBA\"; in that case, we don't
345 -- want to pretend that we know the time by setting it to
346 -- e.g. midnight, so instead we make the entire date/time
348 make_game_time :: UTCTime -> Maybe UTCTime -> Maybe UTCTime
349 make_game_time _ Nothing = Nothing
350 make_game_time d (Just t) = Just $ UTCTime (utctDay d) (utctDayTime t)
353 -- | This lets us insert the XML representation 'OddsGameXml' directly.
355 instance XmlImportFkTeams OddsGameXml
358 -- * OddsGameWithNotes
360 -- | This is our best guess at what occurs in the Odds_XML
361 -- documents. It looks like each consecutive set of games can
362 -- optionally have some notes appear before it. Each \"note\" comes
363 -- as its own \<Notes\>...\</Notes\> element.
365 -- The notes are ignored completely in the database; we only bother
366 -- with them to ensure that we're (un)pickling correctly.
368 -- We can't group the notes with a \"set\" of 'OddsGame's, because
369 -- that leads to ambiguity in parsing. Since we're going to ignore
370 -- the notes anyway, we just stick them with an arbitrary
371 -- game. C'est la vie.
373 -- We have to take the same approach with the league. The
374 -- \<League_Name\> elements are sitting outside of the games, and
375 -- are presumably supposed to be interpreted in \"chronological\"
376 -- order; i.e. the current league stays the same until we see
377 -- another \<League_Name\> element. Unfortunately, that's not how
378 -- XML works. So we're forced to ignore the league in the database
379 -- and pull the same trick, pairing them with games.
381 data OddsGameWithNotes =
383 league :: Maybe String,
385 game :: OddsGameXml }
391 -- | Database representation of a 'Message'.
395 db_xml_file_id :: Int,
398 db_line_time :: String, -- ^ We don't parse these as a 'UTCTime'
399 -- because their timezones are ambiguous
400 -- (and the date is less than useful when
401 -- it might be off by an hour).
402 db_time_stamp :: UTCTime }
405 -- | The XML representation of 'Odds'.
409 xml_xml_file_id :: Int,
410 xml_heading :: String,
411 xml_category :: String,
414 xml_line_time :: String,
415 xml_games_with_notes :: [OddsGameWithNotes],
416 xml_time_stamp :: UTCTime }
419 -- | Pseudo-field that lets us get the 'OddsGame's out of
420 -- 'xml_games_with_notes'.
422 xml_games :: Message -> [OddsGameXml]
423 xml_games m = map game (xml_games_with_notes m)
426 instance ToDb Message where
427 -- | The database representation of a 'Message' is 'Odds'.
429 type Db Message = Odds
431 instance FromXml Message where
432 -- | To convert from the XML representation to the database one, we
433 -- just drop a bunch of fields.
435 from_xml Message{..} =
437 db_xml_file_id = xml_xml_file_id,
438 db_sport = xml_sport,
439 db_title = xml_title,
440 db_line_time = xml_line_time,
441 db_time_stamp = xml_time_stamp }
443 -- | This lets us insert the XML representation 'Message' directly.
445 instance XmlImport Message
452 -- Groundhog database schema. This must come before the DbImport
453 -- instance definition. Don't know why.
454 mkPersist tsn_codegen_config [groundhog|
461 # Prevent multiple imports of the same message.
462 fields: [db_xml_file_id]
469 - name: unique_odds_casinos
471 fields: [casino_client_id]
481 - name: db_away_team_id
484 - name: db_home_team_id
488 - entity: OddsGameLine
489 dbName: odds_games_lines
493 - name: ogl_odds_games_id
496 - name: ogl_odds_casinos_id
502 instance DbImport Message where
505 migrate (undefined :: Team)
506 migrate (undefined :: Odds)
507 migrate (undefined :: OddsCasino)
508 migrate (undefined :: OddsGame)
509 migrate (undefined :: OddsGameLine)
512 -- Insert the root "odds" element and acquire its primary key (id).
513 odds_id <- insert_xml m
515 forM_ (xml_games m) $ \game -> do
516 -- First we insert the home and away teams.
517 away_team_id <- insert_xml_or_select (xml_away_team game)
518 home_team_id <- insert_xml_or_select (xml_home_team game)
520 -- Now insert the game, keyed to the "odds" and its teams.
521 game_id <- insert_xml_fk_teams odds_id away_team_id home_team_id game
523 -- Finally, we insert the lines. The over/under entries for this
524 -- game and the lines for the casinos all wind up in the same
525 -- table, odds_games_lines. We can insert the over/under entries
526 -- freely with empty away/home lines.
528 -- Before we continue, we drop all casinos that are missing
529 -- either a client_id or name field.
531 let ou_casinos = filter nonempty_casino $ xml_over_under_casinos game
533 forM_ ou_casinos $ \c ->
534 -- Since we already filtered out the casinos without a
535 -- client_id or a name, the database conversion should always
536 -- return (Just something).
538 Nothing -> return () -- Should never happen, we filtered them out.
540 -- Start by inserting the casino.
541 ou_casino_id <- insert_or_select casino
543 -- Now add the over/under entry with the casino's id.
544 let ogl = OddsGameLine {
545 ogl_odds_games_id = game_id,
546 ogl_odds_casinos_id = ou_casino_id,
547 ogl_over_under = (xml_casino_line c),
548 ogl_away_line = Nothing,
549 ogl_home_line = Nothing }
553 -- ...but then when we insert the home/away team lines, we
554 -- prefer to update the existing entry rather than overwrite it
555 -- or add a new record.
556 let away_casinos = filter nonempty_casino $
557 xml_team_casinos (xml_away_team game)
559 forM_ away_casinos $ \c ->
561 Nothing -> return () -- Should never happen, we filtered them out.
563 -- insert, or more likely retrieve the existing, casino
564 a_casino_id <- insert_or_select casino
566 -- Get a Maybe Double instead of the Maybe String that's in there.
567 let away_line = home_away_line c
569 -- Unconditionally update that casino's away team line with ours.
570 update [Ogl_Away_Line =. away_line] $ -- WHERE
571 Ogl_Odds_Casinos_Id ==. a_casino_id
573 -- Repeat all that for the home team.
574 let home_casinos = filter nonempty_casino $
575 xml_team_casinos (xml_home_team game)
577 forM_ home_casinos $ \c ->
579 Nothing -> return () -- Should never happen, we filtered them out.
581 h_casino_id <- insert_or_select casino
582 let home_line = home_away_line c
583 update [Ogl_Home_Line =. home_line] $ -- WHERE
584 Ogl_Odds_Casinos_Id ==. h_casino_id
588 return ImportSucceeded
591 nonempty_casino :: OddsGameCasinoXml -> Bool
592 nonempty_casino (OddsGameCasinoXml Nothing _ _) = False
593 nonempty_casino (OddsGameCasinoXml _ Nothing _) = False
594 nonempty_casino _ = True
600 -- | Pickler for an 'OddsGame' optionally preceded by some notes.
602 pickle_game_with_notes :: PU OddsGameWithNotes
603 pickle_game_with_notes =
604 xpWrap (from_pair, to_pair) $
606 (xpOption $ xpElem "League_Name" xpText)
607 (xpList $ xpElem "Notes" xpText)
610 from_pair = uncurryN OddsGameWithNotes
611 to_pair OddsGameWithNotes{..} = (league, notes, game)
614 -- | Pickler for an 'OddsGameCasinoXml'.
616 pickle_casino :: PU OddsGameCasinoXml
619 xpWrap (from_tuple, to_tuple) $
621 (xpAttr "ClientID" $ xpOption xpInt)
622 (xpAttr "Name" $ xpOption xpText)
625 from_tuple = uncurryN OddsGameCasinoXml
626 -- Use record wildcards to avoid unused field warnings.
627 to_tuple OddsGameCasinoXml{..} = (xml_casino_client_id,
632 -- | Pickler for an 'OddsGameTeamXml'.
634 pickle_home_team :: PU OddsGameTeamXml
637 xpWrap (from_tuple, to_tuple) $
639 (xpElem "HomeTeamID" xpText)
640 (xpElem "HomeRotationNumber" (xpOption xpInt))
641 (xpElem "HomeAbbr" xpText)
642 (xpElem "HomeTeamName" xpText)
643 (xpOption pickle_home_starter)
644 (xpList pickle_casino)
646 from_tuple = uncurryN OddsGameTeamXml
648 -- Use record wildcards to avoid unused field warnings.
649 to_tuple OddsGameTeamXml{..} = (xml_team_id,
650 xml_team_rotation_number,
657 -- | Portion of the 'OddsGameTeamStarterXml' pickler that is not
658 -- specific to the home/away teams.
660 pickle_starter :: PU OddsGameTeamStarterXml
662 xpWrap (from_tuple, to_tuple) $
663 xpPair (xpAttr "ID" xpInt) (xpOption xpText)
665 from_tuple = uncurry OddsGameTeamStarterXml
666 to_tuple OddsGameTeamStarterXml{..} = (xml_starter_id,
669 -- | Pickler for an home team 'OddsGameTeamStarterXml'
671 pickle_home_starter :: PU OddsGameTeamStarterXml
672 pickle_home_starter = xpElem "HStarter" pickle_starter
675 -- | Pickler for an away team 'OddsGameTeamStarterXml'
677 pickle_away_starter :: PU OddsGameTeamStarterXml
678 pickle_away_starter = xpElem "AStarter" pickle_starter
682 -- | Pickler for an 'OddsGameTeamXml'.
684 pickle_away_team :: PU OddsGameTeamXml
687 xpWrap (from_tuple, to_tuple) $
689 (xpElem "AwayTeamID" xpText)
690 (xpElem "AwayRotationNumber" (xpOption xpInt))
691 (xpElem "AwayAbbr" xpText)
692 (xpElem "AwayTeamName" xpText)
693 (xpOption pickle_away_starter)
694 (xpList pickle_casino)
696 from_tuple = uncurryN OddsGameTeamXml
698 -- Use record wildcards to avoid unused field warnings.
699 to_tuple OddsGameTeamXml{..} = (xml_team_id,
700 xml_team_rotation_number,
708 -- | Pickler for an 'OddsGameOverUnderXml'.
710 pickle_over_under :: PU OddsGameOverUnderXml
712 xpElem "Over_Under" $
713 xpWrap (to_newtype, from_newtype) $
716 from_newtype (OddsGameOverUnderXml cs) = cs
717 to_newtype = OddsGameOverUnderXml
720 -- | Pickler for an 'OddsGameXml'.
722 pickle_game :: PU OddsGameXml
725 xpWrap (from_tuple, to_tuple) $
727 (xpElem "GameID" xpInt)
728 (xpElem "Game_Date" xp_date_padded)
729 (xpElem "Game_Time" xp_tba_time)
734 from_tuple = uncurryN OddsGameXml
735 -- Use record wildcards to avoid unused field warnings.
736 to_tuple OddsGameXml{..} = (xml_game_id,
744 -- | Pickler for the top-level 'Message'.
746 pickle_message :: PU Message
749 xpWrap (from_tuple, to_tuple) $
750 xp8Tuple (xpElem "XML_File_ID" xpInt)
751 (xpElem "heading" xpText)
752 (xpElem "category" xpText)
753 (xpElem "sport" xpText)
754 (xpElem "Title" xpText)
755 (xpElem "Line_Time" xpText)
756 (xpList pickle_game_with_notes)
757 (xpElem "time_stamp" xp_time_stamp)
759 from_tuple = uncurryN Message
760 to_tuple m = (xml_xml_file_id m,
766 xml_games_with_notes m,
774 -- | A list of all tests for this module.
776 odds_tests :: TestTree
780 [ test_on_delete_cascade,
781 test_pickle_of_unpickle_is_identity,
782 test_unpickle_succeeds ]
785 -- | If we unpickle something and then pickle it, we should wind up
786 -- with the same thing we started with. WARNING: success of this
787 -- test does not mean that unpickling succeeded.
789 test_pickle_of_unpickle_is_identity :: TestTree
790 test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests"
791 [ check "pickle composed with unpickle is the identity"
792 "test/xml/Odds_XML.xml",
794 check "pickle composed with unpickle is the identity (non-int team_id)"
795 "test/xml/Odds_XML-noninteger-team-id.xml",
797 check "pickle composed with unpickle is the identity (positive(+) line)"
798 "test/xml/Odds_XML-positive-line.xml",
800 check "pickle composed with unpickle is the identity (large file)"
801 "test/xml/Odds_XML-largefile.xml",
803 check "pickle composed with unpickle is the identity (league name)"
804 "test/xml/Odds_XML-league-name.xml",
806 check "pickle composed with unpickle is the identity (missing starters)"
807 "test/xml/Odds_XML-missing-starters.xml",
809 check "pickle composed with unpickle is the identity (TBA game time)"
810 "test/xml/Odds_XML-tba-game-time.xml",
812 check "pickle composed with unpickle is the identity (empty casino)"
813 "test/xml/Odds_XML-empty-casino.xml" ]
815 check desc path = testCase desc $ do
816 (expected, actual) <- pickle_unpickle pickle_message path
820 -- | Make sure we can actually unpickle these things.
822 test_unpickle_succeeds :: TestTree
823 test_unpickle_succeeds = testGroup "unpickle tests"
824 [ check "unpickling succeeds"
825 "test/xml/Odds_XML.xml",
827 check "unpickling succeeds (non-int team_id)"
828 "test/xml/Odds_XML-noninteger-team-id.xml",
830 check "unpickling succeeds (positive(+) line)"
831 "test/xml/Odds_XML-positive-line.xml",
833 check "unpickling succeeds (large file)"
834 "test/xml/Odds_XML-largefile.xml",
836 check "unpickling succeeds (league name)"
837 "test/xml/Odds_XML-league-name.xml",
839 check "unpickling succeeds (missing starters)"
840 "test/xml/Odds_XML-missing-starters.xml",
842 check "unpickling succeeds (TBA game time)"
843 "test/xml/Odds_XML-tba-game-time.xml",
845 check "unpickling succeeds (empty casino)"
846 "test/xml/Odds_XML-empty-casino.xml" ]
848 check desc path = testCase desc $ do
849 actual <- unpickleable path pickle_message
854 -- | Make sure everything gets deleted when we delete the top-level
855 -- record. The casinos and teams should be left behind.
857 test_on_delete_cascade :: TestTree
858 test_on_delete_cascade = testGroup "cascading delete tests"
859 [ check "deleting odds deletes its children"
860 "test/xml/Odds_XML.xml"
861 13 -- 5 casinos, 8 teams
864 check "deleting odds deletes its children (non-int team_id)"
865 "test/xml/Odds_XML-noninteger-team-id.xml"
866 51 -- 5 casinos, 46 teams
869 check "deleting odds deleted its children (positive(+) line)"
870 "test/xml/Odds_XML-positive-line.xml"
871 17 -- 5 casinos, 12 teams
874 check "deleting odds deleted its children (large file)"
875 "test/xml/Odds_XML-largefile.xml"
876 189 -- 5 casinos, 184 teams
878 check "deleting odds deleted its children (league name)"
879 "test/xml/Odds_XML-league-name.xml"
880 35 -- 5 casinos, 30 teams
882 check "deleting odds deleted its children (missing starters)"
883 "test/xml/Odds_XML-missing-starters.xml"
884 7 -- 5 casinos, 2 teams
886 check "deleting odds deleted its children (TBA game time)"
887 "test/xml/Odds_XML-tba-game-time.xml"
888 119 -- 5 casinos, 114 teams
890 check "deleting odds deleted its children (empty casino)"
891 "test/xml/Odds_XML-empty-casino.xml"
892 11 -- 5 casinos, 6 teams
895 check desc path expected = testCase desc $ do
896 odds <- unsafe_unpickle path pickle_message
897 let a = undefined :: Team
898 let b = undefined :: Odds
899 let c = undefined :: OddsCasino
900 let d = undefined :: OddsGame
901 let e = undefined :: OddsGameLine
902 actual <- withSqliteConn ":memory:" $ runDbConn $ do
903 runMigration silentMigrationLogger $ do
911 count_a <- countAll a
912 count_b <- countAll b
913 count_c <- countAll c
914 count_d <- countAll d
915 count_e <- countAll e
916 return $ sum [count_a, count_b, count_c,