award shutouts
This commit is contained in:
parent
eedeaed8fc
commit
4941e0e64f
@ -28,6 +28,7 @@ module Mtlstats.Actions.NewGame
|
|||||||
, awardAssist
|
, awardAssist
|
||||||
, resetGoalData
|
, resetGoalData
|
||||||
, assignPMins
|
, assignPMins
|
||||||
|
, awardShutouts
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
@ -171,3 +172,20 @@ assignPMins mins s = fromMaybe s $ do
|
|||||||
(psPMin +~ mins)
|
(psPMin +~ mins)
|
||||||
)
|
)
|
||||||
. (gameSelectedPlayer .~ Nothing)
|
. (gameSelectedPlayer .~ Nothing)
|
||||||
|
|
||||||
|
-- | Awards a shutout to any 'Goalie' who played and didn't allow any
|
||||||
|
-- goals
|
||||||
|
awardShutouts :: ProgState -> ProgState
|
||||||
|
awardShutouts s = foldl
|
||||||
|
(\gs (gid, stats) -> if stats^.gsGoalsAllowed == 0
|
||||||
|
then gs
|
||||||
|
& database.dbGoalies %~ modifyNth gid
|
||||||
|
( ( gYtd.gsShutouts %~ succ )
|
||||||
|
. ( gLifetime.gsShutouts %~ succ )
|
||||||
|
)
|
||||||
|
& progMode.gameStateL.gameGoalieStats %~ M.adjust
|
||||||
|
(gsShutouts %~ succ)
|
||||||
|
gid
|
||||||
|
else gs)
|
||||||
|
s
|
||||||
|
(M.toList $ s^.progMode.gameStateL.gameGoalieStats)
|
||||||
|
@ -106,9 +106,10 @@ verifyDataC = Controller
|
|||||||
return C.CursorInvisible
|
return C.CursorInvisible
|
||||||
, handleController = \e -> do
|
, handleController = \e -> do
|
||||||
case ynHandler e of
|
case ynHandler e of
|
||||||
Just True -> do
|
Just True -> modify
|
||||||
modify $ progMode.gameStateL.dataVerified .~ True
|
$ (progMode.gameStateL.dataVerified .~ True)
|
||||||
modify updateGameStats
|
. updateGameStats
|
||||||
|
. awardShutouts
|
||||||
Just False -> modify $ progMode.gameStateL .~ newGameState
|
Just False -> modify $ progMode.gameStateL .~ newGameState
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
return True
|
return True
|
||||||
|
@ -44,6 +44,7 @@ spec = describe "NewGame" $ do
|
|||||||
awardAssistSpec
|
awardAssistSpec
|
||||||
resetGoalDataSpec
|
resetGoalDataSpec
|
||||||
assignPMinsSpec
|
assignPMinsSpec
|
||||||
|
awardShutoutsSpec
|
||||||
GoalieInput.spec
|
GoalieInput.spec
|
||||||
|
|
||||||
overtimeCheckSpec :: Spec
|
overtimeCheckSpec :: Spec
|
||||||
@ -481,3 +482,45 @@ assignPMinsSpec = describe "assignPMins" $ let
|
|||||||
, ( Just 2, 4, 3, 2, 6, 5, 0 )
|
, ( Just 2, 4, 3, 2, 6, 5, 0 )
|
||||||
, ( Nothing, 4, 3, 2, 6, 5, 0 )
|
, ( Nothing, 4, 3, 2, 6, 5, 0 )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
awardShutoutsSpec :: Spec
|
||||||
|
awardShutoutsSpec = describe "awardShutouts" $ let
|
||||||
|
joe = newGoalie 2 "Joe"
|
||||||
|
& gYtd.gsShutouts .~ 1
|
||||||
|
& gLifetime.gsShutouts .~ 2
|
||||||
|
|
||||||
|
bob = newGoalie 3 "Bob"
|
||||||
|
& gYtd.gsShutouts .~ 3
|
||||||
|
& gLifetime.gsShutouts .~ 4
|
||||||
|
|
||||||
|
steve = newGoalie 5 "Steve"
|
||||||
|
& gYtd.gsShutouts .~ 5
|
||||||
|
& gLifetime.gsShutouts .~ 6
|
||||||
|
|
||||||
|
ps = newProgState
|
||||||
|
& database.dbGoalies .~ [joe, bob, steve]
|
||||||
|
& progMode.gameStateL.gameGoalieStats .~ M.fromList
|
||||||
|
[ ( 0, newGoalieStats & gsGoalsAllowed .~ 1 )
|
||||||
|
, ( 1, newGoalieStats )
|
||||||
|
]
|
||||||
|
& awardShutouts
|
||||||
|
|
||||||
|
in mapM_
|
||||||
|
(\(name, gid, expectedGame, expectedYtd, expectedLt) -> context name $ let
|
||||||
|
game = M.findWithDefault newGoalieStats gid $
|
||||||
|
ps^.progMode.gameStateL.gameGoalieStats
|
||||||
|
goalie = (ps^.database.dbGoalies) !! gid
|
||||||
|
in mapM_
|
||||||
|
(\(label, actual, expected) -> context label $
|
||||||
|
it ("should be " ++ show actual) $
|
||||||
|
actual `shouldBe` expected)
|
||||||
|
-- label, actual, expected
|
||||||
|
[ ( "Game", game^.gsShutouts, expectedGame )
|
||||||
|
, ( "YTD", goalie^.gYtd.gsShutouts, expectedYtd )
|
||||||
|
, ( "lifetime", goalie^.gLifetime.gsShutouts, expectedLt )
|
||||||
|
])
|
||||||
|
-- goalie, goalie ID, Game, YTD, lifetime
|
||||||
|
[ ( "Joe", 0, 0, 1, 2 )
|
||||||
|
, ( "Bob", 1, 1, 4, 5 )
|
||||||
|
, ( "Steve", 2, 0, 5, 6 )
|
||||||
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user