1 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE QuasiQuotes #-}
4 {-# LANGUAGE StandaloneDeriving #-}
5 {-# LANGUAGE TemplateHaskell #-}
6 {-# LANGUAGE TypeFamilies #-}
8 -- | Parse TSN XML for the DTD "Injuries_Detail_XML.dtd". Each
9 -- document contains a root element \<message\> that in turn
10 -- contains zero or more \<Listing\>s (note: capitalization). The
11 -- \<Listing\>s contain \<PlayerListing\>s then contain the real
12 -- meat; everything contained in the parent \<Listing\> can also be
13 -- found within the \<PlayerListing\>s.
15 -- The player listings will be mapped to a database table called
16 -- "injuries_detail" automatically. The root "message" and "listing"
19 module TSN.InjuriesDetail (
23 import Data.Time ( UTCTime )
24 import Data.Tuple.Curry ( uncurryN )
25 import Database.Groundhog()
26 import Database.Groundhog.TH
27 import Text.XML.HXT.Core (
40 import TSN.Picklers( xp_date )
51 fantasy :: String, -- ^ Nobody knows what this is.
53 injury_type :: String -- ^ "type" is a reserved keyword so we can't use it
59 listing_team_id :: Int -- ^ Avoid conflict with PlayerListing's team_id
60 , full_name :: String, -- ^ Team full name
61 player_listings :: [PlayerListing] }
70 listings :: [Listing],
71 time_stamp :: String }
75 mkPersist defaultCodegenConfig [groundhog|
76 - entity: PlayerListing
77 dbName: injuries_detail
80 --TODO see if it works witout this
84 pickle_player_listing :: PU PlayerListing
85 pickle_player_listing =
86 xpElem "PlayerListing" $
87 xpWrap (from_tuple, to_tuple) $
88 xp10Tuple (xpElem "TeamID" xpPrim)
89 (xpElem "PlayerID" xpPrim)
90 (xpElem "Date" xp_date)
92 (xpElem "Name" xpText)
93 (xpElem "Injury" xpText)
94 (xpElem "Status" xpText)
95 (xpElem "Fantasy" xpText0)
96 (xpElem "Injured" xpickle)
97 (xpElem "Type" xpText)
99 from_tuple = uncurryN PlayerListing
100 to_tuple pl = (team_id pl,
111 instance XmlPickler PlayerListing where
112 xpickle = pickle_player_listing
114 pickle_listing :: PU Listing
117 xpWrap (from_tuple, to_tuple) $
118 xpTriple (xpElem "TeamID" xpPrim)
119 (xpElem "FullName" xpText)
120 (xpList pickle_player_listing)
122 from_tuple = uncurryN Listing
123 to_tuple l = (listing_team_id l, full_name l, player_listings l)
125 instance XmlPickler Listing where
126 xpickle = pickle_listing
129 pickle_message :: PU Message
132 xpWrap (from_tuple, to_tuple) $
133 xp6Tuple (xpElem "XML_File_ID" xpPrim)
134 (xpElem "heading" xpText)
135 (xpElem "category" xpText)
136 (xpElem "sport" xpText)
137 (xpList pickle_listing)
138 (xpElem "time_stamp" xpText)
140 from_tuple = uncurryN Message
141 to_tuple m = (xml_file_id m,
148 instance XmlPickler Message where
149 xpickle = pickle_message