implemented playerReport

a private function in the Mtlstats.Report module
This commit is contained in:
Jonathan Lamothe 2019-10-16 02:14:13 -04:00
parent 277ba9a9dd
commit bfe568492d

View File

@ -89,19 +89,26 @@ standingsReport width s = fromMaybe [] $ do
] ]
gameStatsReport :: Int -> ProgState -> [String] gameStatsReport :: Int -> ProgState -> [String]
gameStatsReport width s = fromMaybe [] $ do gameStatsReport width s = maybe [] (playerReport width "GAME") $
pStats <- mapM mapM
(\(pid, stats) -> do (\(pid, stats) -> do
p <- nth pid $ s^.database.dbPlayers p <- nth pid $ s^.database.dbPlayers
Just (p, stats)) Just (p, stats))
(M.toList $ s^.progMode.gameStateL.gamePlayerStats) (M.toList $ s^.progMode.gameStateL.gamePlayerStats)
let
nameWidth = succ $ maximum $ 10 : map gameDate :: GameState -> String
(length . (^.pName) . fst) gameDate gs = fromMaybe "" $ do
pStats year <- show <$> gs^.gameYear
tStats = foldr (addPlayerStats . snd) newPlayerStats pStats month <- month <$> gs^.gameMonth
Just $ day <- padNum 2 <$> gs^.gameDay
[ centre width "GAME STATISTICS" Just $ month ++ " " ++ day ++ " " ++ year
playerReport :: Int -> String -> [(Player, PlayerStats)] -> [String]
playerReport width label ps = let
nameWidth = playerNameColWidth $ map fst ps
tStats = foldr (addPlayerStats . snd) newPlayerStats ps
in
[ centre width (label ++ " STATISTICS")
, "" , ""
, centre width , centre width
$ "NO. " $ "NO. "
@ -119,12 +126,12 @@ gameStatsReport width s = fromMaybe [] $ do
++ right 6 (show $ stats^.psAssists) ++ right 6 (show $ stats^.psAssists)
++ right 6 (show $ psPoints stats) ++ right 6 (show $ psPoints stats)
++ right 6 (show $ stats^.psPMin)) ++ right 6 (show $ stats^.psPMin))
pStats ++ ps ++
[ centre width [ centre width
$ replicate (4 + nameWidth) ' ' $ replicate (4 + nameWidth) ' '
++ replicate (3 + 3 * 6) '-' ++ replicate (3 + 3 * 6) '-'
, overlay , overlay
"GAME TOTALS" (label ++ " TOTALS")
( centre width ( centre width
$ replicate (4 + nameWidth) ' ' $ replicate (4 + nameWidth) ' '
++ right 3 (show $ tStats^.psGoals) ++ right 3 (show $ tStats^.psGoals)
@ -134,13 +141,6 @@ gameStatsReport width s = fromMaybe [] $ do
) )
] ]
gameDate :: GameState -> String
gameDate gs = fromMaybe "" $ do
year <- show <$> gs^.gameYear
month <- month <$> gs^.gameMonth
day <- padNum 2 <$> gs^.gameDay
Just $ month ++ " " ++ day ++ " " ++ year
playerNameColWidth :: [Player] -> Int playerNameColWidth :: [Player] -> Int
playerNameColWidth = foldr playerNameColWidth = foldr
(\player current -> max current $ length $ player^.pName) (\player current -> max current $ length $ player^.pName)