Bump to version 0.2.2 in the cabal file.
src/Configuration.hs
src/ConnectionString.hs
src/ExitCodes.hs
+ src/Misc.hs
src/OptionalConfiguration.hs
src/TSN/Codegen.hs
src/TSN/Database.hs
import Configuration
import ConnectionString
import ExitCodes
+import Misc
import OptionalConfiguration
import TSN.Codegen
import TSN.Database
name: htsn-import
-version: 0.2.1
+version: 0.2.2
cabal-version: >= 1.8
author: Michael Orlitzky
maintainer: Michael Orlitzky <michael@orlitzky.com>
Configuration
ConnectionString
ExitCodes
+ Misc
OptionalConfiguration
TSN.Codegen
TSN.Database
--- /dev/null
+-- | Miscellaneous utility functions
+module Misc (
+ double_just )
+where
+
+-- | If given 'Nothing', return 'Nothing'. Otherwise wrap our argument
+-- in another 'Just'. This is used when handling optional XML
+-- elements that are optionally empty. If the element is missing, we
+-- want 'Nothing'. And if the contents are missing, we want
+-- 'Nothing' then too. But if something is present, we need @Just
+-- (Just foo)@ for the types to match up.
+--
+-- ==== __Examples__:
+--
+-- >>> double_just Nothing
+-- Nothing
+-- >>> double_just (Just 2)
+-- Just (Just 2)
+--
+double_just :: (Maybe a) -> Maybe (Maybe a)
+double_just val =
+ case val of
+ Nothing -> Nothing
+ just_something -> Just just_something
xpWrap )
-- Local imports.
+import Misc ( double_just )
import TSN.Codegen ( tsn_codegen_config )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
import TSN.Picklers (
to_tuple' (EarlyLineGameTeamXml u v w x y z) =
(u, double_just v, w, x, double_just y, double_just z)
- where
- double_just val = case val of
- Nothing -> Nothing
- just_something -> Just just_something
where
-- System imports
-import Control.Monad ( forM_ )
+import Control.Monad ( forM_, join )
import Data.List ( intercalate )
import Data.String.Utils ( split )
import Data.Time ( UTCTime(..) )
-- Local imports
+import Misc ( double_just )
import TSN.Codegen ( tsn_codegen_config )
import TSN.Database ( insert_or_select )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
pickle_game :: PU JFileGameXml
pickle_game =
xpElem "game" $
- xpWrap (from_tuple, H.convert) $
+ xpWrap (from_tuple, to_tuple') $
xp14Tuple (xpElem "game_id" xpInt)
(xpElem "schedule_id" xpInt)
pickle_odds_info
(xpElem "Game_Date" xp_date_padded)
(xpElem "Game_Time" xp_tba_time)
pickle_away_team
- (xpOption $ xpElem "vleague" xpText)
+ (xpOption $ xpElem "vleague" (xpOption xpText))
pickle_home_team
(xpOption $ xpElem "hleague" xpText)
(xpElem "vscore" xpInt)
(xpOption $ xpElem "time_r" xpText)
pickle_status
where
- from_tuple = uncurryN JFileGameXml
+ from_tuple (a,b,c,d,e,f,g,h,i,j,k,l,m,n) =
+ JFileGameXml a b c d e f g (join h) i j k l m n
+
+ to_tuple' (JFileGameXml a b c d e f g h i j k l m n) =
+ (a, b, c, d, e, f, g, double_just h, i, j, k, l, m, n)
pickle_odds_info :: PU JFileGameOddsInfo
xpWrap )
-- Local imports.
+import Misc ( double_just )
import TSN.Codegen ( tsn_codegen_config )
import TSN.Database ( insert_or_select )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
where
from_tuple (x,y,z) = ScoreGameStatus x (join y) z
to_tuple' ScoreGameStatus{..} =
- (db_status_numeral, s, db_status_text)
- where
- s = case db_status_type of
- Nothing -> Nothing
- Just _ -> Just db_status_type
+ (db_status_numeral, double_just db_status_type, db_status_text)
-- | Convert a 'ScoreGameXml' to/from \<game\>.
(xpOption xpText) -- Team name
where
from_tuple (x,y,z)= HTeamXml (HTeam (Team x Nothing z)) (join y)
- to_tuple' (HTeamXml (HTeam t) Nothing) = (team_id t, Nothing, name t)
- to_tuple' (HTeamXml (HTeam t) jhp) = (team_id t, Just jhp, name t)
+ to_tuple' (HTeamXml (HTeam t) jhp) = (team_id t, double_just jhp, name t)
main :: IO ()
main = doctest [ "-isrc",
"-idist/build/autogen",
+ "src/Misc.hs",
"src/TSN/Codegen.hs",
"src/TSN/Picklers.hs"]