Merge pull request #13 from mtlstats/ot-fix

overtime losses don't count towards the loss column
This commit is contained in:
Jonathan Lamothe 2019-09-06 10:21:55 -04:00 committed by GitHub
commit 00c96e763d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 34 deletions

View File

@ -1,3 +1,5 @@
# Changelog for mtlstats # Changelog for mtlstats
## Unreleased changes ## Unreleased changes
- Overtime losses don't count in the loss column

View File

@ -545,7 +545,11 @@ gameWon gs = (>) <$> teamScore gs <*> otherScore gs
-- | Checks if the game was lost -- | Checks if the game was lost
gameLost :: GameState -> Maybe Bool gameLost :: GameState -> Maybe Bool
gameLost gs = (<) <$> teamScore gs <*> otherScore gs gameLost gs = do
ot <- gs^.overtimeFlag
team <- teamScore gs
other <- otherScore gs
Just $ not ot && other > team
-- | Checks if the game has tied -- | Checks if the game has tied
gameTied :: GameState -> Maybe Bool gameTied :: GameState -> Maybe Bool
@ -553,7 +557,7 @@ gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
-- | Calculates the number of games played -- | Calculates the number of games played
gmsGames :: GameStats -> Int gmsGames :: GameStats -> Int
gmsGames gs = gs^.gmsWins + gs^.gmsLosses gmsGames gs = gs^.gmsWins + gs^.gmsLosses + gs^.gmsOvertime
-- | Calculates the number of points -- | Calculates the number of points
gmsPoints :: GameStats -> Int gmsPoints :: GameStats -> Int

View File

@ -227,10 +227,10 @@ updateGameStatsSpec = describe "updateGameStats" $ do
in db' `shouldBe` db 1 2 1 1 1 1 in db' `shouldBe` db 1 2 1 1 1 1
context "home overtime loss" $ context "home overtime loss" $
it "should record a home loss and overtime" $ let it "should record a home overtime" $ let
s' = s (Just HomeGame) (Just 1) (Just 2) (Just True) s' = s (Just HomeGame) (Just 1) (Just 2) (Just True)
db' = updateGameStats s' ^. database db' = updateGameStats s' ^. database
in db' `shouldBe` db 1 2 2 1 1 1 in db' `shouldBe` db 1 1 2 1 1 1
context "away win" $ context "away win" $
it "should record an away win" $ let it "should record an away win" $ let
@ -245,10 +245,10 @@ updateGameStatsSpec = describe "updateGameStats" $ do
in db' `shouldBe` db 1 1 1 1 2 1 in db' `shouldBe` db 1 1 1 1 2 1
context "away overtime loss" $ context "away overtime loss" $
it "should record an away loss and overtime" $ let it "should record an away overtime" $ let
s' = s (Just AwayGame) (Just 2) (Just 1) (Just True) s' = s (Just AwayGame) (Just 2) (Just 1) (Just True)
db' = updateGameStats s' ^. database db' = updateGameStats s' ^. database
in db' `shouldBe` db 1 1 1 1 2 2 in db' `shouldBe` db 1 1 1 1 1 2
context "missing game type" $ context "missing game type" $
it "should not change anything" $ let it "should not change anything" $ let

View File

