From 5b7ad803030c201e3c3ebf292851a3a17ac1e9a0 Mon Sep 17 00:00:00 2001 From: Ben Burlingham Date: Fri, 21 Oct 2016 17:49:23 -0700 Subject: [PATCH] Implementing final data structures. --- Worldcup/Games.hs | 2 +- readme.md | 25 +++++++++++++++---------- worldcup.hs | 32 +++++++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Worldcup/Games.hs b/Worldcup/Games.hs index b11eae1..1c15764 100644 --- a/Worldcup/Games.hs +++ b/Worldcup/Games.hs @@ -7,8 +7,8 @@ import Data.Aeson import Data.Aeson.Types data Game = Game { - roundId :: Int, playAt :: String, + roundId :: Int, team1Id :: Int, team2Id :: Int, score1 :: Value, diff --git a/readme.md b/readme.md index 3421541..53ff0d5 100644 --- a/readme.md +++ b/readme.md @@ -5,22 +5,27 @@ A single JSON file is downloaded to provide the data set. Its structure is as f ``` { 'teams': { - "67": "Uruguay", + teamId: teamCountryId, + ... + }, + 'countries': { + countryId: { countryContinentId, countryName } ... }, 'continents': { - "4": "South America", + continentId: continentName, ... }, - 'events': { - 'world.1930': { - 'games': [...], - 'teams': [...], - 'rounds': { - "2": "Round of 16", - }, + 'rounds': { + roundId: roundName, + }, + 'tourneys': { + eventName: { + 'games': [{ playAt, roundId, team1Id, team2Id, score1, score1et, score1p, score2, score2et, score2p }, ...], + 'teams': [teamId, ...] }, - ... + ... + } } ``` diff --git a/worldcup.hs b/worldcup.hs index ea4f0c7..7085a6d 100644 --- a/worldcup.hs +++ b/worldcup.hs @@ -28,6 +28,23 @@ instance ToJSON FinalResult where toJSON FinalResult{..} = object [ "id" .= resultId, "ct" .= resultCountry, "cn" .= resultContinent, "g" .= resultGoals ] +---- + +data WorldcupData = WorldcupData { + worldcupTeams :: Teams, + worldcupCountries :: Countries, + worldcupContinents :: Continents, + worldcupTourneys :: Tourneys +} deriving (Show) + +type Tourneys = HashMap String Tourney + +data Tourney = Tourney { + tourneyGames :: [Game], + tourneyTeams :: [Int] } deriving (Show) + +---- + parseInt :: Value -> Int parseInt Null = 0 parseInt x = read $ BL8.unpack $ encode x :: Int @@ -55,6 +72,9 @@ buildFinalResult ets hmT hmC hmN gs = P.foldl reducer [] ets where getContinentName x = continentName (continentFromTeamId x hmT hmC hmN) goalCount x = goalsFromTeamId x gs +buildWorldcupData :: WorldcupData +buildWorldcupData = WorldcupData HM.empty HM.empty HM.empty HM.empty + main :: IO () main = do dataTeams <- BL.readFile "./data/teams.json" @@ -73,8 +93,10 @@ main = do let continents = parseContinents (AE.eitherDecode dataContinents) let rounds = parseRounds (AE.eitherDecode dataRounds) - let encoded = encode $ buildFinalResult eventteams teams countries continents games - BL8.putStrLn encoded - P.putStrLn $ show (P.length eventteams) ++ " teams found." - BL8.putStrLn "Writing teams.json" - BL8.writeFile "teams.json" encoded + print events + + -- let encoded = encode $ buildFinalResult eventteams teams countries continents games + -- BL8.putStrLn encoded + -- P.putStrLn $ show (P.length eventteams) ++ " teams found." + -- BL8.putStrLn "Writing teams.json" + -- BL8.writeFile "teams.json" encoded