Implementing final data structures.

master
Ben Burlingham 9 years ago
parent 292491dfb6
commit 5b7ad80303
  1. 2
      Worldcup/Games.hs
  2. 25
      readme.md
  3. 32
      worldcup.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,

@ -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, ...]
},
...
...
}
}
```

@ -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

Loading…
Cancel
Save