@ -320,30 +320,36 @@ gameWonSpec = describe "gameWon" $ mapM_
gameLostSpec :: Spec gameLostSpec :: Spec
gameLostSpec = describe "gameLost" $ mapM_ gameLostSpec = describe "gameLost" $ mapM_
(\(t, h, a, expected) -> let (\(t, h, a, ot, expected) -> let
desc = "game type: " ++ show t ++ desc = "game type: " ++ show t ++
", home score: " ++ show h ++ ", home score: " ++ show h ++
", away score: " ++ show a ", away score: " ++ show a ++
", overtimr flag: " ++ show ot
gs = newGameState gs = newGameState
& gameType .~ t & gameType .~ t
& homeScore .~ h & homeScore .~ h
& awayScore .~ a & awayScore .~ a
& overtimeFlag .~ ot
in context desc $ in context desc $
it ("should be " ++ show expected) $ it ("should be " ++ show expected) $
gameLost gs `shouldBe` expected) gameLost gs `shouldBe` expected)
-- gameType, homeScore, awayScore, expected -- gameType, homeScore, awayScore, overtimeFlag, expected
[ ( Just HomeGame, Just 1, Just 1, Just False ) [ ( Just HomeGame, Just 1, Just 1, Just False, Just False )
, ( Just HomeGame, Just 1, Just 2, Just True ) , ( Just HomeGame, Just 1, Just 2, Just False, Just True )
, ( Just HomeGame, Just 2, Just 1, Just False ) , ( Just HomeGame, Just 1, Just 2, Just True, Just False )
, ( Just AwayGame, Just 1, Just 1, Just False ) , ( Just HomeGame, Just 2, Just 1, Just False, Just False )
, ( Just AwayGame, Just 1, Just 2, Just False ) , ( Just AwayGame, Just 1, Just 1, Just False, Just False )
, ( Just AwayGame, Just 2, Just 1, Just True ) , ( Just AwayGame, Just 1, Just 2, Just False, Just False )
, ( Nothing, Just 1, Just 2, Nothing ) , ( Just AwayGame, Just 2, Just 1, Just False, Just True )
, ( Just HomeGame, Nothing, Just 1, Nothing ) , ( Just AwayGame, Just 2, Just 1, Just True, Just False )
, ( Just AwayGame, Nothing, Just 1, Nothing ) , ( Nothing, Just 1, Just 2, Just False, Nothing )
, ( Just HomeGame, Just 1, Nothing, Nothing ) , ( Just HomeGame, Nothing, Just 1, Just False, Nothing )
, ( Just AwayGame, Just 1, Nothing, Nothing ) , ( Just AwayGame, Nothing, Just 1, Just False, Nothing )
, ( Nothing, Nothing, Nothing, Nothing ) , ( Just HomeGame, Just 1, Nothing, Just False, Nothing )
, ( Just AwayGame, Just 1, Nothing, Just False, Nothing )
, ( Just HomeGame, Just 1, Just 2, Nothing, Nothing )
, ( Just AwayGame, Just 1, Just 2, Nothing, Nothing )
, ( Nothing, Nothing, Nothing, Just False, Nothing )
] ]
gameTiedSpec :: Spec gameTiedSpec :: Spec
@ -366,21 +372,24 @@ gameTiedSpec = describe "gameTied" $ mapM_
gmsGamesSpec :: Spec gmsGamesSpec :: Spec
gmsGamesSpec = describe "gmsGames" $ mapM_ gmsGamesSpec = describe "gmsGames" $ mapM_
(\(w, l, expected) -> let (\(w, l, ot, expected) -> let
desc = "wins: " ++ show w ++ desc = "wins: " ++ show w ++
", losses: " ++ show l ", losses: " ++ show l ++
", overtime: " ++ show ot
gs = newGameStats gs = newGameStats
& gmsWins .~ w & gmsWins .~ w
& gmsLosses .~ l & gmsLosses .~ l
& gmsOvertime .~ ot
in context desc $ in context desc $
it ("should be " ++ show expected) $ it ("should be " ++ show expected) $
gmsGames gs `shouldBe` expected) gmsGames gs `shouldBe` expected)
-- wins, losses, expected -- wins, losses, overtime, expected
[ ( 0, 0, 0 ) [ ( 0, 0, 0, 0 )
, ( 1, 0, 1 ) , ( 1, 0, 0, 1 )
, ( 0, 1, 1 ) , ( 0, 1, 0, 1 )
, ( 1, 1, 2 ) , ( 0, 0, 1, 1 )
, ( 2, 3, 5 ) , ( 1, 1, 1, 3 )
, ( 2, 3, 5, 10 )
] ]
gmsPointsSpec :: Spec gmsPointsSpec :: Spec