From 3b6f77ba2120121192c0cfe8a6433d0e705d8624 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 28 Nov 2019 05:05:52 -0500 Subject: [PATCH] implemented basic logic for generating goalie reports --- src/Mtlstats/Report.hs | 57 ++++++++++++++++++++++++++++++++++-------- src/Mtlstats/Types.hs | 8 +++++- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/Mtlstats/Report.hs b/src/Mtlstats/Report.hs index a575e09..98bc9d6 100644 --- a/src/Mtlstats/Report.hs +++ b/src/Mtlstats/Report.hs @@ -22,7 +22,7 @@ along with this program. If not, see . module Mtlstats.Report (report, gameDate) where import qualified Data.Map as M -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, mapMaybe) import Lens.Micro ((^.)) import Mtlstats.Config @@ -109,21 +109,55 @@ standingsReport width s = fromMaybe [] $ do Just $ rHeader ++ table gameStatsReport :: Int -> ProgState -> [String] -gameStatsReport width s = playerReport width "GAME" $ - fromMaybe [] $ mapM +gameStatsReport width s = let + gs = s^.progMode.gameStateL + db = s^.database + + playerStats = mapMaybe (\(pid, stats) -> do - p <- nth pid $ s^.database.dbPlayers + p <- nth pid $ db^.dbPlayers Just (p, stats)) - (M.toList $ s^.progMode.gameStateL.gamePlayerStats) + (M.toList $ gs^.gamePlayerStats) + + goalieStats = mapMaybe + (\(gid, stats) -> do + g <- nth gid $ db^.dbGoalies + Just (g, stats)) + (M.toList $ gs^.gameGoalieStats) + + in playerReport width "GAME" playerStats + ++ [""] + ++ goalieReport width goalieStats yearToDateStatsReport :: Int -> ProgState -> [String] -yearToDateStatsReport width s = playerReport width "YEAR TO DATE" $ - map (\p -> (p, p^.pYtd)) $ - filter playerIsActive $ s^.database.dbPlayers +yearToDateStatsReport width s = let + db = s^.database + + playerStats = map (\p -> (p, p^.pYtd)) + $ filter playerIsActive + $ db^.dbPlayers + + goalieStats = map (\g -> (g, g^.gYtd)) + $ filter goalieIsActive + $ db^.dbGoalies + + in playerReport width "YEAR TO DATE" playerStats + ++ [""] + ++ goalieReport width goalieStats lifetimeStatsReport :: Int -> ProgState -> [String] -lifetimeStatsReport width s = playerReport width "LIFETIME" $ - map (\p -> (p, p^.pLifetime)) $ s^.database.dbPlayers +lifetimeStatsReport width s = let + db = s^.database + + playerStats = map (\p -> (p, p^.pYtd)) + $ db^.dbPlayers + + goalieStats = map (\g -> (g, g^.gYtd)) + $ db^.dbGoalies + + in playerReport width "LIFETIME" playerStats + ++ [""] + ++ goalieReport width goalieStats gameDate :: GameState -> String gameDate gs = fromMaybe "" $ do @@ -177,3 +211,6 @@ playerReport width label ps = let $ tHeader : body ++ [separator, totals] in rHeader ++ table + +goalieReport :: Int -> [(Goalie, GoalieStats)] -> [String] +goalieReport = undefined diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 430bc0c..24a69d0 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -170,7 +170,8 @@ module Mtlstats.Types ( -- ** Goalie Helpers goalieSearch, goalieSearchExact, - goalieSummary + goalieSummary, + goalieIsActive ) where import Control.Monad.Trans.State (StateT) @@ -984,3 +985,8 @@ goalieSearchExact sStr goalies = let -- | Provides a description string for a 'Goalie' goalieSummary :: Goalie -> String goalieSummary g = g^.gName ++ " (" ++ show (g^.gNumber) ++ ")" + +-- | Determines whether or not a goalie has been active in the current +-- season +goalieIsActive :: Goalie -> Bool +goalieIsActive = undefined