]> gitweb.michael.orlitzky.com - dead/htsn-import.git/commitdiff
Make <weather> and <Description> elements optional in TSN.XML.Weather.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 24 Sep 2014 02:25:36 +0000 (22:25 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 24 Sep 2014 02:25:36 +0000 (22:25 -0400)
Add a test case for the newly-optional elements and update a shelltest.
Update the weatherxml dbschema diagram.

doc/dbschema/weatherxml.png
src/TSN/XML/Weather.hs
test/shell/import-duplicates.test
test/xml/weatherxml-empty-weather.xml [new file with mode: 0644]

index 9382d1204a8fa41699ec4dc91e8f02858e8d9c56..42c25b26337ec443016cb1e5989ff7c0b08045df 100644 (file)
Binary files a/doc/dbschema/weatherxml.png and b/doc/dbschema/weatherxml.png differ
index c1ec2ef0004ff34cd77faf9563896698433f85ef..e7c0e3c7004ecd456e6d4a4caa92d8e4aba9a7d6 100644 (file)
@@ -101,7 +101,7 @@ dtd = "weatherxml.dtd"
 data WeatherForecastListingXml =
   WeatherForecastListingXml {
     xml_teams :: String,
-    xml_weather :: String }
+    xml_weather :: Maybe String }
   deriving (Eq, Show)
 
 
@@ -114,7 +114,7 @@ data WeatherForecastListing =
     db_weather_forecasts_id :: DefaultKey WeatherForecast,
     db_league_name :: Maybe String,
     db_teams :: String,
-    db_weather :: String }
+    db_weather :: Maybe String }
 
 
 -- | We don't make 'WeatherForecastListingXml' an instance of
@@ -247,7 +247,7 @@ data WeatherDetailedWeatherListingItem =
     db_away_team :: String,
     db_home_team :: String,
     db_weather_type :: Int,
-    db_description :: String,
+    db_description :: Maybe String,
     db_temp_adjust :: Maybe String,
     db_temperature :: Int }
 
@@ -263,7 +263,7 @@ data WeatherDetailedWeatherListingItemXml =
     xml_away_team :: String,
     xml_home_team :: String,
     xml_weather_type :: Int,
-    xml_description :: String,
+    xml_description :: Maybe String,
     xml_temp_adjust :: Maybe String,
     xml_temperature :: Int }
   deriving (Eq, Show)
@@ -506,8 +506,9 @@ pickle_listing =
     xpWrap (from_pair, to_pair) $
       xpPair
         (xpElem "teams" xpText)
-        (xpElem "weather" xpText)
+        (xpElem "weather" (xpOption xpText))
   where
+--    from_pair (ts, Nothing) = WeatherForecastListingXml ts (Just "")
     from_pair = uncurry WeatherForecastListingXml
     to_pair WeatherForecastListingXml{..} = (xml_teams, xml_weather)
 
@@ -554,7 +555,7 @@ pickle_item =
              (xpElem "AwayTeam" xpText)
              (xpElem "HomeTeam" xpText)
              (xpElem "WeatherType" xpInt)
-             (xpElem "Description" xpText)
+             (xpElem "Description" (xpOption xpText))
              (xpElem "TempAdjust" (xpOption xpText))
              (xpElem "Temperature" xpInt)
   where
@@ -660,7 +661,9 @@ test_unpickle_succeeds = testGroup "unpickle tests"
   [ check "unpickling succeeds"
           "test/xml/weatherxml.xml",
     check "unpickling succeeds (detailed)"
-          "test/xml/weatherxml-detailed.xml" ]
+          "test/xml/weatherxml-detailed.xml",
+    check "unpickling succeeds (empty weather)"
+          "test/xml/weatherxml-empty-weather.xml"]
   where
     check desc path = testCase desc $ do
       actual <- unpickleable path pickle_message
@@ -676,7 +679,9 @@ test_on_delete_cascade = testGroup "cascading delete tests"
   [ check "deleting weather deletes its children"
           "test/xml/weatherxml.xml",
     check "deleting weather deletes its children (detailed)"
-          "test/xml/weatherxml-detailed.xml" ]
+          "test/xml/weatherxml-detailed.xml",
+    check "deleting weather deletes its children (empty weather)"
+          "test/xml/weatherxml-empty-weather.xml"]
   where
     check desc path = testCase desc $ do
       weather <- unsafe_unpickle path pickle_message
@@ -713,6 +718,9 @@ test_types_detected_correctly =
       check "test/xml/weatherxml-detailed.xml"
             "first type detected correctly (detailed)"
             True,
+      check "test/xml/weatherxml-empty-weather.xml"
+            "first type detected correctly (empty weather)"
+            True,
       check "test/xml/weatherxml-type2.xml"
             "second type detected correctly"
             False ]
