1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE FlexibleInstances #-}
5 {-# LANGUAGE PatternGuards #-}
6 {-# LANGUAGE QuasiQuotes #-}
7 {-# LANGUAGE RecordWildCards #-}
8 {-# LANGUAGE TemplateHaskell #-}
9 {-# LANGUAGE TypeFamilies #-}
11 -- | Parse TSN XML for the DTD \"Odds_XML.dtd\". Each document
12 -- contains a root element \<message\> that contains a bunch of
13 -- other... disorganized... information.
20 -- * WARNING: these are private but exported to silence warnings
21 OddsCasinoConstructor(..),
23 OddsGameConstructor(..),
24 OddsGameLineConstructor(..) )
28 import Control.Applicative ( (<$>) )
29 import Control.Monad ( forM_, join )
30 import Data.Time ( UTCTime(..) )
31 import Data.Tuple.Curry ( uncurryN )
32 import qualified Data.Vector.HFixed as H ( HVector, convert )
33 import Database.Groundhog (
41 import Database.Groundhog.Core ( DefaultKey )
42 import Database.Groundhog.Generic ( runDbConn, runMigrationSilent )
43 import Database.Groundhog.Sqlite ( withSqliteConn )
44 import Database.Groundhog.TH (
47 import qualified GHC.Generics as GHC ( Generic )
48 import Test.Tasty ( TestTree, testGroup )
49 import Test.Tasty.HUnit ( (@?=), testCase )
50 import Text.Read ( readMaybe )
51 import Text.XML.HXT.Core (
66 import TSN.Codegen ( tsn_codegen_config )
67 import TSN.Database ( insert_or_select )
68 import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
74 import TSN.Team ( FromXmlFkTeams(..), Team(..) )
75 import TSN.XmlImport ( XmlImport(..), XmlImportFkTeams(..) )
85 -- | The DTD to which this module corresponds. Used to invoke dbimport.
95 -- * OddsGameCasino/OddsGameCasinoXml
98 -- | The casinos should have their own table, but the lines don't
99 -- belong in that table (there is a separate table for
100 -- 'OddsGameLine' which associates the two).
102 -- We drop the \"Game\" prefix because the casinos really aren't
103 -- children of the games; the XML just makes it seem that way.
107 casino_client_id :: Int,
108 casino_name :: String }
112 -- | The home/away lines are 'Double's, but the over/under lines are
113 -- textual. If we want to use one data type for both, we have to go
114 -- with a 'String' and then attempt to 'read' a 'Double' later when we
115 -- go to insert the thing.
117 -- The client_id and name shouldn't really be optional, but TSN has
118 -- started to send us empty casinos:
120 -- \<Casino ClientID=\"\" Name=\"\"\>\</Casino\>
122 -- We need to parse these, but we'll silently drop them during the
125 data OddsGameCasinoXml =
127 xml_casino_client_id :: Maybe Int,
128 xml_casino_name :: Maybe String,
129 xml_casino_line :: Maybe String }
130 deriving (Eq, GHC.Generic, Show)
133 -- | For 'H.convert'.
135 instance H.HVector OddsGameCasinoXml
138 -- | Try to get a 'Double' out of the 'xml_casino_line' which is a
139 -- priori textual (because it might be an over/under line).
141 home_away_line :: OddsGameCasinoXml -> Maybe Double
142 home_away_line = join . (fmap readMaybe) . xml_casino_line
146 instance ToDb OddsGameCasinoXml where
147 -- | The database representation of an 'OddsGameCasinoXml' is an
148 -- 'OddsCasino'. When our XML representation is missing a
149 -- client_id or a name, we want to ignore it. So in that case,
150 -- when we convert to the database type, we want 'Nothing'.
152 type Db OddsGameCasinoXml = Maybe OddsCasino
155 instance FromXml OddsGameCasinoXml where
156 -- | We convert from XML to the database by dropping the
157 -- 'xml_casino_line' field. If either the 'xml_casino_client_id'
158 -- or 'xml_casino_name' is missing ('Nothing'), we'll return
161 from_xml (OddsGameCasinoXml Nothing _ _) = Nothing
162 from_xml (OddsGameCasinoXml _ Nothing _) = Nothing
164 from_xml (OddsGameCasinoXml (Just c) (Just n) _) =
165 Just OddsCasino { casino_client_id = c, casino_name = n }
169 -- * OddsGameTeamXml / OddsGameTeamStarterXml
171 -- | The XML representation of a \"starter\". It contains both an ID
172 -- and a name. The ID does not appear to be optional, but the name
173 -- can be absent. When the name is absent, the ID has always been
174 -- set to \"0\". This occurs even though the entire starter element
175 -- is optional (see 'OddsGameTeamXml' below).
177 data OddsGameTeamStarterXml =
178 OddsGameTeamStarterXml {
179 xml_starter_id :: Int,
180 xml_starter_name :: Maybe String }
181 deriving (Eq, GHC.Generic, Show)
184 -- | For 'H.convert'.
186 instance H.HVector OddsGameTeamStarterXml
189 -- | The XML representation of a \<HomeTeam\> or \<AwayTeam\>, as
190 -- found in \<Game\>s. We can't use the 'Team' representation
191 -- directly because there are some other fields we need to parse.
193 data OddsGameTeamXml =
195 xml_team_id :: String, -- ^ The home/away team IDs
196 -- are three characters but
197 -- Postgres imposes no
198 -- performance penalty on
199 -- lengthless text fields,
200 -- so we ignore the probable
201 -- upper bound of three
203 xml_team_rotation_number :: Maybe Int,
204 xml_team_abbr :: String,
205 xml_team_name :: String,
206 xml_team_starter :: Maybe OddsGameTeamStarterXml,
207 xml_team_casinos :: [OddsGameCasinoXml] }
208 deriving (Eq, GHC.Generic, Show)
211 -- | For 'H.convert'.
213 instance H.HVector OddsGameTeamXml
216 instance ToDb OddsGameTeamXml where
217 -- | The database representation of an 'OddsGameTeamXml' is an
220 type Db OddsGameTeamXml = Team
222 instance FromXml OddsGameTeamXml where
223 -- | We convert from XML to the database by dropping the lines and
224 -- rotation number (which are specific to the games, not the teams
227 from_xml OddsGameTeamXml{..} =
229 team_id = xml_team_id,
230 abbreviation = Just xml_team_abbr,
231 name = Just xml_team_name }
233 -- | This allows us to insert the XML representation
234 -- 'OddsGameTeamXml' directly.
236 instance XmlImport OddsGameTeamXml where
241 -- * OddsGameOverUnderXml
243 -- | XML representation of the over/under. A wrapper around a bunch of
246 newtype OddsGameOverUnderXml =
247 OddsGameOverUnderXml { xml_casinos :: [OddsGameCasinoXml] }
253 -- | This database representation of the casino lines can't be
254 -- constructed from the one in the XML. The casinos within
255 -- Game-\>HomeTeam, Game-\>AwayTeam, and Game-\>Over_Under are all more or
256 -- less the same. We don't need a bajillion different tables to
257 -- store that, just one tying the casino/game pair to the three
260 -- The one small difference between the over/under casinos and the
261 -- home/away ones is that the home/away lines are all 'Double's, but
262 -- the over/under lines appear to be textual.
266 ogl_odds_games_id :: DefaultKey OddsGame,
267 ogl_odds_casinos_id :: DefaultKey OddsCasino,
268 ogl_over_under :: Maybe String,
269 ogl_away_line :: Maybe Double,
270 ogl_home_line :: Maybe Double }
273 -- * OddsGame/OddsGameXml
275 -- | Database representation of a game. We retain the rotation number
276 -- of the home/away teams, since those are specific to the game and
281 db_odds_id :: DefaultKey Odds,
282 db_away_team_id :: DefaultKey Team,
283 db_home_team_id :: DefaultKey Team,
285 db_game_time :: Maybe UTCTime, -- ^ Contains both the date and time.
286 db_away_team_rotation_number :: Maybe Int,
287 db_home_team_rotation_number :: Maybe Int,
288 db_away_team_starter_id :: Maybe Int,
289 db_away_team_starter_name :: Maybe String,
290 db_home_team_starter_id :: Maybe Int,
291 db_home_team_starter_name :: Maybe String }
294 -- | XML representation of an 'OddsGame'.
299 xml_game_date :: UTCTime, -- ^ Contains only the date
300 xml_game_time :: Maybe UTCTime, -- ^ Contains only the time
301 xml_away_team :: OddsGameTeamXml,
302 xml_home_team :: OddsGameTeamXml,
303 xml_over_under :: OddsGameOverUnderXml }
304 deriving (Eq, GHC.Generic, Show)
307 -- | For 'H.convert'.
309 instance H.HVector OddsGameXml
312 -- | Pseudo-field that lets us get the 'OddsGameCasinoXml's out of
315 xml_over_under_casinos :: OddsGameXml -> [OddsGameCasinoXml]
316 xml_over_under_casinos = xml_casinos . xml_over_under
319 instance ToDb OddsGameXml where
320 -- | The database representation of an 'OddsGameXml' is an
323 type Db OddsGameXml = OddsGame
326 instance Child OddsGameXml where
327 -- | Each 'OddsGameXml' is contained in an 'Odds'. In other words
328 -- the foreign key for 'OddsGame' points to an 'Odds'.
330 type Parent OddsGameXml = Odds
333 instance FromXmlFkTeams OddsGameXml where
334 -- | To convert from the XML representation to the database one, we
335 -- drop the casino lines, but retain the home/away rotation
336 -- numbers and the starters. The foreign keys to 'Odds' and the
337 -- home/away teams are passed in.
339 from_xml_fk_teams fk fk_away fk_home OddsGameXml{..} =
342 db_away_team_id = fk_away,
343 db_home_team_id = fk_home,
344 db_game_id = xml_game_id,
346 db_game_time = make_game_time xml_game_date xml_game_time,
348 db_away_team_rotation_number =
349 (xml_team_rotation_number xml_away_team),
351 db_home_team_rotation_number =
352 (xml_team_rotation_number xml_home_team),
354 db_away_team_starter_id =
355 (xml_starter_id <$> xml_team_starter xml_away_team),
357 -- Sometimes the starter element is present but the name isn't,
358 -- so we combine the two maybes with join.
359 db_away_team_starter_name = join
360 (xml_starter_name <$> xml_team_starter xml_away_team),
362 db_home_team_starter_id =
363 (xml_starter_id <$> xml_team_starter xml_home_team),
365 -- Sometimes the starter element is present but the name isn't,
366 -- so we combine the two maybes with join.
367 db_home_team_starter_name = join
368 (xml_starter_name <$> xml_team_starter xml_home_team) }
370 -- | Construct the database game time from the XML \<Game_Date\>
371 -- and \<Game_Time\> elements. The \<Game_Time\> elements
372 -- sometimes have a value of \"TBA\"; in that case, we don't
373 -- want to pretend that we know the time by setting it to
374 -- e.g. midnight, so instead we make the entire date/time
376 make_game_time :: UTCTime -> Maybe UTCTime -> Maybe UTCTime
377 make_game_time _ Nothing = Nothing
378 make_game_time d (Just t) = Just $ UTCTime (utctDay d) (utctDayTime t)
381 -- | This lets us insert the XML representation 'OddsGameXml' directly.
383 instance XmlImportFkTeams OddsGameXml
386 -- * OddsGameWithNotes
388 -- | This is our best guess at what occurs in the Odds_XML
389 -- documents. It looks like each consecutive set of games can
390 -- optionally have some notes appear before it. Each \"note\" comes
391 -- as its own \<Notes\>...\</Notes\> element.
393 -- The notes are ignored completely in the database; we only bother
394 -- with them to ensure that we're (un)pickling correctly.
396 -- We can't group the notes with a \"set\" of 'OddsGame's, because
397 -- that leads to ambiguity in parsing. Since we're going to ignore
398 -- the notes anyway, we just stick them with an arbitrary
399 -- game. C'est la vie.
401 -- We have to take the same approach with the league. The
402 -- \<League_Name\> elements are sitting outside of the games, and
403 -- are presumably supposed to be interpreted in \"chronological\"
404 -- order; i.e. the current league stays the same until we see
405 -- another \<League_Name\> element. Unfortunately, that's not how
406 -- XML works. So we're forced to ignore the league in the database
407 -- and pull the same trick, pairing them with games.
409 data OddsGameWithNotes =
411 league :: Maybe String,
413 game :: OddsGameXml }
419 -- | Database representation of a 'Message'.
423 db_xml_file_id :: Int,
426 db_line_time :: String, -- ^ We don't parse these as a 'UTCTime'
427 -- because their timezones are ambiguous
428 -- (and the date is less than useful when
429 -- it might be off by an hour).
430 db_time_stamp :: UTCTime }
433 -- | The XML representation of 'Odds'.
437 xml_xml_file_id :: Int,
438 xml_heading :: String,
439 xml_category :: String,
442 xml_line_time :: String,
443 xml_games_with_notes :: [OddsGameWithNotes],
444 xml_time_stamp :: UTCTime }
445 deriving (Eq, GHC.Generic, Show)
447 -- | For 'H.convert'.
449 instance H.HVector Message
452 -- | Pseudo-field that lets us get the 'OddsGame's out of
453 -- 'xml_games_with_notes'.
455 xml_games :: Message -> [OddsGameXml]
456 xml_games m = map game (xml_games_with_notes m)
459 instance ToDb Message where
460 -- | The database representation of a 'Message' is 'Odds'.
462 type Db Message = Odds
464 instance FromXml Message where
465 -- | To convert from the XML representation to the database one, we
466 -- just drop a bunch of fields.
468 from_xml Message{..} =
470 db_xml_file_id = xml_xml_file_id,
471 db_sport = xml_sport,
472 db_title = xml_title,
473 db_line_time = xml_line_time,
474 db_time_stamp = xml_time_stamp }
476 -- | This lets us insert the XML representation 'Message' directly.
478 instance XmlImport Message
485 -- Groundhog database schema. This must come before the DbImport
486 -- instance definition. Don't know why.
487 mkPersist tsn_codegen_config [groundhog|
494 # Prevent multiple imports of the same message.
495 fields: [db_xml_file_id]
502 - name: unique_odds_casinos
504 fields: [casino_client_id]
514 - name: db_away_team_id
517 - name: db_home_team_id
521 - entity: OddsGameLine
522 dbName: odds_games_lines
526 - name: ogl_odds_games_id
529 - name: ogl_odds_casinos_id
535 instance DbImport Message where
538 migrate (undefined :: Team)
539 migrate (undefined :: Odds)
540 migrate (undefined :: OddsCasino)
541 migrate (undefined :: OddsGame)
542 migrate (undefined :: OddsGameLine)
545 -- Insert the root "odds" element and acquire its primary key (id).
546 odds_id <- insert_xml m
548 forM_ (xml_games m) $ \game -> do
549 -- First we insert the home and away teams.
550 away_team_id <- insert_xml_or_select (xml_away_team game)
551 home_team_id <- insert_xml_or_select (xml_home_team game)
553 -- Now insert the game, keyed to the "odds" and its teams.
554 game_id <- insert_xml_fk_teams odds_id away_team_id home_team_id game
556 -- Finally, we insert the lines. The over/under entries for this
557 -- game and the lines for the casinos all wind up in the same
558 -- table, odds_games_lines. We can insert the over/under entries
559 -- freely with empty away/home lines.
561 -- Before we continue, we drop all casinos that are missing
562 -- either a client_id or name field.
564 let ou_casinos = filter nonempty_casino $ xml_over_under_casinos game
566 forM_ ou_casinos $ \c ->
567 -- Since we already filtered out the casinos without a
568 -- client_id or a name, the database conversion should always
569 -- return (Just something).
571 Nothing -> return () -- Should never happen, we filtered them out.
573 -- Start by inserting the casino.
574 ou_casino_id <- insert_or_select casino
576 -- Now add the over/under entry with the casino's id.
577 let ogl = OddsGameLine {
578 ogl_odds_games_id = game_id,
579 ogl_odds_casinos_id = ou_casino_id,
580 ogl_over_under = (xml_casino_line c),
581 ogl_away_line = Nothing,
582 ogl_home_line = Nothing }
586 -- ...but then when we insert the home/away team lines, we
587 -- prefer to update the existing entry rather than overwrite it
588 -- or add a new record.
589 let away_casinos = filter nonempty_casino $
590 xml_team_casinos (xml_away_team game)
592 forM_ away_casinos $ \c ->
594 Nothing -> return () -- Should never happen, we filtered them out.
596 -- insert, or more likely retrieve the existing, casino
597 a_casino_id <- insert_or_select casino
599 -- Get a Maybe Double instead of the Maybe String that's in there.
600 let away_line = home_away_line c
602 -- Unconditionally update that casino's away team line with ours.
603 update [Ogl_Away_Line =. away_line] $ -- WHERE
604 Ogl_Odds_Casinos_Id ==. a_casino_id
606 -- Repeat all that for the home team.
607 let home_casinos = filter nonempty_casino $
608 xml_team_casinos (xml_home_team game)
610 forM_ home_casinos $ \c ->
612 Nothing -> return () -- Should never happen, we filtered them out.
614 h_casino_id <- insert_or_select casino
615 let home_line = home_away_line c
616 update [Ogl_Home_Line =. home_line] $ -- WHERE
617 Ogl_Odds_Casinos_Id ==. h_casino_id
621 return ImportSucceeded
624 nonempty_casino :: OddsGameCasinoXml -> Bool
625 nonempty_casino OddsGameCasinoXml{..}
626 | Nothing <- xml_casino_client_id = False
627 | Nothing <- xml_casino_name = False
634 -- | Pickler for an 'OddsGame' optionally preceded by some notes.
636 pickle_game_with_notes :: PU OddsGameWithNotes
637 pickle_game_with_notes =
638 xpWrap (from_pair, to_pair) $
640 (xpOption $ xpElem "League_Name" xpText)
641 (xpList $ xpElem "Notes" xpText)
644 from_pair = uncurryN OddsGameWithNotes
645 to_pair OddsGameWithNotes{..} = (league, notes, game)
648 -- | Pickler for an 'OddsGameCasinoXml'.
650 pickle_casino :: PU OddsGameCasinoXml
653 xpWrap (from_tuple, H.convert) $
655 (xpAttr "ClientID" xp_attr_option)
656 (xpAttr "Name" $ xpOption xpText)
659 from_tuple = uncurryN OddsGameCasinoXml
662 -- | Pickler for an 'OddsGameTeamXml'.
664 pickle_home_team :: PU OddsGameTeamXml
667 xpWrap (from_tuple, H.convert) $
669 (xpElem "HomeTeamID" xpText)
670 (xpElem "HomeRotationNumber" (xpOption xpInt))
671 (xpElem "HomeAbbr" xpText)
672 (xpElem "HomeTeamName" xpText)
673 (xpOption pickle_home_starter)
674 (xpList pickle_casino)
676 from_tuple = uncurryN OddsGameTeamXml
680 -- | Portion of the 'OddsGameTeamStarterXml' pickler that is not
681 -- specific to the home/away teams.
683 pickle_starter :: PU OddsGameTeamStarterXml
685 xpWrap (from_tuple, H.convert) $
686 xpPair (xpAttr "ID" xpInt) (xpOption xpText)
688 from_tuple = uncurry OddsGameTeamStarterXml
691 -- | Pickler for an home team 'OddsGameTeamStarterXml'
693 pickle_home_starter :: PU OddsGameTeamStarterXml
694 pickle_home_starter = xpElem "HStarter" pickle_starter
697 -- | Pickler for an away team 'OddsGameTeamStarterXml'
699 pickle_away_starter :: PU OddsGameTeamStarterXml
700 pickle_away_starter = xpElem "AStarter" pickle_starter
704 -- | Pickler for an 'OddsGameTeamXml'.
706 pickle_away_team :: PU OddsGameTeamXml
709 xpWrap (from_tuple, H.convert) $
711 (xpElem "AwayTeamID" xpText)
712 (xpElem "AwayRotationNumber" (xpOption xpInt))
713 (xpElem "AwayAbbr" xpText)
714 (xpElem "AwayTeamName" xpText)
715 (xpOption pickle_away_starter)
716 (xpList pickle_casino)
718 from_tuple = uncurryN OddsGameTeamXml
722 -- | Pickler for an 'OddsGameOverUnderXml'.
724 pickle_over_under :: PU OddsGameOverUnderXml
726 xpElem "Over_Under" $
727 xpWrap (to_newtype, from_newtype) $
730 from_newtype (OddsGameOverUnderXml cs) = cs
731 to_newtype = OddsGameOverUnderXml
734 -- | Pickler for an 'OddsGameXml'.
736 pickle_game :: PU OddsGameXml
739 xpWrap (from_tuple, H.convert) $
741 (xpElem "GameID" xpInt)
742 (xpElem "Game_Date" xp_date_padded)
743 (xpElem "Game_Time" xp_tba_time)
748 from_tuple = uncurryN OddsGameXml
751 -- | Pickler for the top-level 'Message'.
753 pickle_message :: PU Message
756 xpWrap (from_tuple, H.convert) $
757 xp8Tuple (xpElem "XML_File_ID" xpInt)
758 (xpElem "heading" xpText)
759 (xpElem "category" xpText)
760 (xpElem "sport" xpText)
761 (xpElem "Title" xpText)
762 (xpElem "Line_Time" xpText)
763 (xpList pickle_game_with_notes)
764 (xpElem "time_stamp" xp_time_stamp)
766 from_tuple = uncurryN Message
773 -- | A list of all tests for this module.
775 odds_tests :: TestTree
779 [ test_on_delete_cascade,
780 test_pickle_of_unpickle_is_identity,
781 test_unpickle_succeeds ]
784 -- | If we unpickle something and then pickle it, we should wind up
785 -- with the same thing we started with. WARNING: success of this
786 -- test does not mean that unpickling succeeded.
788 test_pickle_of_unpickle_is_identity :: TestTree
789 test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests"
790 [ check "pickle composed with unpickle is the identity"
791 "test/xml/Odds_XML.xml",
793 check "pickle composed with unpickle is the identity (non-int team_id)"
794 "test/xml/Odds_XML-noninteger-team-id.xml",
796 check "pickle composed with unpickle is the identity (positive(+) line)"
797 "test/xml/Odds_XML-positive-line.xml",
799 check "pickle composed with unpickle is the identity (large file)"
800 "test/xml/Odds_XML-largefile.xml",
802 check "pickle composed with unpickle is the identity (league name)"
803 "test/xml/Odds_XML-league-name.xml",
805 check "pickle composed with unpickle is the identity (missing starters)"
806 "test/xml/Odds_XML-missing-starters.xml",
808 check "pickle composed with unpickle is the identity (TBA game time)"
809 "test/xml/Odds_XML-tba-game-time.xml",
811 check "pickle composed with unpickle is the identity (empty casino)"
812 "test/xml/Odds_XML-empty-casino.xml",
814 check "pickle composed with unpickle is the identity (long import)"
815 "test/xml/Odds_XML-long-import.xml" ]
817 check desc path = testCase desc $ do
818 (expected, actual) <- pickle_unpickle pickle_message path
822 -- | Make sure we can actually unpickle these things.
824 test_unpickle_succeeds :: TestTree
825 test_unpickle_succeeds = testGroup "unpickle tests"
826 [ check "unpickling succeeds"
827 "test/xml/Odds_XML.xml",
829 check "unpickling succeeds (non-int team_id)"
830 "test/xml/Odds_XML-noninteger-team-id.xml",
832 check "unpickling succeeds (positive(+) line)"
833 "test/xml/Odds_XML-positive-line.xml",
835 check "unpickling succeeds (large file)"
836 "test/xml/Odds_XML-largefile.xml",
838 check "unpickling succeeds (league name)"
839 "test/xml/Odds_XML-league-name.xml",
841 check "unpickling succeeds (missing starters)"
842 "test/xml/Odds_XML-missing-starters.xml",
844 check "unpickling succeeds (TBA game time)"
845 "test/xml/Odds_XML-tba-game-time.xml",
847 check "unpickling succeeds (empty casino)"
848 "test/xml/Odds_XML-empty-casino.xml",
850 check "unpickling succeeds (long-import)"
851 "test/xml/Odds_XML-long-import.xml" ]
853 check desc path = testCase desc $ do
854 actual <- unpickleable path pickle_message
859 -- | Make sure everything gets deleted when we delete the top-level
860 -- record. The casinos and teams should be left behind.
862 test_on_delete_cascade :: TestTree
863 test_on_delete_cascade = testGroup "cascading delete tests"
864 [ check "deleting odds deletes its children"
865 "test/xml/Odds_XML.xml"
866 13 -- 5 casinos, 8 teams
869 check "deleting odds deletes its children (non-int team_id)"
870 "test/xml/Odds_XML-noninteger-team-id.xml"
871 51 -- 5 casinos, 46 teams
874 check "deleting odds deleted its children (positive(+) line)"
875 "test/xml/Odds_XML-positive-line.xml"
876 17 -- 5 casinos, 12 teams
879 check "deleting odds deleted its children (large file)"
880 "test/xml/Odds_XML-largefile.xml"
881 189 -- 5 casinos, 184 teams
883 check "deleting odds deleted its children (league name)"
884 "test/xml/Odds_XML-league-name.xml"
885 35 -- 5 casinos, 30 teams
887 check "deleting odds deleted its children (missing starters)"
888 "test/xml/Odds_XML-missing-starters.xml"
889 7 -- 5 casinos, 2 teams
891 check "deleting odds deleted its children (TBA game time)"
892 "test/xml/Odds_XML-tba-game-time.xml"
893 119 -- 5 casinos, 114 teams
895 check "deleting odds deleted its children (empty casino)"
896 "test/xml/Odds_XML-empty-casino.xml"
897 11 -- 5 casinos, 6 teams
899 check "deleting odds deleted its children (long import)"
900 "test/xml/Odds_XML-long-import.xml"
901 219 -- 5 casinos, 214 teams
904 check desc path expected = testCase desc $ do
905 odds <- unsafe_unpickle path pickle_message
906 let a = undefined :: Team
907 let b = undefined :: Odds
908 let c = undefined :: OddsCasino
909 let d = undefined :: OddsGame
910 let e = undefined :: OddsGameLine
911 actual <- withSqliteConn ":memory:" $ runDbConn $ do
912 runMigrationSilent $ do
920 count_a <- countAll a
921 count_b <- countAll b
922 count_c <- countAll c
923 count_d <- countAll d
924 count_e <- countAll e
925 return $ sum [count_a, count_b, count_c,