{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Worldcup.Squads (Squad(..), buildSquads) where import Data.Aeson import Data.Aeson.Types import Data.HashMap.Strict as HM import Data.Maybe as M import Prelude as P import Worldcup.Continents import Worldcup.Countries import Worldcup.Events import Worldcup.EventsTeams import Worldcup.Games import Worldcup.Rounds import Worldcup.Teams import Worldcup.Tourneys data Squad = Squad { squadCountryId :: String, squadContinentId :: String, squadGoalsFor :: Int, squadGoalsAgainst :: Int } deriving (Show) instance ToJSON Squad where toJSON Squad{..} = object [ "id" .= squadId, "ct" .= squadCountry, "cn" .= squadContinent, "g" .= squadGoals ] buildSquads :: [Squad] buildSquads = [] -- countryFromTeamId :: Int -> Teams -> Countries -> Country -- countryFromTeamId _id ts = lookupCountry a where -- a = teamCountryId $ lookupTeam _id ts -- -- parseInt :: Value -> Int -- parseInt Null = 0 -- parseInt x = read $ BL8.unpack $ encode x :: Int -- -- 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