index 53ab0bd5ef9eb47a59e31093e9b55aaf981cebbc..10a46508dba179dfb706200db9b4d10385d57cbf 100644 (file)
@@ -16,15 +16,15 @@ rm -f shelltest.sqlite3
 # and a newsxml that aren't really supposed to import.
 find ./test/xml -maxdepth 1 -name '*.xml' | wc -l
 >>>
-31
+32
 >>>= 0
 
 # Run the imports again; we should get complaints about the duplicate
-# xml_file_ids. There are 2 errors for each violation, so we expect 2*27
+# xml_file_ids. There are 2 errors for each violation, so we expect 2*28
 # occurrences of the string 'ERROR'.
 ./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l
 >>>
-54
+56
 >>>= 0
 
 # Finally, clean up after ourselves.
diff --git a/test/xml/weatherxml-empty-weather.xml b/test/xml/weatherxml-empty-weather.xml
new file mode 100644 (file)
index 0000000..b42bb0f
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Weather 1.0/EN" "weatherxml.dtd">\r<message>\r<XML_File_ID>21812233</XML_File_ID>\r<heading>AAW%BBWEATHER</heading>\r<category>Weather</category>\r<sport>MLB</sport>\r<title>Major League Baseball Weather from The Sports Network</title>\r<forecast gamedate="Thursday, September 18th">\r<league name="National League">\r<listing>\r<teams>Washington Nationals at Miami Marlins, 7:10 p.m.</teams>\r<weather>Partly cloudy with a 60-percent chance of rain. Winds blowing in from right  field at 5-10 m.p.h.  Game-time temperature: Around 80.</weather>\r</listing>\r<listing>\r<teams>Los Angeles Dodgers at Chicago Cubs, 8:05 p.m.</teams>\r<weather>Clear. Winds blowing in from center field at 5-10 m.p.h.  Game-time temperature: Around 60.</weather>\r</listing>\r<listing>\r<teams>Milwaukee Brewers at St. Louis Cardinals, 8:15 p.m.</teams>\r<weather>Clear. Winds blowing in from center field at 5-10 m.p.h.  Game-time temperature: Around 70.</weather>\r</listing>\r<listing>\r<teams>Arizona Diamondbacks at Colorado Rockies, 8:40 p.m.</teams>\r<weather>Clear. Winds blowing out to left field at 10-15 m.p.h.  Game-time temperature: Around 85.</weather>\r</listing>\r<listing>\r<teams>Philadelphia Phillies at San Diego Padres, 9:10 p.m.</teams>\r<weather>Partly cloudy. Winds blowing in from left field at 10-15 m.p.h.  Game-time temperature: Around 75.</weather>\r</listing>\r</league>\r<league name="Interleague">\r<listing>\r<teams>Boston Red Sox at Pittsburgh Pirates, 7:05 p.m.</teams>\r<weather>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h.  Game-time temperature: Around 65.</weather>\r</listing>\r</league>\r<league name="American League">\r<listing>\r<teams>Texas Rangers at Oakland Athletics, 3:35 p.m.</teams>\r<weather>Cloudy with a 40-percent chance of rain. Winds blowing out to center field at  5-10 m.p.h.  Game-time temperature: Around 70.</weather>\r</listing>\r<listing>\r<teams>Toronto Blue Jays at New York Yankees, 7:05 p.m.</teams>\r<weather>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h.  Game-time temperature: Around 70.</weather>\r</listing>\r<listing>\r<teams>Cleveland Indians at Houston Astros, 8:10 p.m.</teams>\r<weather>Partly cloudy with a 70-percent chance of rain. Winds blowing out to left  field at 5-10 m.p.h.  Game-time temperature: Around 80.</weather>\r</listing>\r<listing>\r<teams>Seattle Mariners at LA Angels of Anaheim, 10:05 p.m.</teams>\r<weather>Clear. Winds blowing out to left field at 5-10 m.p.h.  Game-time temperature: Around 80.</weather>\r</listing>\r</league>\r</forecast>\r<forecast gamedate="Monday, September 22nd">\r<league name="">\r<listing>\r<teams>Cleveland Indians at Kansas City Royals, 6:05 p.m.</teams>\r<weather></weather>\r</listing>\r</league>\r</forecast>\r<Detailed_Weather>\r<DW_Listing SportCode="AA" Sport="MLB">\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41428</GameID>\r<Gamedate>9/18/2014 7:10:00 PM</Gamedate>\r<AwayTeam>Washington Nationals</AwayTeam>\r<HomeTeam>Miami Marlins</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy with a 60-percent chance of rain. Winds blowing in from right field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41430</GameID>\r<Gamedate>9/18/2014 8:05:00 PM</Gamedate>\r<AwayTeam>Los Angeles Dodgers</AwayTeam>\r<HomeTeam>Chicago Cubs</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing in from center field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>60</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41431</GameID>\r<Gamedate>9/18/2014 8:15:00 PM</Gamedate>\r<AwayTeam>Milwaukee Brewers</AwayTeam>\r<HomeTeam>St. Louis Cardinals</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing in from center field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>70</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41433</GameID>\r<Gamedate>9/18/2014 8:40:00 PM</Gamedate>\r<AwayTeam>Arizona Diamondbacks</AwayTeam>\r<HomeTeam>Colorado Rockies</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing out to left field at 10-15 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>85</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41432</GameID>\r<Gamedate>9/18/2014 9:10:00 PM</Gamedate>\r<AwayTeam>Philadelphia Phillies</AwayTeam>\r<HomeTeam>San Diego Padres</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds blowing in from left field at 10-15 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>75</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41429</GameID>\r<Gamedate>9/18/2014 7:05:00 PM</Gamedate>\r<AwayTeam>Boston Red Sox</AwayTeam>\r<HomeTeam>Pittsburgh Pirates</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>65</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41426</GameID>\r<Gamedate>9/18/2014 3:35:00 PM</Gamedate>\r<AwayTeam>Texas Rangers</AwayTeam>\r<HomeTeam>Oakland Athletics</HomeTeam>\r<WeatherType>3</WeatherType>\r<Description>Cloudy with a 40-percent chance of rain. Winds blowing out to center field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>70</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41424</GameID>\r<Gamedate>9/18/2014 7:05:00 PM</Gamedate>\r<AwayTeam>Toronto Blue Jays</AwayTeam>\r<HomeTeam>New York Yankees</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds blowing out to right field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>70</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41425</GameID>\r<Gamedate>9/18/2014 8:10:00 PM</Gamedate>\r<AwayTeam>Cleveland Indians</AwayTeam>\r<HomeTeam>Houston Astros</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy with a 70-percent chance of rain. Winds blowing out to left field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41427</GameID>\r<Gamedate>9/18/2014 10:05:00 PM</Gamedate>\r<AwayTeam>Seattle Mariners</AwayTeam>\r<HomeTeam>LA Angels of Anaheim</HomeTeam>\r<WeatherType>10</WeatherType>\r<Description>Clear. Winds blowing out to left field at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r<Item>\r<Sportcode>AA</Sportcode>\r<GameID>41180</GameID>\r<Gamedate>9/22/2014 6:05:00 PM</Gamedate>\r<AwayTeam>Cleveland Indians</AwayTeam>\r<HomeTeam>Kansas City Royals</HomeTeam>\r<WeatherType>11</WeatherType>\r<Description></Description>\r<TempAdjust></TempAdjust>\r<Temperature>0</Temperature>\r</Item>\r</DW_Listing>\r<DW_Listing SportCode="AB" Sport="NFL">\r<Item>\r<Sportcode>AB</Sportcode>\r<GameID>4631</GameID>\r<Gamedate>9/18/2014 8:25:00 PM</Gamedate>\r<AwayTeam>Tampa Bay Buccaneers</AwayTeam>\r<HomeTeam>Atlanta Falcons</HomeTeam>\r<WeatherType>11</WeatherType>\r<Description>Game is being played inside a dome.</Description>\r<TempAdjust></TempAdjust>\r<Temperature>0</Temperature>\r</Item>\r</DW_Listing>\r<DW_Listing SportCode="AJ" Sport="CFL">\r<Item>\r<Sportcode>AJ</Sportcode>\r<GameID>1247</GameID>\r<Gamedate>9/19/2014 10:00:00 PM</Gamedate>\r<AwayTeam>Toronto Argonauts</AwayTeam>\r<HomeTeam>British Columbia Lions</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds southeast at 5-10 m.p.h.</Description>\r<TempAdjust>Near</TempAdjust>\r<Temperature>65</Temperature>\r</Item>\r</DW_Listing>\r<DW_Listing SportCode="AF" Sport="CFOOT">\r<Item>\r<Sportcode>AF</Sportcode>\r<GameID>42695</GameID>\r<Gamedate>9/18/2014 7:30:00 PM</Gamedate>\r<AwayTeam>Auburn</AwayTeam>\r<HomeTeam>Kansas State</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy. Winds southeast at 10-15 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>75</Temperature>\r</Item>\r<Item>\r<Sportcode>AF</Sportcode>\r<GameID>44032</GameID>\r<Gamedate>9/19/2014 8:00:00 PM</Gamedate>\r<AwayTeam>Connecticut</AwayTeam>\r<HomeTeam>So Florida</HomeTeam>\r<WeatherType>2</WeatherType>\r<Description>Partly cloudy with a 50-percent chance of rain. Winds northeast at 5-10 m.p.h.</Description>\r<TempAdjust>Around</TempAdjust>\r<Temperature>80</Temperature>\r</Item>\r</DW_Listing>\r</Detailed_Weather>\r<time_stamp> September 18, 2014, at 09:19 AM ET </time_stamp>\r</message>\r
\ No newline at end of file