refactored updateGameStats and validageGameDate
This commit is contained in:
parent
24f02b427e
commit
5b6ecc8c40
|
@ -77,41 +77,37 @@ overtimeCheck s
|
||||||
|
|
||||||
-- | Adjusts the game stats based on the results of the current game
|
-- | Adjusts the game stats based on the results of the current game
|
||||||
updateGameStats :: ProgState -> ProgState
|
updateGameStats :: ProgState -> ProgState
|
||||||
updateGameStats s = fromMaybe s result
|
updateGameStats s = fromMaybe s $ do
|
||||||
where
|
gType <- s^.progMode.gameStateL.gameType
|
||||||
result = do
|
won <- gameWon $ s^.progMode.gameStateL
|
||||||
gType <- s^.progMode.gameStateL.gameType
|
lost <- gameLost $ s^.progMode.gameStateL
|
||||||
won <- gameWon $ s^.progMode.gameStateL
|
ot <- s^.progMode.gameStateL.overtimeFlag
|
||||||
lost <- gameLost $ s^.progMode.gameStateL
|
let
|
||||||
ot <- s^.progMode.gameStateL.overtimeFlag
|
hw = if gType == HomeGame && won then 1 else 0
|
||||||
let
|
hl = if gType == HomeGame && lost then 1 else 0
|
||||||
hw = if gType == HomeGame && won then 1 else 0
|
hot = if gType == HomeGame && ot then 1 else 0
|
||||||
hl = if gType == HomeGame && lost then 1 else 0
|
aw = if gType == AwayGame && won then 1 else 0
|
||||||
hot = if gType == HomeGame && ot then 1 else 0
|
al = if gType == AwayGame && lost then 1 else 0
|
||||||
aw = if gType == AwayGame && won then 1 else 0
|
aot = if gType == AwayGame && ot then 1 else 0
|
||||||
al = if gType == AwayGame && lost then 1 else 0
|
Just $ s
|
||||||
aot = if gType == AwayGame && ot then 1 else 0
|
& database.dbHomeGameStats
|
||||||
Just $ s
|
%~ (gmsWins +~ hw)
|
||||||
& database.dbHomeGameStats
|
. (gmsLosses +~ hl)
|
||||||
%~ (gmsWins +~ hw)
|
. (gmsOvertime +~ hot)
|
||||||
. (gmsLosses +~ hl)
|
& database.dbAwayGameStats
|
||||||
. (gmsOvertime +~ hot)
|
%~ (gmsWins +~ aw)
|
||||||
& database.dbAwayGameStats
|
. (gmsLosses +~ al)
|
||||||
%~ (gmsWins +~ aw)
|
. (gmsOvertime +~ aot)
|
||||||
. (gmsLosses +~ al)
|
|
||||||
. (gmsOvertime +~ aot)
|
|
||||||
|
|
||||||
-- | Validates the game date
|
-- | Validates the game date
|
||||||
validateGameDate :: ProgState -> ProgState
|
validateGameDate :: ProgState -> ProgState
|
||||||
validateGameDate s = fromMaybe s result
|
validateGameDate s = fromMaybe s $ do
|
||||||
where
|
y <- toInteger <$> s^.progMode.gameStateL.gameYear
|
||||||
result = do
|
m <- s^.progMode.gameStateL.gameMonth
|
||||||
y <- toInteger <$> s^.progMode.gameStateL.gameYear
|
d <- s^.progMode.gameStateL.gameDay
|
||||||
m <- s^.progMode.gameStateL.gameMonth
|
Just $ if null $ fromGregorianValid y m d
|
||||||
d <- s^.progMode.gameStateL.gameDay
|
then s & progMode.gameStateL
|
||||||
Just $ if null $ fromGregorianValid y m d
|
%~ (gameYear .~ Nothing)
|
||||||
then s & progMode.gameStateL
|
. (gameMonth .~ Nothing)
|
||||||
%~ (gameYear .~ Nothing)
|
. (gameDay .~ Nothing)
|
||||||
. (gameMonth .~ Nothing)
|
else s
|
||||||
. (gameDay .~ Nothing)
|
|
||||||
else s
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user