|
|
|
@ -15,20 +15,18 @@ import Worldcup.EventsTeams |
|
|
|
|
import Worldcup.Games |
|
|
|
|
import Worldcup.Rounds |
|
|
|
|
import Worldcup.Teams |
|
|
|
|
|
|
|
|
|
----- Data constructors ----- |
|
|
|
|
data FinalResult = FinalResult { |
|
|
|
|
resultId :: Int, |
|
|
|
|
resultCountry :: String, |
|
|
|
|
resultContinent :: String, |
|
|
|
|
resultGoals :: Int |
|
|
|
|
} deriving (Show) |
|
|
|
|
|
|
|
|
|
instance ToJSON FinalResult where |
|
|
|
|
toJSON FinalResult{..} = |
|
|
|
|
object [ "id" .= resultId, "ct" .= resultCountry, "cn" .= resultContinent, "g" .= resultGoals ] |
|
|
|
|
|
|
|
|
|
---- |
|
|
|
|
import Worldcup.Tourneys |
|
|
|
|
|
|
|
|
|
-- data FinalResult = FinalResult { |
|
|
|
|
-- resultId :: Int, |
|
|
|
|
-- resultCountry :: String, |
|
|
|
|
-- resultContinent :: String, |
|
|
|
|
-- resultGoals :: Int |
|
|
|
|
-- } deriving (Show) |
|
|
|
|
-- |
|
|
|
|
-- instance ToJSON FinalResult where |
|
|
|
|
-- toJSON FinalResult{..} = |
|
|
|
|
-- object [ "id" .= resultId, "ct" .= resultCountry, "cn" .= resultContinent, "g" .= resultGoals ] |
|
|
|
|
|
|
|
|
|
data WorldcupData = WorldcupData { |
|
|
|
|
worldcupTeams :: Teams, |
|
|
|
@ -37,40 +35,32 @@ data WorldcupData = WorldcupData { |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
countryFromTeamId :: Int -> Teams -> Countries -> Country |
|
|
|
|
countryFromTeamId _id hmT = lookupCountry a where |
|
|
|
|
a = teamCountryId $ lookupTeam _id hmT |
|
|
|
|
|
|
|
|
|
continentFromTeamId :: Int -> Teams -> Countries -> Continents -> Continent |
|
|
|
|
continentFromTeamId _id hmT hmC = lookupContinent (countryContinentId b) where |
|
|
|
|
a = teamCountryId $ lookupTeam _id hmT |
|
|
|
|
b = lookupCountry a hmC |
|
|
|
|
|
|
|
|
|
goalsFromTeamId :: Int -> [Game] -> Int |
|
|
|
|
goalsFromTeamId _id = P.foldl reducer 0 where |
|
|
|
|
reducer acc x |
|
|
|
|
| team1Id x == _id = acc + parseInt (score1 x) + parseInt (score1et x) + parseInt (score1p x) |
|
|
|
|
| team2Id x == _id = acc + parseInt (score2 x) + parseInt (score2et x) + parseInt (score2p x) |
|
|
|
|
| otherwise = acc |
|
|
|
|
|
|
|
|
|
buildFinalResult :: [Int] -> Teams -> Countries -> Continents -> [Game] -> [FinalResult] |
|
|
|
|
buildFinalResult ets hmT hmC hmN gs = P.foldl reducer [] ets where |
|
|
|
|
reducer acc x = FinalResult x (getCountryName x) (getContinentName x) (goalCount x) : acc |
|
|
|
|
getCountryName x = countryName (countryFromTeamId x hmT hmC) |
|
|
|
|
getContinentName x = continentName (continentFromTeamId x hmT hmC hmN) |
|
|
|
|
goalCount x = goalsFromTeamId x gs |
|
|
|
|
-- countryFromTeamId :: Int -> Teams -> Countries -> Country |
|
|
|
|
-- countryFromTeamId _id hmT = lookupCountry a where |
|
|
|
|
-- a = teamCountryId $ lookupTeam _id hmT |
|
|
|
|
-- |
|
|
|
|
-- continentFromTeamId :: Int -> Teams -> Countries -> Continents -> Continent |
|
|
|
|
-- continentFromTeamId _id hmT hmC = lookupContinent (countryContinentId b) where |
|
|
|
|
-- a = teamCountryId $ lookupTeam _id hmT |
|
|
|
|
-- b = lookupCountry a hmC |
|
|
|
|
-- |
|
|
|
|
-- goalsFromTeamId :: Int -> [Game] -> Int |
|
|
|
|
-- goalsFromTeamId _id = P.foldl reducer 0 where |
|
|
|
|
-- reducer acc x |
|
|
|
|
-- | team1Id x == _id = acc + parseInt (score1 x) + parseInt (score1et x) + parseInt (score1p x) |
|
|
|
|
-- | team2Id x == _id = acc + parseInt (score2 x) + parseInt (score2et x) + parseInt (score2p x) |
|
|
|
|
-- | otherwise = acc |
|
|
|
|
-- |
|
|
|
|
-- buildFinalResult :: [Int] -> Teams -> Countries -> Continents -> [Game] -> [FinalResult] |
|
|
|
|
-- buildFinalResult ets hmT hmC hmN gs = P.foldl reducer [] ets where |
|
|
|
|
-- reducer acc x = FinalResult x (getCountryName x) (getContinentName x) (goalCount x) : acc |
|
|
|
|
-- getCountryName x = countryName (countryFromTeamId x hmT hmC) |
|
|
|
|
-- 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 |
|
|
|
@ -78,7 +68,7 @@ buildWorldcupData = WorldcupData HM.empty HM.empty HM.empty HM.empty |
|
|
|
|
main :: IO () |
|
|
|
|
main = do |
|
|
|
|
dataTeams <- BL.readFile "./data/teams.json" |
|
|
|
|
dataEventTeams <- BL.readFile "./data/events_teams.json" |
|
|
|
|
dataEventsTeams <- BL.readFile "./data/events_teams.json" |
|
|
|
|
dataCountries <- BL.readFile "./data/countries.json" |
|
|
|
|
dataContinents <- BL.readFile "./data/continents.json" |
|
|
|
|
dataGames <- BL.readFile "./data/games.json" |
|
|
|
@ -87,16 +77,15 @@ main = do |
|
|
|
|
|
|
|
|
|
let teams = parseTeams (AE.eitherDecode dataTeams) |
|
|
|
|
let events = parseEvents (AE.eitherDecode dataEvents) |
|
|
|
|
let eventteams = parseEventsTeams (AE.eitherDecode dataEventTeams) |
|
|
|
|
let eventsteams = parseEventsTeams (AE.eitherDecode dataEventsTeams) |
|
|
|
|
let games = parseGames (AE.eitherDecode dataGames) |
|
|
|
|
let countries = parseCountries (AE.eitherDecode dataCountries) |
|
|
|
|
let continents = parseContinents (AE.eitherDecode dataContinents) |
|
|
|
|
let rounds = parseRounds (AE.eitherDecode dataRounds) |
|
|
|
|
|
|
|
|
|
print events |
|
|
|
|
|
|
|
|
|
-- let encoded = encode $ buildFinalResult eventteams teams countries continents games |
|
|
|
|
-- BL8.putStrLn encoded |
|
|
|
|
let encoded = encode $ buildTourneys rounds eventsteams games events |
|
|
|
|
BL8.putStrLn encoded |
|
|
|
|
-- P.putStrLn $ show (P.length eventteams) ++ " teams found." |
|
|
|
|
-- BL8.putStrLn "Writing teams.json" |
|
|
|
|
-- BL8.writeFile "teams.json" encoded |
|
|
|
|
print "DONE" |
|
|
|
|