From: Michael Orlitzky Date: Mon, 6 Oct 2014 14:04:02 +0000 (-0400) Subject: Make the JFile elements optional (they can contain "TBA"). X-Git-Tag: 0.1.2 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhtsn-import.git;a=commitdiff_plain;h=refs%2Ftags%2F0.1.2 Make the JFile elements optional (they can contain "TBA"). Add a test case for a JFile with "TBA" game time. Update the jfilexml dbschema diagram. --- diff --git a/doc/dbschema/jfilexml.png b/doc/dbschema/jfilexml.png index 06a31d1..9ba361b 100644 Binary files a/doc/dbschema/jfilexml.png and b/doc/dbschema/jfilexml.png differ diff --git a/src/TSN/XML/JFile.hs b/src/TSN/XML/JFile.hs index 51e845d..84e6b66 100644 --- a/src/TSN/XML/JFile.hs +++ b/src/TSN/XML/JFile.hs @@ -67,7 +67,7 @@ import TSN.Picklers ( xp_date, xp_date_padded, xp_datetime, - xp_time, + xp_tba_time, xp_time_dots, xp_time_stamp ) import TSN.Team ( @@ -214,7 +214,7 @@ data JFileGame = db_schedule_id :: Int, db_odds_info :: JFileGameOddsInfo, db_season_type :: Maybe String, - db_game_time :: UTCTime, + db_game_time :: Maybe UTCTime, db_vleague :: Maybe String, db_hleague :: Maybe String, db_vscore :: Int, @@ -236,7 +236,7 @@ data JFileGameXml = xml_odds_info :: JFileGameOddsInfo, xml_season_type :: Maybe String, xml_game_date :: UTCTime, - xml_game_time :: UTCTime, + xml_game_time :: Maybe UTCTime, xml_vteam :: VTeam, xml_vleague :: Maybe String, xml_hteam :: HTeam, @@ -297,11 +297,15 @@ instance FromXmlFkTeams JFileGameXml where db_time_remaining = xml_time_remaining, db_game_status = xml_game_status } where - -- | Make the database \"game time\" from the XML - -- date/time. Simply take the day part from one and the time - -- from the other. - -- - make_game_time d t = UTCTime (utctDay d) (utctDayTime t) + -- | Construct the database game time from the XML \ + -- and \ elements. The \ elements + -- sometimes have a value of \"TBA\"; in that case, we don't + -- want to pretend that we know the time by setting it to + -- e.g. midnight, so instead we make the entire date/time + -- Nothing. + make_game_time :: UTCTime -> Maybe UTCTime -> Maybe UTCTime + make_game_time _ Nothing = Nothing + make_game_time d (Just t) = Just $ UTCTime (utctDay d) (utctDayTime t) -- | This allows us to insert the XML representation @@ -453,7 +457,7 @@ pickle_game = pickle_odds_info (xpElem "seasontype" (xpOption xpText)) (xpElem "Game_Date" xp_date_padded) - (xpElem "Game_Time" xp_time) + (xpElem "Game_Time" xp_tba_time) pickle_away_team (xpOption $ xpElem "vleague" xpText) pickle_home_team @@ -612,7 +616,10 @@ test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests" [ check "pickle composed with unpickle is the identity" "test/xml/jfilexml.xml", check "pickle composed with unpickle is the identity (missing fields)" - "test/xml/jfilexml-missing-fields.xml" ] + "test/xml/jfilexml-missing-fields.xml", + + check "pickle composed with unpickle is the identity (TBA game time)" + "test/xml/jfilexml-tba-game-time.xml"] where check desc path = testCase desc $ do (expected, actual) <- pickle_unpickle pickle_message path @@ -625,8 +632,12 @@ test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests" test_unpickle_succeeds :: TestTree test_unpickle_succeeds = testGroup "unpickle tests" [ check "unpickling succeeds" "test/xml/jfilexml.xml", + check "unpickling succeeds (missing fields)" - "test/xml/jfilexml-missing-fields.xml" ] + "test/xml/jfilexml-missing-fields.xml", + + check "unpickling succeeds (TBA game time)" + "test/xml/jfilexml-tba-game-time.xml" ] where check desc path = testCase desc $ do actual <- unpickleable path pickle_message @@ -643,10 +654,15 @@ test_on_delete_cascade :: TestTree test_on_delete_cascade = testGroup "cascading delete tests" [ check "deleting auto_racing_results deletes its children" "test/xml/jfilexml.xml" - 20, + 20, -- teams + check "deleting auto_racing_results deletes its children (missing fields)" "test/xml/jfilexml-missing-fields.xml" - 44 ] + 44, + + check "deleting auto_racing_results deletes its children (TBA game time)" + "test/xml/jfilexml-tba-game-time.xml" + 8 ] where check desc path expected = testCase desc $ do results <- unsafe_unpickle path pickle_message diff --git a/test/shell/import-duplicates.test b/test/shell/import-duplicates.test index a81bd04..1eb256d 100644 --- a/test/shell/import-duplicates.test +++ b/test/shell/import-duplicates.test @@ -16,7 +16,7 @@ rm -f shelltest.sqlite3 # and a newsxml that aren't really supposed to import. find ./test/xml -maxdepth 1 -name '*.xml' | wc -l >>> -34 +35 >>>= 0 # Run the imports again; we should get complaints about the duplicate @@ -24,7 +24,7 @@ find ./test/xml -maxdepth 1 -name '*.xml' | wc -l # occurrences of the string 'ERROR'. ./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l >>> -60 +62 >>>= 0 # Finally, clean up after ourselves. diff --git a/test/xml/jfilexml-tba-game-time.xml b/test/xml/jfilexml-tba-game-time.xml new file mode 100644 index 0000000..b3032f6 --- /dev/null +++ b/test/xml/jfilexml-tba-game-time.xml @@ -0,0 +1 @@ + 21933332 BC-AAJ JFILE MLB 44542 44542 PostSeason 10/06/2014 TBA Los Angeles NL St. Louis NL 0 0 3:00 AM 44543 44543 PostSeason 10/06/2014 TBA Washington NL San Francisco NL 0 0 3:00 AM 44533 44533 10/5/2014 032 027 DET BAL Detroit Baltimore D.Price B.Norris 10/5/2014 3:45:00 PM 918 917 3:30 P.M. True ALDS - Baltimore leads 2-0 PostSeason 10/05/2014 03:45 PM Baltimore AL Detroit AL 0 0 3:00 AM 44532 44532 10/5/2014 033 029 KAN ANA Kansas City LA Angels J.Shields C.Wilson 10/5/2014 7:37:00 PM 920 919 3:30 P.M. True ALDS - Kansas City leads 2-0 PostSeason 10/05/2014 07:37 PM LA Angels AL Kansas City AL 0 0 7:37 PM October 5, 2014, at 04:10 PM ET \ No newline at end of file