Implementing final data structures.

master
Ben Burlingham 9 years ago
parent 292491dfb6
commit 5b7ad80303
  1. 2
      Worldcup/Games.hs
  2. 23
      readme.md
  3. 32
      worldcup.hs

@ -7,8 +7,8 @@ import Data.Aeson
import Data.Aeson.Types import Data.Aeson.Types
data Game = Game { data Game = Game {
roundId :: Int,
playAt :: String, playAt :: String,
roundId :: Int,
team1Id :: Int, team1Id :: Int,
team2Id :: Int, team2Id :: Int,
score1 :: Value, score1 :: Value,

@ -5,22 +5,27 @@ A single JSON file is downloaded to provide the data set. Its structure is as f
``` ```
{ {
'teams': { 'teams': {
"67": "Uruguay", teamId: teamCountryId,
...
},
'countries': {
countryId: { countryContinentId, countryName }
... ...
}, },
'continents': { 'continents': {
"4": "South America", continentId: continentName,
... ...
}, },
'events': { 'rounds': {
'world.1930': { roundId: roundName,
'games': [...], },
'teams': [...], 'tourneys': {
'rounds': { eventName: {
"2": "Round of 16", 'games': [{ playAt, roundId, team1Id, team2Id, score1, score1et, score1p, score2, score2et, score2p }, ...],
}, 'teams': [teamId, ...]
}, },
... ...
}
} }
``` ```

@ -28,6 +28,23 @@ instance ToJSON FinalResult where
toJSON FinalResult{..} = toJSON FinalResult{..} =
object [ "id" .= resultId, "ct" .= resultCountry, "cn" .= resultContinent, "g" .= resultGoals ] 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 :: Value -> Int
parseInt Null = 0 parseInt Null = 0
parseInt x = read $ BL8.unpack $ encode x :: Int 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) getContinentName x = continentName (continentFromTeamId x hmT hmC hmN)
goalCount x = goalsFromTeamId x gs goalCount x = goalsFromTeamId x gs
buildWorldcupData :: WorldcupData
buildWorldcupData = WorldcupData HM.empty HM.empty HM.empty HM.empty
main :: IO () main :: IO ()
main = do main = do
dataTeams <- BL.readFile "./data/teams.json" dataTeams <- BL.readFile "./data/teams.json"
@ -73,8 +93,10 @@ main = do
let continents = parseContinents (AE.eitherDecode dataContinents) let continents = parseContinents (AE.eitherDecode dataContinents)
let rounds = parseRounds (AE.eitherDecode dataRounds) let rounds = parseRounds (AE.eitherDecode dataRounds)
let encoded = encode $ buildFinalResult eventteams teams countries continents games print events
BL8.putStrLn encoded
P.putStrLn $ show (P.length eventteams) ++ " teams found." -- let encoded = encode $ buildFinalResult eventteams teams countries continents games
BL8.putStrLn "Writing teams.json" -- BL8.putStrLn encoded
BL8.writeFile "teams.json" encoded -- P.putStrLn $ show (P.length eventteams) ++ " teams found."
-- BL8.putStrLn "Writing teams.json"
-- BL8.writeFile "teams.json" encoded

Loading…
Cancel
Save