From 0826c5ed85cab5bf6758ac60fefc22a9a55218bb Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 13 Jan 2014 13:50:52 -0500 Subject: [PATCH] Fix unpickling of non-integer team_ids in TSN.XML.Odds (with tests). --- src/TSN/XML/Odds.hs | 20 +++++++++++++++----- test/xml/Odds_XML-noninteger-team-id.xml | 1 + test/xml/Odds_XML-positive-line.xml | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 test/xml/Odds_XML-noninteger-team-id.xml create mode 100644 test/xml/Odds_XML-positive-line.xml diff --git a/src/TSN/XML/Odds.hs b/src/TSN/XML/Odds.hs index eb017d8..dde6a09 100644 --- a/src/TSN/XML/Odds.hs +++ b/src/TSN/XML/Odds.hs @@ -51,6 +51,7 @@ import Text.XML.HXT.Core ( import TSN.Codegen ( tsn_codegen_config ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) +import TSN.Picklers ( xp_team_id ) import TSN.XmlImport ( XmlImport(..) ) import Xml ( FromXml(..), pickle_unpickle, unpickleable ) @@ -102,7 +103,7 @@ instance XmlImport OddsGameCasinoXml data OddsGameHomeTeamXml = OddsGameHomeTeamXml { - xml_home_team_id :: Int, + xml_home_team_id :: String, -- ^ These are three-character IDs. xml_home_rotation_number :: Int, xml_home_abbr :: String, xml_home_team_name :: String, @@ -121,7 +122,7 @@ instance XmlImport OddsGameHomeTeamXml where data OddsGameTeam = OddsGameTeam { - db_team_id :: Int, + db_team_id :: String, -- ^ The home/away team IDs are 3 characters db_abbr :: String, db_team_name :: String } deriving (Eq, Show) @@ -136,7 +137,7 @@ data OddsGame_OddsGameTeam = data OddsGameAwayTeamXml = OddsGameAwayTeamXml { - xml_away_team_id :: Int, + xml_away_team_id :: String, -- ^ These are 3 character IDs. xml_away_rotation_number :: Int, xml_away_abbr :: String, xml_away_team_name :: String, @@ -297,6 +298,9 @@ mkPersist tsn_codegen_config [groundhog| dbName: odds_games_teams constructors: - name: OddsGameTeam + fields: + - name: db_team_id + type: varchar(3) uniques: - name: unique_odds_games_team type: constraint @@ -430,7 +434,7 @@ pickle_home_team = xpElem "HomeTeam" $ xpWrap (from_tuple, to_tuple) $ xp5Tuple - (xpElem "HomeTeamID" xpInt) + (xpElem "HomeTeamID" xp_team_id) (xpElem "HomeRotationNumber" xpInt) (xpElem "HomeAbbr" xpText) (xpElem "HomeTeamName" xpText) @@ -451,7 +455,7 @@ pickle_away_team = xpElem "AwayTeam" $ xpWrap (from_tuple, to_tuple) $ xp5Tuple - (xpElem "AwayTeamID" xpInt) + (xpElem "AwayTeamID" xp_team_id) (xpElem "AwayRotationNumber" xpInt) (xpElem "AwayAbbr" xpText) (xpElem "AwayTeamName" xpText) @@ -541,6 +545,9 @@ test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests" [ check "pickle composed with unpickle is the identity" "test/xml/Odds_XML.xml", + check "pickle composed with unpickle is the identity (non-int team_id)" + "test/xml/Odds_XML-noninteger-team-id.xml", + check "pickle composed with unpickle is the identity (positive(+) line)" "test/xml/Odds_XML-positive-line.xml" ] where @@ -554,6 +561,9 @@ test_unpickle_succeeds = testGroup "unpickle tests" [ check "unpickling succeeds" "test/xml/Odds_XML.xml", + check "unpickling succeeds (non-int team_id)" + "test/xml/Odds_XML-noninteger-team-id.xml", + check "unpickling succeeds (positive(+) line)" "test/xml/Odds_XML-positive-line.xml" ] where diff --git a/test/xml/Odds_XML-noninteger-team-id.xml b/test/xml/Odds_XML-noninteger-team-id.xml new file mode 100644 index 0000000..eb776fa --- /dev/null +++ b/test/xml/Odds_XML-noninteger-team-id.xml @@ -0,0 +1 @@ + 20128027 AEO;CBB-ODDS Odds CBASK Las Vegas College Basketball Line Current Line as of 10:30 A.M. ET 68260 01/12/2014 12:00 PM B85 807 NEBRASKA Nebraska C29 808 PURDUE Purdue -7.5 -7.5 -7.5 145 145 Time change 68141 01/12/2014 01:30 PM B27 809 IOWA Iowa C12 810 OHIOST Ohio State -8 -8 -8 137 137 70237 01/12/2014 01:00 PM C67 811 SOTHRNMISS Southern Miss -2.5 -2.5 -2.5 C96 812 TULSA Tulsa 138 138 68586 01/12/2014 01:00 PM C66 813 SMU SMU B49 814 LOUISVILLE Louisville -13.5 -13.5 -13 142 142 72468 01/12/2014 02:00 PM D23 815 WGREENBAY Green Bay -5.5 -5.5 -5.5 D24 816 WMILWAUKEE Milwaukee 145 144.5 70372 01/12/2014 02:30 PM B37 817 LASALLE La Salle -4.5 -4 -4.5 A78 818 DUQUESNE Duquesne 149.5 149.5 68485 01/12/2014 03:00 PM D28 819 XAVIER Xavier A66 820 CREIGHTON Creighton -8 -8 -8 141 141 68934 01/12/2014 03:00 PM A60 821 COLORADO Colorado -4 -4 -3.5 D11 822 WASHINGTON Washington 148 148 69218 01/12/2014 04:00 PM C51 823 SANDIEGOST San Diego St -11 -11 -11 A01 824 AIRFORCE Air Force 132 132 70638 01/12/2014 04:30 PM C05 825 NILLINOIS Northern Ill A29 826 BOWLINGGRN Bowling Green -8.5 -8.5 -8.5 117 117 68969 01/12/2014 05:00 PM C72 827 STANFORD Stanford C17 828 OREGON Oregon -6.5 -7 -6.5 160 160 70403 01/12/2014 06:00 PM A02 829 AKRON Akron C11 830 OHIOU Ohio -4.5 -4.5 -4.5 132.5 132.5 72568 01/12/2014 07:00 PM B21 831 ILLCHICAGO Ill-Chicago D26 832 WRIGHTST Wright State -11 -11 -11 129.5 129.5 69117 01/12/2014 07:00 PM C98 833 UTAH Utah -2.5 -2.5 -2.5 D12 834 WASHSTATE Washington St 123.5 123.5 68037 01/12/2014 07:30 PM B19 835 ILLINOIS Illinois -5.5 -5.5 -5.5 C07 836 NWESTERN Northwestern 123.5 123.5 67789 01/12/2014 08:00 PM B58 837 MARYLAND Maryland A93 838 FLORIDAST Florida State -6.5 -6.5 -6.5 128.5 138.5 68787 01/12/2014 09:00 PM A11 839 ARIZONA Arizona -13 -13 -13 C64 840 USC USC 128 138 68833 01/12/2014 10:00 PM A12 841 ARIZONAST Arizona State C97 842 UCLA UCLA -6.5 -6.5 -6.5 153.5 153.5 Added games 72263 01/12/2014 02:00 PM B76 843 MONMOUTH Monmouth A44 844 CANISIUS Canisius -10 -10 -10 72492 01/12/2014 02:00 PM C35 845 RIDER Rider B92 846 NIAGARA Niagara pick pick pick 72365 01/12/2014 02:00 PM B55 847 MARIST Marist B54 848 MANHATTAN Manhattan -12 -12 -12 72331 01/12/2014 02:00 PM B26 849 IONA Iona -3.5 -3.5 -3.5 C57 850 SIENA Siena 72531 01/12/2014 02:30 PM C30 851 QUINNIPIAC Quinnipiac -4.5 -4 -4.5 C47 852 STPETERS Saint Peters January 12, 2014, at 10:32 AM ET \ No newline at end of file diff --git a/test/xml/Odds_XML-positive-line.xml b/test/xml/Odds_XML-positive-line.xml new file mode 100644 index 0000000..ef777f5 --- /dev/null +++ b/test/xml/Odds_XML-positive-line.xml @@ -0,0 +1 @@ + 20130236 ADO;NHL-ODDS Odds NHL Las Vegas National Hockey League Line Current Line as of 3:30 P.M. ET 18068 01/12/2014 06:00 PM 132 003 NYI NY Islanders +120 +120 +125 +120 +120 130 004 DAL Dallas -140 -140 -145 -140 -140 5.5o 5.5o 5.5o 5.5o 5.5o 18072 01/12/2014 07:00 PM 131 005 NJD New Jersey +110 +115 +110 +120 +116 138 006 TOR Toronto -130 -135 -130 -140 -126 5o 5o 5o 5o 5o 18075 01/12/2014 07:00 PM 134 007 PHI Philadelphia +140 +140 +140 +140 +140 133 008 NYR NY Rangers -160 -165 -160 -160 -160 5o 5o 5o 5o 5o 18079 01/12/2014 07:00 PM 126 009 EDM Edmonton +243 +255 +245 +230 +240 124 010 CHI Chicago -285 -315 -290 -270 -280 5.5o 5.5o 5.5o 5.5o 5.5o 18083 01/12/2014 07:00 PM 149 011 MIN Minnesota +120 +115 +120 +120 +120 150 012 NAS Nashville -140 -135 -140 -140 -140 5o 5o 5p 5u 5p 18088 01/12/2014 08:00 PM 125 013 DET Detroit +170 +175 +170 +170 +170 145 014 ANA Anaheim -200 -210 -210 -200 -200 5.5u 5.5u 5.5u 5.5u 5.5u January 12, 2014, at 03:29 PM ET \ No newline at end of file -- 2.44.2