+{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
+{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
import Database.Groundhog.TH (
groundhog,
mkPersist )
+import qualified GHC.Generics as GHC ( Generic )
import Test.Tasty ( TestTree, testGroup )
import Test.Tasty.HUnit ( (@?=), testCase )
import Text.Read ( readMaybe )
xpWrap )
-- Local imports.
+import Generics ( Generic(..), to_tuple )
import TSN.Codegen ( tsn_codegen_config )
import TSN.Database ( insert_or_select )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
xml_casino_client_id :: Maybe Int,
xml_casino_name :: Maybe String,
xml_casino_line :: Maybe String }
- deriving (Eq, Show)
+ deriving (Eq, GHC.Generic, Show)
+
+
+-- | For 'Generics.to_tuple'.
+--
+instance Generic OddsGameCasinoXml
-- | Try to get a 'Double' out of the 'xml_casino_line' which is a
OddsGameTeamStarterXml {
xml_starter_id :: Int,
xml_starter_name :: Maybe String }
- deriving (Eq, Show)
+ deriving (Eq, GHC.Generic, Show)
+
+
+-- | For 'Generics.to_tuple'.
+--
+instance Generic OddsGameTeamStarterXml
-- | The XML representation of a \<HomeTeam\> or \<AwayTeam\>, as
xml_team_name :: String,
xml_team_starter :: Maybe OddsGameTeamStarterXml,
xml_team_casinos :: [OddsGameCasinoXml] }
- deriving (Eq, Show)
+ deriving (Eq, GHC.Generic, Show)
+
+
+-- | For 'Generics.to_tuple'.
+--
+instance Generic OddsGameTeamXml
+
instance ToDb OddsGameTeamXml where
-- | The database representation of an 'OddsGameTeamXml' is an
xml_away_team :: OddsGameTeamXml,
xml_home_team :: OddsGameTeamXml,
xml_over_under :: OddsGameOverUnderXml }
- deriving (Eq, Show)
+ deriving (Eq, GHC.Generic, Show)
+
+
+-- | For 'Generics.to_tuple'.
+--
+instance Generic OddsGameXml
+
-- | Pseudo-field that lets us get the 'OddsGameCasinoXml's out of
-- xml_over_under.
xml_line_time :: String,
xml_games_with_notes :: [OddsGameWithNotes],
xml_time_stamp :: UTCTime }
- deriving (Eq, Show)
+ deriving (Eq, GHC.Generic, Show)
+
+-- | For 'Generics.to_tuple'.
+--
+instance Generic Message
+
-- | Pseudo-field that lets us get the 'OddsGame's out of
-- 'xml_games_with_notes'.
where
nonempty_casino :: OddsGameCasinoXml -> Bool
- nonempty_casino (OddsGameCasinoXml Nothing _ _) = False
- nonempty_casino (OddsGameCasinoXml _ Nothing _) = False
- nonempty_casino _ = True
+ nonempty_casino OddsGameCasinoXml{..}
+ | Nothing <- xml_casino_client_id = False
+ | Nothing <- xml_casino_name = False
+ | otherwise = True
--
-- Pickling
(xpOption xpText)
where
from_tuple = uncurryN OddsGameCasinoXml
- -- Use record wildcards to avoid unused field warnings.
- to_tuple OddsGameCasinoXml{..} = (xml_casino_client_id,
- xml_casino_name,
- xml_casino_line)
-- | Pickler for an 'OddsGameTeamXml'.
where
from_tuple = uncurryN OddsGameTeamXml
- -- Use record wildcards to avoid unused field warnings.
- to_tuple OddsGameTeamXml{..} = (xml_team_id,
- xml_team_rotation_number,
- xml_team_abbr,
- xml_team_name,
- xml_team_starter,
- xml_team_casinos)
-- | Portion of the 'OddsGameTeamStarterXml' pickler that is not
xpPair (xpAttr "ID" xpInt) (xpOption xpText)
where
from_tuple = uncurry OddsGameTeamStarterXml
- to_tuple OddsGameTeamStarterXml{..} = (xml_starter_id,
- xml_starter_name)
+
-- | Pickler for an home team 'OddsGameTeamStarterXml'
--
where
from_tuple = uncurryN OddsGameTeamXml
- -- Use record wildcards to avoid unused field warnings.
- to_tuple OddsGameTeamXml{..} = (xml_team_id,
- xml_team_rotation_number,
- xml_team_abbr,
- xml_team_name,
- xml_team_starter,
- xml_team_casinos)
-
-- | Pickler for an 'OddsGameOverUnderXml'.
pickle_over_under
where
from_tuple = uncurryN OddsGameXml
- -- Use record wildcards to avoid unused field warnings.
- to_tuple OddsGameXml{..} = (xml_game_id,
- xml_game_date,
- xml_game_time,
- xml_away_team,
- xml_home_team,
- xml_over_under)
-- | Pickler for the top-level 'Message'.
(xpElem "time_stamp" xp_time_stamp)
where
from_tuple = uncurryN Message
- to_tuple m = (xml_xml_file_id m,
- xml_heading m,
- xml_category m,
- xml_sport m,
- xml_title m,
- xml_line_time m,
- xml_games_with_notes m,
- xml_time_stamp m)
--