From: Michael Orlitzky Date: Sun, 6 Jul 2014 01:02:34 +0000 (-0400) Subject: Remove two unnecessary XML representations of teams/locations. X-Git-Tag: 0.0.6~23 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=d88388235ec3df702f80e70d50898850befef6ed;p=dead%2Fhtsn-import.git Remove two unnecessary XML representations of teams/locations. --- diff --git a/src/TSN/XML/JFile.hs b/src/TSN/XML/JFile.hs index 84b28b1..51db0ab 100644 --- a/src/TSN/XML/JFile.hs +++ b/src/TSN/XML/JFile.hs @@ -61,6 +61,7 @@ import Text.XML.HXT.Core ( -- Local imports import TSN.Codegen ( tsn_codegen_config ) +import TSN.Database ( insert_or_select ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_date, @@ -148,67 +149,6 @@ instance FromXml Message where instance XmlImport Message --- * JFileGameAwayTeamXml / JFileGameHomeTeamXml - --- | The XML representation of a JFile away team. Its corresponding --- database representation (along with that of the home team) is a --- TSN.Team, but their XML representations are different. -data JFileGameAwayTeamXml = - JFileGameAwayTeamXml { - away_team_id :: String, - away_team_abbreviation :: Maybe String, - away_team_name :: Maybe String } - deriving (Eq, Show) - -instance ToDb JFileGameAwayTeamXml where - -- | The database analogue of an 'JFileGameAwayTeamXml' is - -- a 'Team'. - -- - type Db JFileGameAwayTeamXml = Team - -instance FromXml JFileGameAwayTeamXml where - -- | To convert a 'JFileGameAwayTeamXml' to a 'Team', we do just - -- about nothing. - -- - from_xml JFileGameAwayTeamXml{..} = - Team { - team_id = away_team_id, - abbreviation = away_team_abbreviation, - name = away_team_name } - --- | Allow us to import JFileGameAwayTeamXml directly. -instance XmlImport JFileGameAwayTeamXml - - --- | The XML representation of a JFile home team. Its corresponding --- database representation (along with that of the away team) is a --- TSN.Team, but their XML representations are different. -data JFileGameHomeTeamXml = - JFileGameHomeTeamXml { - home_team_id :: String, - home_team_abbreviation :: Maybe String, - home_team_name :: Maybe String } - deriving (Eq, Show) - -instance ToDb JFileGameHomeTeamXml where - -- | The database analogue of an 'JFileGameHomeTeamXml' is - -- a 'Team'. - -- - type Db JFileGameHomeTeamXml = Team - -instance FromXml JFileGameHomeTeamXml where - -- | To convert a 'JFileGameHomeTeamXml' to a 'Team', we do just - -- about nothing. - -- - from_xml JFileGameHomeTeamXml{..} = - Team { - team_id = home_team_id, - abbreviation = home_team_abbreviation, - name = home_team_name } - --- | Allow us to import JFileGameHomeTeamXml directly. -instance XmlImport JFileGameHomeTeamXml - -- * JFileGame/JFileGameXml @@ -294,9 +234,9 @@ data JFileGameXml = xml_season_type :: Maybe String, xml_game_date :: UTCTime, xml_game_time :: UTCTime, - xml_vteam :: JFileGameAwayTeamXml, + xml_vteam :: Team, xml_vleague :: Maybe String, - xml_hteam :: JFileGameHomeTeamXml, + xml_hteam :: Team, xml_hleague :: Maybe String, xml_vscore :: Int, xml_hscore :: Int, @@ -385,8 +325,8 @@ instance DbImport Message where -- Now loop through the message's games forM_ (xml_games $ xml_gamelist m) $ \game -> do -- First we insert the home and away teams. - away_team_id <- insert_xml_or_select (xml_vteam game) - home_team_id <- insert_xml_or_select (xml_hteam game) + away_team_id <- insert_or_select (xml_vteam game) + home_team_id <- insert_or_select (xml_hteam game) -- Now insert the game keyed to the "jfile" and its teams. insert_xml_fk_teams_ msg_id away_team_id home_team_id game @@ -598,7 +538,10 @@ pickle_odds_info = (_:_:_:_:notes5:_) -> notes5 _ -> "" -pickle_home_team :: PU JFileGameHomeTeamXml +-- | (Un)pickle a home team to/from the dual XML/DB representation +-- 'Team'. +-- +pickle_home_team :: PU Team pickle_home_team = xpElem "hteam" $ xpWrap (from_tuple, to_tuple) $ @@ -606,13 +549,16 @@ pickle_home_team = (xpAttr "abbr" (xpOption xpText)) -- Some are blank (xpOption xpText) -- Yup, some are nameless where - from_tuple = uncurryN JFileGameHomeTeamXml - to_tuple t = (home_team_id t, - home_team_abbreviation t, - home_team_name t) + from_tuple = uncurryN Team + to_tuple t = (team_id t, + abbreviation t, + name t) -pickle_away_team :: PU JFileGameAwayTeamXml +-- | (Un)pickle an away team to/from the dual XML/DB representation +-- 'Team'. +-- +pickle_away_team :: PU Team pickle_away_team = xpElem "vteam" $ xpWrap (from_tuple, to_tuple) $ @@ -620,10 +566,10 @@ pickle_away_team = (xpAttr "abbr" (xpOption xpText)) -- Some are blank (xpOption xpText) -- Yup, some are nameless where - from_tuple = uncurryN JFileGameAwayTeamXml - to_tuple t = (away_team_id t, - away_team_abbreviation t, - away_team_name t) + from_tuple = uncurryN Team + to_tuple t = (team_id t, + abbreviation t, + name t) pickle_status :: PU JFileGameStatus diff --git a/src/TSN/XML/News.hs b/src/TSN/XML/News.hs index 50584be..a36ff7e 100644 --- a/src/TSN/XML/News.hs +++ b/src/TSN/XML/News.hs @@ -108,7 +108,7 @@ data Message = xml_sport :: String, xml_url :: Maybe String, xml_teams :: [NewsTeam], - xml_locations :: [NewsLocationXml], + xml_locations :: [Location], xml_sms :: String, xml_editor :: Maybe String, xml_text :: Maybe String, -- Text and continue seem to show up in pairs, @@ -190,38 +190,6 @@ data News_NewsTeam = News_NewsTeam (DefaultKey NewsTeam) --- * NewsLocationXml - --- | The XML type for locations as they show up in the news. The --- associated database type comes from "TSN.Location". --- -data NewsLocationXml = - NewsLocationXml { - xml_city :: Maybe String, - xml_state :: Maybe String, - xml_country :: String } - deriving (Eq, Show) - - -instance ToDb NewsLocationXml where - -- | The database analogue of a NewsLocationXml is a Location. - type Db NewsLocationXml = Location - - -instance FromXml NewsLocationXml where - -- | To convert from the XML representation to the database one, we - -- don't have to do anything. Just copy the fields. - -- - from_xml NewsLocationXml{..} = - Location xml_city xml_state xml_country - - --- | Allow us to import the XML representation directly into the --- database, without having to perform the conversion manually first. --- -instance XmlImport NewsLocationXml - - -- * News_Location -- | Mapping between 'News' records and 'Location' records in the @@ -267,7 +235,7 @@ instance DbImport Message where mapM_ insert_ news_news_teams -- Do all of that over again for the Locations. - loc_ids <- mapM insert_xml_or_select (xml_locations message) + loc_ids <- mapM insert_or_select (xml_locations message) let news_news_locations = map (News_Location news_id) loc_ids mapM_ insert_ news_news_locations @@ -374,9 +342,9 @@ pickle_msg_id = to_tuple m = (db_msg_id m, db_event_id m) --- | Convert a 'NewsLocationXml' to/from XML. +-- | Convert a 'Location' to/from XML. -- -pickle_location :: PU NewsLocationXml +pickle_location :: PU Location pickle_location = xpElem "location" $ xpWrap (from_tuple, to_tuple) $ @@ -385,8 +353,8 @@ pickle_location = (xpElem "country" xpText) where from_tuple = - uncurryN NewsLocationXml - to_tuple l = (xml_city l, xml_state l, xml_country l) + uncurryN Location + to_tuple l = (city l, state l, country l) -- | Convert a 'Message' to/from XML.