Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9534218797 | ||
|
|
d7d3d1a4fd | ||
|
|
86c4fe316e | ||
|
|
d5ac42268f | ||
|
|
df26e9d265 | ||
|
|
cb5f2d7d15 | ||
|
|
152ea76bda | ||
|
|
36ab31a17c | ||
|
|
768cb47fac | ||
|
|
427ad12603 | ||
|
|
1ca2ffc378 | ||
|
|
9e6b71c464 | ||
|
|
2f4e963e41 | ||
|
|
05af939963 | ||
|
|
8af7974c8f | ||
|
|
f7cfd5d835 | ||
|
|
cc495fa589 | ||
|
|
9c5d166f31 | ||
|
|
a9e12d11a9 | ||
|
|
08be4154b3 | ||
|
|
4e25db12f1 | ||
|
|
50389b4f4c | ||
|
|
dcbb809ae1 | ||
|
|
be54198960 | ||
|
|
e3d5af5f88 | ||
|
|
de67628df0 | ||
|
|
4848e54d81 | ||
|
|
3b6f77ba21 | ||
|
|
e7606c8a5e | ||
|
|
3560aa7595 | ||
|
|
5979856578 | ||
|
|
4941e0e64f | ||
|
|
eedeaed8fc | ||
|
|
d0f237e707 | ||
|
|
8795cb46a9 | ||
|
|
f1f7077c8c | ||
|
|
a407a01339 | ||
|
|
3e1218f6ff | ||
|
|
7ff16b8ac2 | ||
|
|
d7879a92af | ||
|
|
9b9feefa4f | ||
|
|
26a90a5ed9 | ||
|
|
e8b850c23a | ||
|
|
0efac07a33 |
11
ChangeLog.md
11
ChangeLog.md
@@ -1,5 +1,16 @@
|
|||||||
# Changelog for mtlstats
|
# Changelog for mtlstats
|
||||||
|
|
||||||
|
## 0.8.0
|
||||||
|
- Bugfix: removed quotation marks from goalie names in report
|
||||||
|
- Allow lower case player names
|
||||||
|
- Don't show players without points in game report
|
||||||
|
- Removed unnecessary goalie statistics from game report
|
||||||
|
- Fixed goalie average calculation
|
||||||
|
|
||||||
|
## 0.7.0
|
||||||
|
- Shortened views to fit within 25 lines
|
||||||
|
- Implemented goalie reports
|
||||||
|
|
||||||
## 0.6.0
|
## 0.6.0
|
||||||
- Generate lifetime statistics report
|
- Generate lifetime statistics report
|
||||||
- Implemented goalie editing
|
- Implemented goalie editing
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: mtlstats
|
name: mtlstats
|
||||||
version: 0.6.0
|
version: 0.8.0
|
||||||
github: "mtlstats/mtlstats"
|
github: "mtlstats/mtlstats"
|
||||||
license: GPL-3
|
license: GPL-3
|
||||||
author: "Jonathan Lamothe"
|
author: "Jonathan Lamothe"
|
||||||
|
|||||||
@@ -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
|
||||||
|
(\s' (gid, stats) -> if stats^.gsGoalsAllowed == 0
|
||||||
|
then s'
|
||||||
|
& database.dbGoalies %~ modifyNth gid
|
||||||
|
( ( gYtd.gsShutouts %~ succ )
|
||||||
|
. ( gLifetime.gsShutouts %~ succ )
|
||||||
|
)
|
||||||
|
& progMode.gameStateL.gameGoalieStats %~ M.adjust
|
||||||
|
(gsShutouts %~ succ)
|
||||||
|
gid
|
||||||
|
else s')
|
||||||
|
s
|
||||||
|
(M.toList $ s^.progMode.gameStateL.gameGoalieStats)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ dispatch :: ProgState -> Controller
|
|||||||
dispatch s = case s^.progMode of
|
dispatch s = case s^.progMode of
|
||||||
MainMenu -> mainMenuC
|
MainMenu -> mainMenuC
|
||||||
NewSeason -> newSeasonC
|
NewSeason -> newSeasonC
|
||||||
NewGame _ -> newGameC s
|
NewGame gs -> newGameC gs
|
||||||
CreatePlayer cps
|
CreatePlayer cps
|
||||||
| null $ cps^.cpsNumber -> getPlayerNumC
|
| null $ cps^.cpsNumber -> getPlayerNumC
|
||||||
| null $ cps^.cpsName -> getPlayerNameC
|
| null $ cps^.cpsName -> getPlayerNameC
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import Data.Maybe (fromMaybe)
|
|||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
import UI.NCurses as C
|
import UI.NCurses as C
|
||||||
|
|
||||||
|
import Mtlstats.Helpers.Goalie
|
||||||
import Mtlstats.Menu
|
import Mtlstats.Menu
|
||||||
import Mtlstats.Menu.EditGoalie
|
import Mtlstats.Menu.EditGoalie
|
||||||
import Mtlstats.Prompt
|
import Mtlstats.Prompt
|
||||||
@@ -118,20 +119,4 @@ header :: ProgState -> C.Update ()
|
|||||||
header s = C.drawString $ fromMaybe "" $ do
|
header s = C.drawString $ fromMaybe "" $ do
|
||||||
gid <- s^.progMode.editGoalieStateL.egsSelectedGoalie
|
gid <- s^.progMode.editGoalieStateL.egsSelectedGoalie
|
||||||
g <- nth gid $ s^.database.dbGoalies
|
g <- nth gid $ s^.database.dbGoalies
|
||||||
Just $ unlines
|
Just $ goalieDetails g ++ "\n"
|
||||||
[ " Goalie number: " ++ show (g^.gNumber)
|
|
||||||
, " Goalie name: " ++ g^.gName
|
|
||||||
, " YTD games played: " ++ show (g^.gYtd.gsGames)
|
|
||||||
, " YTD mins played: " ++ show (g^.gYtd.gsMinsPlayed)
|
|
||||||
, " YTD goals allowed: " ++ show (g^.gYtd.gsGoalsAllowed)
|
|
||||||
, " YTD wins: " ++ show (g^.gYtd.gsWins)
|
|
||||||
, " YTD losses: " ++ show (g^.gYtd.gsLosses)
|
|
||||||
, " YTD ties: " ++ show (g^.gYtd.gsTies)
|
|
||||||
, " Lifetime games played: " ++ show (g^.gLifetime.gsGames)
|
|
||||||
, " Lifetime mins played: " ++ show (g^.gLifetime.gsMinsPlayed)
|
|
||||||
, "Lifetime goals allowed: " ++ show (g^.gLifetime.gsGoalsAllowed)
|
|
||||||
, " Lifetime wins: " ++ show (g^.gLifetime.gsWins)
|
|
||||||
, " Lifetime losses: " ++ show (g^.gLifetime.gsLosses)
|
|
||||||
, " Lifetime ties: " ++ show (g^.gLifetime.gsTies)
|
|
||||||
, ""
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ import Data.Maybe (fromMaybe)
|
|||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
|
||||||
|
import Mtlstats.Helpers.Player
|
||||||
import Mtlstats.Menu
|
import Mtlstats.Menu
|
||||||
|
import Mtlstats.Menu.EditPlayer
|
||||||
import Mtlstats.Prompt
|
import Mtlstats.Prompt
|
||||||
import Mtlstats.Prompt.EditPlayer
|
import Mtlstats.Prompt.EditPlayer
|
||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
@@ -40,6 +42,8 @@ editPlayerC eps
|
|||||||
EPNumber -> numberC
|
EPNumber -> numberC
|
||||||
EPName -> nameC
|
EPName -> nameC
|
||||||
EPPosition -> positionC
|
EPPosition -> positionC
|
||||||
|
EPYtd -> ytdC
|
||||||
|
EPLifetime -> lifetimeC
|
||||||
EPYtdGoals -> ytdGoalsC
|
EPYtdGoals -> ytdGoalsC
|
||||||
EPYtdAssists -> ytdAssistsC
|
EPYtdAssists -> ytdAssistsC
|
||||||
EPYtdPMin -> ytdPMinC
|
EPYtdPMin -> ytdPMinC
|
||||||
@@ -48,96 +52,46 @@ editPlayerC eps
|
|||||||
EPLtPMin -> ltPMinC
|
EPLtPMin -> ltPMinC
|
||||||
|
|
||||||
selectPlayerC :: Controller
|
selectPlayerC :: Controller
|
||||||
selectPlayerC = Controller
|
selectPlayerC = promptController playerToEditPrompt
|
||||||
{ drawController = drawPrompt playerToEditPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler playerToEditPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
menuC :: Controller
|
menuC :: Controller
|
||||||
menuC = Controller
|
menuC = menuControllerWith header editPlayerMenu
|
||||||
{ drawController = \s -> do
|
|
||||||
let
|
|
||||||
header = fromMaybe "" $ do
|
|
||||||
pid <- s^.progMode.editPlayerStateL.epsSelectedPlayer
|
|
||||||
p <- nth pid $ s^.database.dbPlayers
|
|
||||||
Just $ playerDetails p ++ "\n"
|
|
||||||
C.drawString header
|
|
||||||
drawMenu editPlayerMenu
|
|
||||||
, handleController = \e -> do
|
|
||||||
menuHandler editPlayerMenu e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
numberC :: Controller
|
numberC :: Controller
|
||||||
numberC = Controller
|
numberC = promptController editPlayerNumPrompt
|
||||||
{ drawController = drawPrompt editPlayerNumPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerNumPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
nameC :: Controller
|
nameC :: Controller
|
||||||
nameC = Controller
|
nameC = promptController editPlayerNamePrompt
|
||||||
{ drawController = drawPrompt editPlayerNamePrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerNamePrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
positionC :: Controller
|
positionC :: Controller
|
||||||
positionC = Controller
|
positionC = promptController editPlayerPosPrompt
|
||||||
{ drawController = drawPrompt editPlayerPosPrompt
|
|
||||||
, handleController = \e -> do
|
ytdC :: Controller
|
||||||
promptHandler editPlayerPosPrompt e
|
ytdC = menuControllerWith header editPlayerYtdMenu
|
||||||
return True
|
|
||||||
}
|
lifetimeC :: Controller
|
||||||
|
lifetimeC = menuControllerWith header editPlayerLtMenu
|
||||||
|
|
||||||
ytdGoalsC :: Controller
|
ytdGoalsC :: Controller
|
||||||
ytdGoalsC = Controller
|
ytdGoalsC = promptController editPlayerYtdGoalsPrompt
|
||||||
{ drawController = drawPrompt editPlayerYtdGoalsPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerYtdGoalsPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
ytdAssistsC :: Controller
|
ytdAssistsC :: Controller
|
||||||
ytdAssistsC = Controller
|
ytdAssistsC = promptController editPlayerYtdAssistsPrompt
|
||||||
{ drawController = drawPrompt editPlayerYtdAssistsPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerYtdAssistsPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
ytdPMinC :: Controller
|
ytdPMinC :: Controller
|
||||||
ytdPMinC = Controller
|
ytdPMinC = promptController editPlayerYtdPMinPrompt
|
||||||
{ drawController = drawPrompt editPlayerYtdPMinPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerYtdPMinPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
ltGoalsC :: Controller
|
ltGoalsC :: Controller
|
||||||
ltGoalsC = Controller
|
ltGoalsC = promptController editPlayerLtGoalsPrompt
|
||||||
{ drawController = drawPrompt editPlayerLtGoalsPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerLtGoalsPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
ltAssistsC :: Controller
|
ltAssistsC :: Controller
|
||||||
ltAssistsC = Controller
|
ltAssistsC = promptController editPlayerLtAssistsPrompt
|
||||||
{ drawController = drawPrompt editPlayerLtAssistsPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler editPlayerLtAssistsPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
ltPMinC :: Controller
|
ltPMinC :: Controller
|
||||||
ltPMinC = Controller
|
ltPMinC = promptController editPlayerLtPMinPrompt
|
||||||
{ drawController = drawPrompt editPlayerLtPMinPrompt
|
|
||||||
, handleController = \e -> do
|
header :: ProgState -> C.Update ()
|
||||||
promptHandler editPlayerLtPMinPrompt e
|
header s = C.drawString $ fromMaybe "" $ do
|
||||||
return True
|
pid <- s^.progMode.editPlayerStateL.epsSelectedPlayer
|
||||||
}
|
player <- nth pid $ s^.database.dbPlayers
|
||||||
|
Just $ playerDetails player ++ "\n"
|
||||||
|
|||||||
@@ -39,95 +39,43 @@ import Mtlstats.Types
|
|||||||
import Mtlstats.Util
|
import Mtlstats.Util
|
||||||
|
|
||||||
-- | Dispatcher for a new game
|
-- | Dispatcher for a new game
|
||||||
newGameC :: ProgState -> Controller
|
newGameC :: GameState -> Controller
|
||||||
newGameC s = let
|
newGameC gs
|
||||||
gs = s^.progMode.gameStateL
|
| null $ gs^.gameYear = gameYearC
|
||||||
in if null $ gs^.gameYear then gameYearC
|
| null $ gs^.gameMonth = gameMonthC
|
||||||
else if null $ gs^.gameMonth then gameMonthC
|
| null $ gs^.gameDay = gameDayC
|
||||||
else if null $ gs^.gameDay then gameDayC
|
| null $ gs^.gameType = gameTypeC
|
||||||
else if null $ gs^.gameType then gameTypeC
|
| null $ gs^.otherTeam = otherTeamC
|
||||||
else if null $ gs^.otherTeam then otherTeamC
|
| null $ gs^.homeScore = homeScoreC
|
||||||
else if null $ gs^.homeScore then homeScoreC
|
| null $ gs^.awayScore = awayScoreC
|
||||||
else if null $ gs^.awayScore then awayScoreC
|
| null $ gs^.overtimeFlag = overtimeFlagC
|
||||||
else if null $ gs^.overtimeFlag then overtimeFlagC
|
| not $ gs^.dataVerified = verifyDataC
|
||||||
else if not $ gs^.dataVerified then verifyDataC
|
| fromJust (unaccountedPoints gs) = goalInput gs
|
||||||
else if fromJust (unaccountedPoints gs) then goalInput gs
|
| isJust $ gs^.gameSelectedPlayer = getPMinsC
|
||||||
else if isJust $ gs^.gameSelectedPlayer then getPMinsC
|
| not $ gs^.gamePMinsRecorded = pMinPlayerC
|
||||||
else if not $ gs^.gamePMinsRecorded then pMinPlayerC
|
| not $ gs^.gameGoalieAssigned = goalieInputC gs
|
||||||
else if not $ gs^.gameGoalieAssigned then goalieInputC s
|
| otherwise = reportC
|
||||||
else reportC
|
|
||||||
|
|
||||||
gameYearC :: Controller
|
gameYearC :: Controller
|
||||||
gameYearC = Controller
|
gameYearC = promptControllerWith header gameYearPrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt gameYearPrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler gameYearPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
gameMonthC :: Controller
|
gameMonthC :: Controller
|
||||||
gameMonthC = Controller
|
gameMonthC = menuControllerWith header gameMonthMenu
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawMenu gameMonthMenu
|
|
||||||
, handleController = \e -> do
|
|
||||||
menuHandler gameMonthMenu e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
gameDayC :: Controller
|
gameDayC :: Controller
|
||||||
gameDayC = Controller
|
gameDayC = promptControllerWith header gameDayPrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt gameDayPrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler gameDayPrompt e
|
|
||||||
modify validateGameDate
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
gameTypeC :: Controller
|
gameTypeC :: Controller
|
||||||
gameTypeC = Controller
|
gameTypeC = menuControllerWith header gameTypeMenu
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawMenu gameTypeMenu
|
|
||||||
, handleController = \e -> do
|
|
||||||
menuHandler gameTypeMenu e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
otherTeamC :: Controller
|
otherTeamC :: Controller
|
||||||
otherTeamC = Controller
|
otherTeamC = promptControllerWith header otherTeamPrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt otherTeamPrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler otherTeamPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
homeScoreC :: Controller
|
homeScoreC :: Controller
|
||||||
homeScoreC = Controller
|
homeScoreC = promptControllerWith header homeScorePrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt homeScorePrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler homeScorePrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
awayScoreC :: Controller
|
awayScoreC :: Controller
|
||||||
awayScoreC = Controller
|
awayScoreC = promptControllerWith header awayScorePrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt awayScorePrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler awayScorePrompt e
|
|
||||||
modify overtimeCheck
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
overtimeFlagC :: Controller
|
overtimeFlagC :: Controller
|
||||||
overtimeFlagC = Controller
|
overtimeFlagC = Controller
|
||||||
@@ -146,19 +94,22 @@ verifyDataC = Controller
|
|||||||
let gs = s^.progMode.gameStateL
|
let gs = s^.progMode.gameStateL
|
||||||
header s
|
header s
|
||||||
C.drawString "\n"
|
C.drawString "\n"
|
||||||
C.drawString $ " Date: " ++ gameDate gs ++ "\n"
|
C.drawString $ unlines $ labelTable
|
||||||
C.drawString $ " Game type: " ++ show (fromJust $ gs^.gameType) ++ "\n"
|
[ ( "Date", gameDate gs )
|
||||||
C.drawString $ "Other team: " ++ gs^.otherTeam ++ "\n"
|
, ( "Game type", show $ fromJust $ gs^.gameType )
|
||||||
C.drawString $ "Home score: " ++ show (fromJust $ gs^.homeScore) ++ "\n"
|
, ( "Other team", gs^.otherTeam )
|
||||||
C.drawString $ "Away score: " ++ show (fromJust $ gs^.awayScore) ++ "\n"
|
, ( "Home score", show $ fromJust $ gs^.homeScore )
|
||||||
C.drawString $ " Overtime: " ++ show (fromJust $ gs^.overtimeFlag) ++ "\n\n"
|
, ( "Away score", show $ fromJust $ gs^.awayScore )
|
||||||
C.drawString "Is the above information correct? (Y/N)"
|
, ( "Overtime", show $ fromJust $ gs^.overtimeFlag )
|
||||||
|
]
|
||||||
|
C.drawString "\nIs the above information correct? (Y/N)"
|
||||||
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
|
||||||
|
|||||||
@@ -33,16 +33,12 @@ import Mtlstats.Types
|
|||||||
import Mtlstats.Util
|
import Mtlstats.Util
|
||||||
|
|
||||||
-- | The dispatcher for handling goalie input
|
-- | The dispatcher for handling goalie input
|
||||||
goalieInputC :: ProgState -> Controller
|
goalieInputC :: GameState -> Controller
|
||||||
goalieInputC s = let
|
goalieInputC gs
|
||||||
gs = s^.progMode.gameStateL
|
| gs^.gameGoaliesRecorded = selectGameGoalieC
|
||||||
in if gs^.gameGoaliesRecorded
|
| null $ gs^.gameSelectedGoalie = selectGoalieC
|
||||||
then selectGameGoalieC s
|
| null $ gs^.gameGoalieMinsPlayed = minsPlayedC
|
||||||
else if null $ gs^.gameSelectedGoalie
|
| otherwise = goalsAllowedC
|
||||||
then selectGoalieC
|
|
||||||
else if null $ gs^.gameGoalieMinsPlayed
|
|
||||||
then minsPlayedC
|
|
||||||
else goalsAllowedC
|
|
||||||
|
|
||||||
selectGoalieC :: Controller
|
selectGoalieC :: Controller
|
||||||
selectGoalieC = promptController selectGameGoaliePrompt
|
selectGoalieC = promptController selectGameGoaliePrompt
|
||||||
@@ -53,8 +49,8 @@ minsPlayedC = promptControllerWith header goalieMinsPlayedPrompt
|
|||||||
goalsAllowedC :: Controller
|
goalsAllowedC :: Controller
|
||||||
goalsAllowedC = promptControllerWith header goalsAllowedPrompt
|
goalsAllowedC = promptControllerWith header goalsAllowedPrompt
|
||||||
|
|
||||||
selectGameGoalieC :: ProgState -> Controller
|
selectGameGoalieC :: Controller
|
||||||
selectGameGoalieC = menuController . gameGoalieMenu
|
selectGameGoalieC = menuStateController gameGoalieMenu
|
||||||
|
|
||||||
header :: ProgState -> C.Update ()
|
header :: ProgState -> C.Update ()
|
||||||
header s = C.drawString $ unlines
|
header s = C.drawString $ unlines
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
|
|
||||||
module Mtlstats.Format
|
module Mtlstats.Format
|
||||||
( padNum
|
( padNum
|
||||||
, left
|
, left
|
||||||
@@ -26,8 +28,18 @@ module Mtlstats.Format
|
|||||||
, centre
|
, centre
|
||||||
, overlay
|
, overlay
|
||||||
, month
|
, month
|
||||||
|
, labelTable
|
||||||
|
, numTable
|
||||||
|
, tableWith
|
||||||
|
, complexTable
|
||||||
|
, overlayLast
|
||||||
|
, showFloating
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Data.List (transpose)
|
||||||
|
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
-- | Pad an 'Int' with leading zeroes to fit a certain character width
|
-- | Pad an 'Int' with leading zeroes to fit a certain character width
|
||||||
padNum
|
padNum
|
||||||
:: Int
|
:: Int
|
||||||
@@ -101,3 +113,84 @@ month 10 = "OCT"
|
|||||||
month 11 = "NOV"
|
month 11 = "NOV"
|
||||||
month 12 = "DEC"
|
month 12 = "DEC"
|
||||||
month _ = ""
|
month _ = ""
|
||||||
|
|
||||||
|
-- | Creates a two-column table with labels
|
||||||
|
labelTable :: [(String, String)] -> [String]
|
||||||
|
labelTable xs = let
|
||||||
|
labelWidth = maximum $ map (length . fst) xs
|
||||||
|
in map
|
||||||
|
(\(label, val) -> right labelWidth label ++ ": " ++ val)
|
||||||
|
xs
|
||||||
|
|
||||||
|
-- | Creates a variable column table of numbers with two axes
|
||||||
|
numTable
|
||||||
|
:: [String]
|
||||||
|
-- ^ The top column labels
|
||||||
|
-> [(String, [Int])]
|
||||||
|
-- ^ The rows with their labels
|
||||||
|
-> [String]
|
||||||
|
numTable headers rows = tableWith right $ header : body
|
||||||
|
where
|
||||||
|
header = "" : headers
|
||||||
|
body = map
|
||||||
|
(\(label, row) ->
|
||||||
|
label : map show row)
|
||||||
|
rows
|
||||||
|
|
||||||
|
-- | Creates a table from a two-dimensional list with a specified
|
||||||
|
-- padding function
|
||||||
|
tableWith
|
||||||
|
:: (Int -> String -> String)
|
||||||
|
-- ^ The padding function
|
||||||
|
-> [[String]]
|
||||||
|
-- ^ The cells
|
||||||
|
-> [String]
|
||||||
|
tableWith pFunc tData = complexTable
|
||||||
|
(repeat pFunc)
|
||||||
|
(map (map CellText) tData)
|
||||||
|
|
||||||
|
-- | Creates a complex table
|
||||||
|
complexTable
|
||||||
|
:: [Int -> String -> String]
|
||||||
|
-- ^ The padding function for each column
|
||||||
|
-> [[TableCell]]
|
||||||
|
-- ^ The table cells (an array of rows)
|
||||||
|
-> [String]
|
||||||
|
complexTable pFuncs tData = let
|
||||||
|
widths = map
|
||||||
|
(map $ \case
|
||||||
|
CellText str -> length str
|
||||||
|
CellFill _ -> 0)
|
||||||
|
tData
|
||||||
|
colWidths = map maximum $ transpose widths
|
||||||
|
|
||||||
|
bFunc = \case
|
||||||
|
[] -> ""
|
||||||
|
[(f, len, CellText str)] -> f len str
|
||||||
|
[(_, len, CellFill ch)] -> replicate len ch
|
||||||
|
(f, len, CellText str) : cells -> f len str ++ " " ++ bFunc cells
|
||||||
|
(_, len, CellFill ch) : cells -> replicate (succ len) ch ++ bFunc cells
|
||||||
|
|
||||||
|
in map
|
||||||
|
(bFunc . zip3 pFuncs colWidths)
|
||||||
|
tData
|
||||||
|
|
||||||
|
-- | Places an overlay on the last line of an report
|
||||||
|
overlayLast
|
||||||
|
:: String
|
||||||
|
-- ^ The text to overlay
|
||||||
|
-> [String]
|
||||||
|
-- ^ The report to modify
|
||||||
|
-> [String]
|
||||||
|
-- ^ The resulting report
|
||||||
|
overlayLast _ [] = []
|
||||||
|
overlayLast str [l] = [overlay str l]
|
||||||
|
overlayLast str (l:ls) = l : overlayLast str ls
|
||||||
|
|
||||||
|
-- | Converts a non-integer into a string
|
||||||
|
showFloating :: RealFrac n => n -> String
|
||||||
|
showFloating n = let
|
||||||
|
i = round $ n * 100
|
||||||
|
whole = i `div` 100
|
||||||
|
fraction = i `mod` 100
|
||||||
|
in show whole ++ "." ++ padNum 2 fraction
|
||||||
|
|||||||
47
src/Mtlstats/Helpers/Goalie.hs
Normal file
47
src/Mtlstats/Helpers/Goalie.hs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{- |
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 2019 Rhéal Lamothe
|
||||||
|
<rheal.lamothe@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Mtlstats.Helpers.Goalie (goalieDetails) where
|
||||||
|
|
||||||
|
import Lens.Micro ((^.))
|
||||||
|
|
||||||
|
import Mtlstats.Format
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
|
-- | Provides a detailed 'String' describing a 'Goalie'
|
||||||
|
goalieDetails :: Goalie -> String
|
||||||
|
goalieDetails g = let
|
||||||
|
header = unlines $ labelTable
|
||||||
|
[ ( "Number", show $ g^.gNumber )
|
||||||
|
, ( "Name", g^.gName )
|
||||||
|
]
|
||||||
|
|
||||||
|
body = unlines $ numTable ["YTD", "Lifetime"] $ map
|
||||||
|
(\(label, lens) -> (label, [g^.gYtd.lens, g^.gLifetime.lens]))
|
||||||
|
[ ( "Games played", gsGames )
|
||||||
|
, ( "Mins played", gsMinsPlayed )
|
||||||
|
, ( "Goals allowed", gsGoalsAllowed )
|
||||||
|
, ( "Wins", gsWins )
|
||||||
|
, ( "Losses", gsLosses )
|
||||||
|
, ( "Ties", gsTies )
|
||||||
|
]
|
||||||
|
|
||||||
|
in header ++ "\n" ++ body
|
||||||
45
src/Mtlstats/Helpers/Player.hs
Normal file
45
src/Mtlstats/Helpers/Player.hs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{- |
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 2019 Rhéal Lamothe
|
||||||
|
<rheal.lamothe@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Mtlstats.Helpers.Player (playerDetails) where
|
||||||
|
|
||||||
|
import Lens.Micro ((^.))
|
||||||
|
|
||||||
|
import Mtlstats.Format
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
|
-- | Provides a detailed string describing a 'Player'
|
||||||
|
playerDetails :: Player -> String
|
||||||
|
playerDetails p = unlines $ top ++ [""] ++ table
|
||||||
|
where
|
||||||
|
top = labelTable
|
||||||
|
[ ( "Number", show $ p^.pNumber )
|
||||||
|
, ( "Name", p^.pName )
|
||||||
|
, ( "Position", p^.pPosition )
|
||||||
|
]
|
||||||
|
|
||||||
|
table = numTable ["YTD", "Lifetime"] $ map
|
||||||
|
(\(label, lens) ->
|
||||||
|
(label, [p^.pYtd.lens, p^.pLifetime.lens]))
|
||||||
|
[ ( "Goals", psGoals )
|
||||||
|
, ( "Assists", psAssists )
|
||||||
|
, ( "Penalty mins", psPMin )
|
||||||
|
]
|
||||||
@@ -23,6 +23,7 @@ module Mtlstats.Menu (
|
|||||||
-- * Menu Functions
|
-- * Menu Functions
|
||||||
menuController,
|
menuController,
|
||||||
menuControllerWith,
|
menuControllerWith,
|
||||||
|
menuStateController,
|
||||||
drawMenu,
|
drawMenu,
|
||||||
menuHandler,
|
menuHandler,
|
||||||
-- * Menus
|
-- * Menus
|
||||||
@@ -30,7 +31,6 @@ module Mtlstats.Menu (
|
|||||||
newSeasonMenu,
|
newSeasonMenu,
|
||||||
gameMonthMenu,
|
gameMonthMenu,
|
||||||
gameTypeMenu,
|
gameTypeMenu,
|
||||||
editPlayerMenu,
|
|
||||||
gameGoalieMenu
|
gameGoalieMenu
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ import Data.Aeson (encodeFile)
|
|||||||
import Data.Char (toUpper)
|
import Data.Char (toUpper)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Maybe (mapMaybe)
|
import Data.Maybe (mapMaybe)
|
||||||
import Lens.Micro ((^.), (.~), (?~))
|
import Lens.Micro ((^.), (?~))
|
||||||
import Lens.Micro.Extras (view)
|
import Lens.Micro.Extras (view)
|
||||||
import System.EasyFile
|
import System.EasyFile
|
||||||
( createDirectoryIfMissing
|
( createDirectoryIfMissing
|
||||||
@@ -77,6 +77,21 @@ menuControllerWith header menu = Controller
|
|||||||
return True
|
return True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Generate and create a controller for a menu based on the current
|
||||||
|
-- 'ProgState'
|
||||||
|
menuStateController
|
||||||
|
:: (ProgState -> Menu ())
|
||||||
|
-- ^ The function to generate the menu
|
||||||
|
-> Controller
|
||||||
|
-- ^ The resulting controller
|
||||||
|
menuStateController menuFunc = Controller
|
||||||
|
{ drawController = drawMenu . menuFunc
|
||||||
|
, handleController = \e -> do
|
||||||
|
menu <- gets menuFunc
|
||||||
|
menuHandler menu e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
-- | The draw function for a 'Menu'
|
-- | The draw function for a 'Menu'
|
||||||
drawMenu :: Menu a -> C.Update C.CursorMode
|
drawMenu :: Menu a -> C.Update C.CursorMode
|
||||||
drawMenu m = do
|
drawMenu m = do
|
||||||
@@ -157,24 +172,6 @@ gameTypeMenu = Menu "Game type:" ()
|
|||||||
modify $ progMode.gameStateL.gameType ?~ AwayGame
|
modify $ progMode.gameStateL.gameType ?~ AwayGame
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | The player edit menu
|
|
||||||
editPlayerMenu :: Menu ()
|
|
||||||
editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
|
|
||||||
(\(ch, label, mode) -> MenuItem ch label $ case mode of
|
|
||||||
Nothing -> modify $ progMode .~ MainMenu
|
|
||||||
Just m -> modify $ progMode.editPlayerStateL.epsMode .~ m)
|
|
||||||
[ ( '1', "Change number", Just EPNumber )
|
|
||||||
, ( '2', "Change name", Just EPName )
|
|
||||||
, ( '3', "Change position", Just EPPosition )
|
|
||||||
, ( '4', "YTD goals", Just EPYtdGoals )
|
|
||||||
, ( '5', "YTD assists", Just EPYtdAssists )
|
|
||||||
, ( '6', "YTD penalty mins", Just EPYtdPMin )
|
|
||||||
, ( '7', "Lifetime goals", Just EPLtGoals )
|
|
||||||
, ( '8', "Lifetime assists", Just EPLtAssists )
|
|
||||||
, ( '9', "Lifetime penalty mins", Just EPLtPMin )
|
|
||||||
, ( '0', "Finished editing", Nothing )
|
|
||||||
]
|
|
||||||
|
|
||||||
-- | Game goalie selection menu
|
-- | Game goalie selection menu
|
||||||
gameGoalieMenu :: ProgState -> Menu ()
|
gameGoalieMenu :: ProgState -> Menu ()
|
||||||
gameGoalieMenu s = let
|
gameGoalieMenu s = let
|
||||||
|
|||||||
74
src/Mtlstats/Menu/EditPlayer.hs
Normal file
74
src/Mtlstats/Menu/EditPlayer.hs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
{- |
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 2019 Rhéal Lamothe
|
||||||
|
<rheal.lamothe@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Mtlstats.Menu.EditPlayer
|
||||||
|
( editPlayerMenu
|
||||||
|
, editPlayerYtdMenu
|
||||||
|
, editPlayerLtMenu
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Control.Monad.Trans.State (modify)
|
||||||
|
import Lens.Micro ((.~))
|
||||||
|
|
||||||
|
import Mtlstats.Types
|
||||||
|
import Mtlstats.Types.Menu
|
||||||
|
|
||||||
|
-- | The 'Player' edit menu
|
||||||
|
editPlayerMenu :: Menu ()
|
||||||
|
editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
|
||||||
|
(\(ch, label, mode) -> MenuItem ch label $ case mode of
|
||||||
|
Nothing -> modify $ progMode .~ MainMenu
|
||||||
|
Just m -> modify $ progMode.editPlayerStateL.epsMode .~ m)
|
||||||
|
-- key, label, value
|
||||||
|
[ ( '1', "Edit number", Just EPNumber )
|
||||||
|
, ( '2', "Edit name", Just EPName )
|
||||||
|
, ( '3', "Edit position", Just EPPosition )
|
||||||
|
, ( '4', "Edit YTD stats", Just EPYtd )
|
||||||
|
, ( '5', "Edit lifetime stats", Just EPLifetime )
|
||||||
|
, ( 'R', "Finished editing", Nothing )
|
||||||
|
]
|
||||||
|
|
||||||
|
-- | The 'Player' YTD stats edit menu
|
||||||
|
editPlayerYtdMenu :: Menu ()
|
||||||
|
editPlayerYtdMenu = editMenu
|
||||||
|
"*** EDIT PLAYER YEAR-TO-DATE ***"
|
||||||
|
-- key, label, value
|
||||||
|
[ ( '1', "Edit YTD goals", EPYtdGoals )
|
||||||
|
, ( '2', "Edit YTD assists", EPYtdAssists )
|
||||||
|
, ( '3', "Edit YTD penalty mins", EPYtdPMin )
|
||||||
|
, ( 'R', "Return to player edit menu", EPMenu )
|
||||||
|
]
|
||||||
|
|
||||||
|
-- | The 'Player' lifetime stats edit menu
|
||||||
|
editPlayerLtMenu :: Menu ()
|
||||||
|
editPlayerLtMenu = editMenu
|
||||||
|
"*** EDIT PLAYER LIFETIME ***"
|
||||||
|
-- key, label, value
|
||||||
|
[ ( '1', "Edit lifetime goals", EPLtGoals )
|
||||||
|
, ( '2', "Edit lifetime assits", EPLtAssists )
|
||||||
|
, ( '3', "Edit lifetime penalty mins", EPLtPMin )
|
||||||
|
, ( 'R', "Return to edit player menu", EPMenu )
|
||||||
|
]
|
||||||
|
|
||||||
|
editMenu :: String -> [(Char, String, EditPlayerMode)] -> Menu ()
|
||||||
|
editMenu title = Menu title () . map
|
||||||
|
(\(key, label, val) -> MenuItem key label $
|
||||||
|
modify $ progMode.editPlayerStateL.epsMode .~ val)
|
||||||
@@ -28,6 +28,7 @@ module Mtlstats.Prompt (
|
|||||||
promptControllerWith,
|
promptControllerWith,
|
||||||
promptController,
|
promptController,
|
||||||
strPrompt,
|
strPrompt,
|
||||||
|
ucStrPrompt,
|
||||||
numPrompt,
|
numPrompt,
|
||||||
selectPrompt,
|
selectPrompt,
|
||||||
-- * Individual prompts
|
-- * Individual prompts
|
||||||
@@ -46,7 +47,7 @@ import Control.Monad.Extra (whenJust)
|
|||||||
import Control.Monad.Trans.State (gets, modify)
|
import Control.Monad.Trans.State (gets, modify)
|
||||||
import Data.Char (isDigit, toUpper)
|
import Data.Char (isDigit, toUpper)
|
||||||
import Data.Foldable (forM_)
|
import Data.Foldable (forM_)
|
||||||
import Lens.Micro ((^.), (&), (.~), (?~))
|
import Lens.Micro ((^.), (&), (.~), (?~), (%~))
|
||||||
import Lens.Micro.Extras (view)
|
import Lens.Micro.Extras (view)
|
||||||
import Text.Read (readMaybe)
|
import Text.Read (readMaybe)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
@@ -68,10 +69,8 @@ promptHandler p (C.EventCharacter '\n') = do
|
|||||||
val <- gets $ view inputBuffer
|
val <- gets $ view inputBuffer
|
||||||
modify $ inputBuffer .~ ""
|
modify $ inputBuffer .~ ""
|
||||||
promptAction p val
|
promptAction p val
|
||||||
promptHandler p (C.EventCharacter c) = let
|
promptHandler p (C.EventCharacter c) =
|
||||||
c' = toUpper c
|
modify $ inputBuffer %~ promptProcessChar p c
|
||||||
in when (promptCharCheck p c') $
|
|
||||||
modify $ addChar c'
|
|
||||||
promptHandler _ (C.EventSpecialKey C.KeyBackspace) =
|
promptHandler _ (C.EventSpecialKey C.KeyBackspace) =
|
||||||
modify removeChar
|
modify removeChar
|
||||||
promptHandler p (C.EventSpecialKey k) =
|
promptHandler p (C.EventSpecialKey k) =
|
||||||
@@ -111,12 +110,22 @@ strPrompt
|
|||||||
-- ^ The callback function for the result
|
-- ^ The callback function for the result
|
||||||
-> Prompt
|
-> Prompt
|
||||||
strPrompt pStr act = Prompt
|
strPrompt pStr act = Prompt
|
||||||
{ promptDrawer = drawSimplePrompt pStr
|
{ promptDrawer = drawSimplePrompt pStr
|
||||||
, promptCharCheck = const True
|
, promptProcessChar = \ch -> (++ [ch])
|
||||||
, promptAction = act
|
, promptAction = act
|
||||||
, promptSpecialKey = const $ return ()
|
, promptSpecialKey = const $ return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Creates an upper case string prompt
|
||||||
|
ucStrPrompt
|
||||||
|
:: String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (String -> Action ())
|
||||||
|
-- ^ The callback function for the result
|
||||||
|
-> Prompt
|
||||||
|
ucStrPrompt pStr act = (strPrompt pStr act)
|
||||||
|
{ promptProcessChar = \ch -> (++ [toUpper ch]) }
|
||||||
|
|
||||||
-- | Builds a numeric prompt
|
-- | Builds a numeric prompt
|
||||||
numPrompt
|
numPrompt
|
||||||
:: String
|
:: String
|
||||||
@@ -125,10 +134,12 @@ numPrompt
|
|||||||
-- ^ The callback function for the result
|
-- ^ The callback function for the result
|
||||||
-> Prompt
|
-> Prompt
|
||||||
numPrompt pStr act = Prompt
|
numPrompt pStr act = Prompt
|
||||||
{ promptDrawer = drawSimplePrompt pStr
|
{ promptDrawer = drawSimplePrompt pStr
|
||||||
, promptCharCheck = isDigit
|
, promptProcessChar = \ch str -> if isDigit ch
|
||||||
, promptAction = \inStr -> forM_ (readMaybe inStr) act
|
then str ++ [ch]
|
||||||
, promptSpecialKey = const $ return ()
|
else str
|
||||||
|
, promptAction = \inStr -> forM_ (readMaybe inStr) act
|
||||||
|
, promptSpecialKey = const $ return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Builds a selection prompt
|
-- | Builds a selection prompt
|
||||||
@@ -146,7 +157,7 @@ selectPrompt params = Prompt
|
|||||||
in "F" ++ show n ++ ") " ++ desc)
|
in "F" ++ show n ++ ") " ++ desc)
|
||||||
results
|
results
|
||||||
C.moveCursor row col
|
C.moveCursor row col
|
||||||
, promptCharCheck = const True
|
, promptProcessChar = \ch -> (++[ch])
|
||||||
, promptAction = \sStr -> if null sStr
|
, promptAction = \sStr -> if null sStr
|
||||||
then spCallback params Nothing
|
then spCallback params Nothing
|
||||||
else do
|
else do
|
||||||
@@ -180,7 +191,7 @@ playerNamePrompt = strPrompt "Player name: " $
|
|||||||
|
|
||||||
-- | Prompts for a new player's position
|
-- | Prompts for a new player's position
|
||||||
playerPosPrompt :: Prompt
|
playerPosPrompt :: Prompt
|
||||||
playerPosPrompt = strPrompt "Player position: " $
|
playerPosPrompt = ucStrPrompt "Player position: " $
|
||||||
modify . (progMode.createPlayerStateL.cpsPosition .~)
|
modify . (progMode.createPlayerStateL.cpsPosition .~)
|
||||||
|
|
||||||
-- | Prompts tor the goalie's number
|
-- | Prompts tor the goalie's number
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ editPlayerNamePrompt = strPrompt "Player name: " $
|
|||||||
|
|
||||||
-- | Prompt to edit a player's position
|
-- | Prompt to edit a player's position
|
||||||
editPlayerPosPrompt :: Prompt
|
editPlayerPosPrompt :: Prompt
|
||||||
editPlayerPosPrompt = strPrompt "Player position: " $
|
editPlayerPosPrompt = ucStrPrompt "Player position: " $
|
||||||
editPlayer . (pPosition .~)
|
editPlayer . (pPosition .~)
|
||||||
|
|
||||||
-- | Prompt to edit a player's year-to-date goals
|
-- | Prompt to edit a player's year-to-date goals
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ gameDayPrompt = numPrompt "Day of month: " $
|
|||||||
|
|
||||||
-- | Prompts for the other team name
|
-- | Prompts for the other team name
|
||||||
otherTeamPrompt :: Prompt
|
otherTeamPrompt :: Prompt
|
||||||
otherTeamPrompt = strPrompt "Other team: " $
|
otherTeamPrompt = ucStrPrompt "Other team: " $
|
||||||
modify . (progMode.gameStateL.otherTeam .~)
|
modify . (progMode.gameStateL.otherTeam .~)
|
||||||
|
|
||||||
-- | Prompts for the home score
|
-- | Prompts for the home score
|
||||||
@@ -65,8 +65,9 @@ homeScorePrompt = numPrompt "Home score: " $
|
|||||||
|
|
||||||
-- | Prompts for the away score
|
-- | Prompts for the away score
|
||||||
awayScorePrompt :: Prompt
|
awayScorePrompt :: Prompt
|
||||||
awayScorePrompt = numPrompt "Away score: " $
|
awayScorePrompt = numPrompt "Away score: " $ \score -> modify
|
||||||
modify . (progMode.gameStateL.awayScore ?~)
|
$ overtimeCheck
|
||||||
|
. (progMode.gameStateL.awayScore ?~ score)
|
||||||
|
|
||||||
-- | Prompts for the player who scored the goal
|
-- | Prompts for the player who scored the goal
|
||||||
recordGoalPrompt
|
recordGoalPrompt
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Mtlstats.Report (report, gameDate, playerNameColWidth) where
|
module Mtlstats.Report (report, gameDate) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe, mapMaybe)
|
||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
|
|
||||||
import Mtlstats.Config
|
import Mtlstats.Config
|
||||||
@@ -60,54 +60,106 @@ standingsReport width s = fromMaybe [] $ do
|
|||||||
tStats = addGameStats hStats aStats
|
tStats = addGameStats hStats aStats
|
||||||
hScore <- gs^.homeScore
|
hScore <- gs^.homeScore
|
||||||
aScore <- gs^.awayScore
|
aScore <- gs^.awayScore
|
||||||
Just
|
let
|
||||||
[ overlay
|
rHeader =
|
||||||
("GAME NUMBER " ++ padNum 2 gNum)
|
[ overlay
|
||||||
(centre width
|
("GAME NUMBER " ++ padNum 2 gNum)
|
||||||
$ aTeam ++ " " ++ show aScore ++ " AT "
|
(centre width
|
||||||
++ hTeam ++ " " ++ show hScore)
|
$ aTeam ++ " " ++ show aScore ++ " AT "
|
||||||
, date
|
++ hTeam ++ " " ++ show hScore)
|
||||||
, centre width "STANDINGS"
|
, date
|
||||||
, ""
|
, centre width "STANDINGS"
|
||||||
, centre width
|
, ""
|
||||||
$ left 11 myTeam
|
]
|
||||||
++ right 2 "G"
|
|
||||||
++ right 4 "W"
|
tHeader =
|
||||||
++ right 4 "L"
|
[ CellText myTeam
|
||||||
++ right 4 "OT"
|
, CellText " G"
|
||||||
++ right 4 "GF"
|
, CellText " W"
|
||||||
++ right 4 "GA"
|
, CellText " L"
|
||||||
++ right 4 "P"
|
, CellText " OT"
|
||||||
, centre width
|
, CellText " GF"
|
||||||
$ left 11 "HOME"
|
, CellText " GA"
|
||||||
++ showStats hStats
|
, CellText " P"
|
||||||
, centre width
|
]
|
||||||
$ left 11 "ROAD"
|
|
||||||
++ showStats aStats
|
rowCells stats =
|
||||||
, centre width
|
[ CellText $ show $ gmsGames stats
|
||||||
$ replicate 11 ' '
|
, CellText $ show $ stats^.gmsWins
|
||||||
++ replicate (2 + 4 * 6) '-'
|
, CellText $ show $ stats^.gmsLosses
|
||||||
, centre width
|
, CellText $ show $ stats^.gmsOvertime
|
||||||
$ left 11 "TOTALS"
|
, CellText $ show $ stats^.gmsGoalsFor
|
||||||
++ showStats tStats
|
, CellText $ show $ stats^.gmsGoalsAgainst
|
||||||
]
|
, CellText $ show $ gmsPoints stats
|
||||||
|
]
|
||||||
|
|
||||||
|
body =
|
||||||
|
[ CellText "HOME" : rowCells hStats
|
||||||
|
, CellText "ROAD" : rowCells aStats
|
||||||
|
]
|
||||||
|
|
||||||
|
separator = CellText "" : replicate 7 (CellFill '-')
|
||||||
|
totals = CellText "TOTALS" : rowCells tStats
|
||||||
|
|
||||||
|
table = map (centre width) $
|
||||||
|
complexTable
|
||||||
|
(left : repeat right)
|
||||||
|
(tHeader : body ++ [separator, totals])
|
||||||
|
|
||||||
|
Just $ rHeader ++ table
|
||||||
|
|
||||||
gameStatsReport :: Int -> ProgState -> [String]
|
gameStatsReport :: Int -> ProgState -> [String]
|
||||||
gameStatsReport width s = playerReport width "GAME" $
|
gameStatsReport width s = let
|
||||||
fromMaybe [] $ mapM
|
gs = s^.progMode.gameStateL
|
||||||
|
db = s^.database
|
||||||
|
|
||||||
|
playerStats = mapMaybe
|
||||||
(\(pid, stats) -> do
|
(\(pid, stats) -> do
|
||||||
p <- nth pid $ s^.database.dbPlayers
|
p <- nth pid $ db^.dbPlayers
|
||||||
Just (p, stats))
|
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)
|
||||||
|
|
||||||
|
criteria (_, ps) = psPoints ps > 0
|
||||||
|
|
||||||
|
in filteredPlayerReport width "GAME" criteria playerStats
|
||||||
|
++ [""]
|
||||||
|
++ gameGoalieReport width goalieStats
|
||||||
|
|
||||||
yearToDateStatsReport :: Int -> ProgState -> [String]
|
yearToDateStatsReport :: Int -> ProgState -> [String]
|
||||||
yearToDateStatsReport width s = playerReport width "YEAR TO DATE" $
|
yearToDateStatsReport width s = let
|
||||||
map (\p -> (p, p^.pYtd)) $
|
db = s^.database
|
||||||
filter playerIsActive $ s^.database.dbPlayers
|
|
||||||
|
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 :: Int -> ProgState -> [String]
|
||||||
lifetimeStatsReport width s = playerReport width "LIFETIME" $
|
lifetimeStatsReport width s = let
|
||||||
map (\p -> (p, p^.pLifetime)) $ s^.database.dbPlayers
|
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 :: GameState -> String
|
||||||
gameDate gs = fromMaybe "" $ do
|
gameDate gs = fromMaybe "" $ do
|
||||||
@@ -117,54 +169,124 @@ gameDate gs = fromMaybe "" $ do
|
|||||||
Just $ m ++ " " ++ d ++ " " ++ y
|
Just $ m ++ " " ++ d ++ " " ++ y
|
||||||
|
|
||||||
playerReport :: Int -> String -> [(Player, PlayerStats)] -> [String]
|
playerReport :: Int -> String -> [(Player, PlayerStats)] -> [String]
|
||||||
playerReport width label ps = let
|
playerReport width label ps =
|
||||||
nameWidth = playerNameColWidth $ map fst ps
|
filteredPlayerReport width label (const True) ps
|
||||||
tStats = foldr (addPlayerStats . snd) newPlayerStats ps
|
|
||||||
in
|
filteredPlayerReport
|
||||||
|
:: Int
|
||||||
|
-> String
|
||||||
|
-> ((Player, PlayerStats) -> Bool)
|
||||||
|
-> [(Player, PlayerStats)]
|
||||||
|
-> [String]
|
||||||
|
filteredPlayerReport width label criteria ps = let
|
||||||
|
tStats = foldl addPlayerStats newPlayerStats $ map snd ps
|
||||||
|
fps = filter criteria ps
|
||||||
|
|
||||||
|
rHeader =
|
||||||
[ centre width (label ++ " STATISTICS")
|
[ centre width (label ++ " STATISTICS")
|
||||||
, ""
|
, ""
|
||||||
, centre width
|
|
||||||
$ "NO. "
|
|
||||||
++ left nameWidth "PLAYER"
|
|
||||||
++ right 3 "G"
|
|
||||||
++ right 6 "A"
|
|
||||||
++ right 6 "P"
|
|
||||||
++ right 6 "PM"
|
|
||||||
] ++ map
|
|
||||||
(\(p, stats) -> centre width
|
|
||||||
$ right 2 (show $ p^.pNumber)
|
|
||||||
++ " "
|
|
||||||
++ left nameWidth (p^.pName)
|
|
||||||
++ right 3 (show $ stats^.psGoals)
|
|
||||||
++ right 6 (show $ stats^.psAssists)
|
|
||||||
++ right 6 (show $ psPoints stats)
|
|
||||||
++ right 6 (show $ stats^.psPMin))
|
|
||||||
ps ++
|
|
||||||
[ centre width
|
|
||||||
$ replicate (4 + nameWidth) ' '
|
|
||||||
++ replicate (3 + 3 * 6) '-'
|
|
||||||
, overlay
|
|
||||||
(label ++ " TOTALS")
|
|
||||||
( centre width
|
|
||||||
$ replicate (4 + nameWidth) ' '
|
|
||||||
++ right 3 (show $ tStats^.psGoals)
|
|
||||||
++ right 6 (show $ tStats^.psAssists)
|
|
||||||
++ right 6 (show $ psPoints tStats)
|
|
||||||
++ right 6 (show $ tStats^.psPMin)
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
playerNameColWidth :: [Player] -> Int
|
tHeader =
|
||||||
playerNameColWidth = foldr
|
[ CellText "NO."
|
||||||
(\player current -> max current $ succ $ length $ player^.pName)
|
, CellText "Player"
|
||||||
10
|
, CellText " G"
|
||||||
|
, CellText " A"
|
||||||
|
, CellText " P"
|
||||||
|
, CellText " PM"
|
||||||
|
]
|
||||||
|
|
||||||
showStats :: GameStats -> String
|
statsCells stats =
|
||||||
showStats gs
|
[ CellText $ show $ stats^.psGoals
|
||||||
= right 2 (show $ gmsGames gs)
|
, CellText $ show $ stats^.psAssists
|
||||||
++ right 4 (show $ gs^.gmsWins)
|
, CellText $ show $ psPoints stats
|
||||||
++ right 4 (show $ gs^.gmsLosses)
|
, CellText $ show $ stats^.psPMin
|
||||||
++ right 4 (show $ gs^.gmsOvertime)
|
]
|
||||||
++ right 4 (show $ gs^.gmsGoalsFor)
|
|
||||||
++ right 4 (show $ gs^.gmsGoalsAgainst)
|
body = map
|
||||||
++ right 4 (show $ gmsPoints gs)
|
(\(p, stats) ->
|
||||||
|
[ CellText $ show (p^.pNumber) ++ " "
|
||||||
|
, CellText $ p^.pName
|
||||||
|
] ++ statsCells stats)
|
||||||
|
fps
|
||||||
|
|
||||||
|
separator = replicate 2 (CellText "") ++ replicate 4 (CellFill '-')
|
||||||
|
|
||||||
|
totals =
|
||||||
|
[ CellText ""
|
||||||
|
, CellText ""
|
||||||
|
] ++ statsCells tStats
|
||||||
|
|
||||||
|
table = overlayLast (label ++ " TOTALS")
|
||||||
|
$ map (centre width)
|
||||||
|
$ complexTable ([right, left] ++ repeat right)
|
||||||
|
$ tHeader : body ++ [separator, totals]
|
||||||
|
|
||||||
|
in rHeader ++ table
|
||||||
|
|
||||||
|
goalieReport :: Int -> [(Goalie, GoalieStats)] -> [String]
|
||||||
|
goalieReport width goalieData = let
|
||||||
|
olayText = "GOALTENDING TOTALS"
|
||||||
|
|
||||||
|
tData = foldl addGoalieStats newGoalieStats
|
||||||
|
$ map snd goalieData
|
||||||
|
|
||||||
|
header =
|
||||||
|
[ CellText "NO."
|
||||||
|
, CellText $ left (length olayText) "GOALTENDER"
|
||||||
|
, CellText "GP"
|
||||||
|
, CellText " MIN"
|
||||||
|
, CellText " GA"
|
||||||
|
, CellText " SO"
|
||||||
|
, CellText "AVE"
|
||||||
|
]
|
||||||
|
|
||||||
|
rowCells stats =
|
||||||
|
[ CellText $ show $ stats^.gsGames
|
||||||
|
, CellText $ show $ stats^.gsMinsPlayed
|
||||||
|
, CellText $ show $ stats^.gsGoalsAllowed
|
||||||
|
, CellText $ show $ stats^.gsShutouts
|
||||||
|
, CellText $ showFloating $ gsAverage stats
|
||||||
|
]
|
||||||
|
|
||||||
|
body = map
|
||||||
|
(\(goalie, stats) ->
|
||||||
|
[ CellText $ show (goalie^.gNumber) ++ " "
|
||||||
|
, CellText $ goalie^.gName
|
||||||
|
] ++ rowCells stats)
|
||||||
|
goalieData
|
||||||
|
|
||||||
|
separator
|
||||||
|
= replicate 2 (CellText "")
|
||||||
|
++ replicate 5 (CellFill '-')
|
||||||
|
|
||||||
|
summary = replicate 2 (CellText "") ++ rowCells tData
|
||||||
|
|
||||||
|
in map (centre width)
|
||||||
|
$ overlayLast olayText
|
||||||
|
$ complexTable ([right, left] ++ repeat right)
|
||||||
|
$ header : body ++ [separator, summary]
|
||||||
|
|
||||||
|
gameGoalieReport :: Int -> [(Goalie, GoalieStats)] -> [String]
|
||||||
|
gameGoalieReport width goalieData = let
|
||||||
|
header =
|
||||||
|
[ CellText "NO."
|
||||||
|
, CellText "GOALTENDER"
|
||||||
|
, CellText " MIN"
|
||||||
|
, CellText " GA"
|
||||||
|
, CellText " AVE"
|
||||||
|
]
|
||||||
|
|
||||||
|
body = map
|
||||||
|
(\(goalie, stats) ->
|
||||||
|
[ CellText $ show (goalie^.gNumber) ++ " "
|
||||||
|
, CellText $ goalie^.gName
|
||||||
|
, CellText $ show $ stats^.gsMinsPlayed
|
||||||
|
, CellText $ show $ stats^.gsGoalsAllowed
|
||||||
|
, CellText $ showFloating $ gsAverage stats
|
||||||
|
])
|
||||||
|
goalieData
|
||||||
|
|
||||||
|
in map (centre width)
|
||||||
|
$ complexTable ([right, left] ++ repeat right)
|
||||||
|
$ header : body
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ module Mtlstats.Types (
|
|||||||
GameStats (..),
|
GameStats (..),
|
||||||
Prompt (..),
|
Prompt (..),
|
||||||
SelectParams (..),
|
SelectParams (..),
|
||||||
|
TableCell (..),
|
||||||
-- * Lenses
|
-- * Lenses
|
||||||
-- ** ProgState Lenses
|
-- ** ProgState Lenses
|
||||||
database,
|
database,
|
||||||
@@ -120,6 +121,7 @@ module Mtlstats.Types (
|
|||||||
gsGames,
|
gsGames,
|
||||||
gsMinsPlayed,
|
gsMinsPlayed,
|
||||||
gsGoalsAllowed,
|
gsGoalsAllowed,
|
||||||
|
gsShutouts,
|
||||||
gsWins,
|
gsWins,
|
||||||
gsLosses,
|
gsLosses,
|
||||||
gsTies,
|
gsTies,
|
||||||
@@ -161,7 +163,6 @@ module Mtlstats.Types (
|
|||||||
playerSearchExact,
|
playerSearchExact,
|
||||||
modifyPlayer,
|
modifyPlayer,
|
||||||
playerSummary,
|
playerSummary,
|
||||||
playerDetails,
|
|
||||||
playerIsActive,
|
playerIsActive,
|
||||||
-- ** PlayerStats Helpers
|
-- ** PlayerStats Helpers
|
||||||
psPoints,
|
psPoints,
|
||||||
@@ -169,7 +170,11 @@ module Mtlstats.Types (
|
|||||||
-- ** Goalie Helpers
|
-- ** Goalie Helpers
|
||||||
goalieSearch,
|
goalieSearch,
|
||||||
goalieSearchExact,
|
goalieSearchExact,
|
||||||
goalieSummary
|
goalieSummary,
|
||||||
|
goalieIsActive,
|
||||||
|
-- ** GoalieStats Helpers
|
||||||
|
addGoalieStats,
|
||||||
|
gsAverage
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.State (StateT)
|
import Control.Monad.Trans.State (StateT)
|
||||||
@@ -183,8 +188,11 @@ import Data.Aeson
|
|||||||
, toJSON
|
, toJSON
|
||||||
, withObject
|
, withObject
|
||||||
, (.:)
|
, (.:)
|
||||||
|
, (.:?)
|
||||||
|
, (.!=)
|
||||||
, (.=)
|
, (.=)
|
||||||
)
|
)
|
||||||
|
import Data.Char (toUpper)
|
||||||
import Data.List (isInfixOf)
|
import Data.List (isInfixOf)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Maybe (listToMaybe)
|
import Data.Maybe (listToMaybe)
|
||||||
@@ -335,6 +343,8 @@ data EditPlayerMode
|
|||||||
| EPNumber
|
| EPNumber
|
||||||
| EPName
|
| EPName
|
||||||
| EPPosition
|
| EPPosition
|
||||||
|
| EPYtd
|
||||||
|
| EPLifetime
|
||||||
| EPYtdGoals
|
| EPYtdGoals
|
||||||
| EPYtdAssists
|
| EPYtdAssists
|
||||||
| EPYtdPMin
|
| EPYtdPMin
|
||||||
@@ -512,6 +522,8 @@ data GoalieStats = GoalieStats
|
|||||||
-- ^ The number of minutes played
|
-- ^ The number of minutes played
|
||||||
, _gsGoalsAllowed :: Int
|
, _gsGoalsAllowed :: Int
|
||||||
-- ^ The number of goals allowed
|
-- ^ The number of goals allowed
|
||||||
|
, _gsShutouts :: Int
|
||||||
|
-- ^ The number of shutouts the goalie has accumulated
|
||||||
, _gsWins :: Int
|
, _gsWins :: Int
|
||||||
-- ^ The number of wins
|
-- ^ The number of wins
|
||||||
, _gsLosses :: Int
|
, _gsLosses :: Int
|
||||||
@@ -522,26 +534,29 @@ data GoalieStats = GoalieStats
|
|||||||
|
|
||||||
instance FromJSON GoalieStats where
|
instance FromJSON GoalieStats where
|
||||||
parseJSON = withObject "GoalieStats" $ \v -> GoalieStats
|
parseJSON = withObject "GoalieStats" $ \v -> GoalieStats
|
||||||
<$> v .: "games"
|
<$> v .:? "games" .!= 0
|
||||||
<*> v .: "mins_played"
|
<*> v .:? "mins_played" .!= 0
|
||||||
<*> v .: "goals_allowed"
|
<*> v .:? "goals_allowed" .!= 0
|
||||||
<*> v .: "wins"
|
<*> v .:? "shutouts" .!= 0
|
||||||
<*> v .: "losses"
|
<*> v .:? "wins" .!= 0
|
||||||
<*> v .: "ties"
|
<*> v .:? "losses" .!= 0
|
||||||
|
<*> v .:? "ties" .!= 0
|
||||||
|
|
||||||
instance ToJSON GoalieStats where
|
instance ToJSON GoalieStats where
|
||||||
toJSON (GoalieStats g m a w l t) = object
|
toJSON (GoalieStats g m a s w l t) = object
|
||||||
[ "games" .= g
|
[ "games" .= g
|
||||||
, "mins_played" .= m
|
, "mins_played" .= m
|
||||||
, "goals_allowed" .= a
|
, "goals_allowed" .= a
|
||||||
|
, "shutouts" .= s
|
||||||
, "wins" .= w
|
, "wins" .= w
|
||||||
, "losses" .= l
|
, "losses" .= l
|
||||||
, "ties" .= t
|
, "ties" .= t
|
||||||
]
|
]
|
||||||
toEncoding (GoalieStats g m a w l t) = pairs $
|
toEncoding (GoalieStats g m a s w l t) = pairs $
|
||||||
"games" .= g <>
|
"games" .= g <>
|
||||||
"mins_played" .= m <>
|
"mins_played" .= m <>
|
||||||
"goals_allowed" .= a <>
|
"goals_allowed" .= a <>
|
||||||
|
"shutouts" .= s <>
|
||||||
"wins" .= w <>
|
"wins" .= w <>
|
||||||
"losses" .= l <>
|
"losses" .= l <>
|
||||||
"ties" .= t
|
"ties" .= t
|
||||||
@@ -585,13 +600,13 @@ instance ToJSON GameStats where
|
|||||||
|
|
||||||
-- | Defines a user prompt
|
-- | Defines a user prompt
|
||||||
data Prompt = Prompt
|
data Prompt = Prompt
|
||||||
{ promptDrawer :: ProgState -> C.Update ()
|
{ promptDrawer :: ProgState -> C.Update ()
|
||||||
-- ^ Draws the prompt to the screen
|
-- ^ Draws the prompt to the screen
|
||||||
, promptCharCheck :: Char -> Bool
|
, promptProcessChar :: Char -> String -> String
|
||||||
-- ^ Determines whether or not the character is valid
|
-- ^ Modifies the string based on the character entered
|
||||||
, promptAction :: String -> Action ()
|
, promptAction :: String -> Action ()
|
||||||
-- ^ Action to perform when the value is entered
|
-- ^ Action to perform when the value is entered
|
||||||
, promptSpecialKey :: C.Key -> Action ()
|
, promptSpecialKey :: C.Key -> Action ()
|
||||||
-- ^ Action to perform when a special key is pressed
|
-- ^ Action to perform when a special key is pressed
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,6 +628,14 @@ data SelectParams a = SelectParams
|
|||||||
-- ^ The function to call when the selection doesn't exist
|
-- ^ The function to call when the selection doesn't exist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Describes a table cell
|
||||||
|
data TableCell
|
||||||
|
= CellText String
|
||||||
|
-- ^ A cell with text
|
||||||
|
| CellFill Char
|
||||||
|
-- ^ A cell filled with the given character
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
makeLenses ''ProgState
|
makeLenses ''ProgState
|
||||||
makeLenses ''GameState
|
makeLenses ''GameState
|
||||||
makeLenses ''CreatePlayerState
|
makeLenses ''CreatePlayerState
|
||||||
@@ -785,6 +808,7 @@ newGoalieStats = GoalieStats
|
|||||||
{ _gsGames = 0
|
{ _gsGames = 0
|
||||||
, _gsMinsPlayed = 0
|
, _gsMinsPlayed = 0
|
||||||
, _gsGoalsAllowed = 0
|
, _gsGoalsAllowed = 0
|
||||||
|
, _gsShutouts = 0
|
||||||
, _gsWins = 0
|
, _gsWins = 0
|
||||||
, _gsLosses = 0
|
, _gsLosses = 0
|
||||||
, _gsTies = 0
|
, _gsTies = 0
|
||||||
@@ -881,7 +905,7 @@ playerSearch
|
|||||||
-- ^ The matching players with their index numbers
|
-- ^ The matching players with their index numbers
|
||||||
playerSearch sStr =
|
playerSearch sStr =
|
||||||
filter match . zip [0..]
|
filter match . zip [0..]
|
||||||
where match (_, p) = sStr `isInfixOf` (p^.pName)
|
where match (_, p) = map toUpper sStr `isInfixOf` map toUpper (p^.pName)
|
||||||
|
|
||||||
-- | Searches for a player by exact match on name
|
-- | Searches for a player by exact match on name
|
||||||
playerSearchExact
|
playerSearchExact
|
||||||
@@ -915,20 +939,6 @@ playerSummary :: Player -> String
|
|||||||
playerSummary p =
|
playerSummary p =
|
||||||
p^.pName ++ " (" ++ show (p^.pNumber) ++ ") " ++ p^.pPosition
|
p^.pName ++ " (" ++ show (p^.pNumber) ++ ") " ++ p^.pPosition
|
||||||
|
|
||||||
-- | Provides a detailed string describing a 'Player'
|
|
||||||
playerDetails :: Player -> String
|
|
||||||
playerDetails p = unlines
|
|
||||||
[ " Number: " ++ show (p^.pNumber)
|
|
||||||
, " Name: " ++ p^.pName
|
|
||||||
, " Position: " ++ p^.pPosition
|
|
||||||
, " YTD goals: " ++ show (p^.pYtd.psGoals)
|
|
||||||
, " YTD assists: " ++ show (p^.pYtd.psAssists)
|
|
||||||
, " YTD penalty mins: " ++ show (p^.pYtd.psPMin)
|
|
||||||
, " Lifetime goals: " ++ show (p^.pLifetime.psGoals)
|
|
||||||
, " Lifetime assists: " ++ show (p^.pLifetime.psAssists)
|
|
||||||
, "Lifetime penalty mins: " ++ show (p^.pLifetime.psPMin)
|
|
||||||
]
|
|
||||||
|
|
||||||
-- | Determines whether or not a player has been active in the current
|
-- | Determines whether or not a player has been active in the current
|
||||||
-- season/year
|
-- season/year
|
||||||
playerIsActive :: Player -> Bool
|
playerIsActive :: Player -> Bool
|
||||||
@@ -958,8 +968,9 @@ goalieSearch
|
|||||||
-- ^ The list to search
|
-- ^ The list to search
|
||||||
-> [(Int, Goalie)]
|
-> [(Int, Goalie)]
|
||||||
-- ^ The search results with their corresponding index numbers
|
-- ^ The search results with their corresponding index numbers
|
||||||
goalieSearch sStr = filter (\(_, goalie) -> sStr `isInfixOf` (goalie^.gName)) .
|
goalieSearch sStr =
|
||||||
zip [0..]
|
filter match . zip [0..]
|
||||||
|
where match (_, g) = map toUpper sStr `isInfixOf` map toUpper (g^.gName)
|
||||||
|
|
||||||
-- | Searches a list of goalies for an exact match
|
-- | Searches a list of goalies for an exact match
|
||||||
goalieSearchExact
|
goalieSearchExact
|
||||||
@@ -979,3 +990,30 @@ goalieSearchExact sStr goalies = let
|
|||||||
-- | Provides a description string for a 'Goalie'
|
-- | Provides a description string for a 'Goalie'
|
||||||
goalieSummary :: Goalie -> String
|
goalieSummary :: Goalie -> String
|
||||||
goalieSummary g = g^.gName ++ " (" ++ show (g^.gNumber) ++ ")"
|
goalieSummary g = g^.gName ++ " (" ++ show (g^.gNumber) ++ ")"
|
||||||
|
|
||||||
|
-- | Determines whether or not a goalie has been active in the current
|
||||||
|
-- season
|
||||||
|
goalieIsActive :: Goalie -> Bool
|
||||||
|
goalieIsActive g = g^.gYtd.gsMinsPlayed /= 0
|
||||||
|
|
||||||
|
-- | Adds two sets of 'GoalieStats'
|
||||||
|
addGoalieStats :: GoalieStats -> GoalieStats -> GoalieStats
|
||||||
|
addGoalieStats g1 g2 = GoalieStats
|
||||||
|
{ _gsGames = g1^.gsGames + g2^.gsGames
|
||||||
|
, _gsMinsPlayed = g1^.gsMinsPlayed + g2^.gsMinsPlayed
|
||||||
|
, _gsGoalsAllowed = g1^.gsGoalsAllowed + g2^.gsGoalsAllowed
|
||||||
|
, _gsShutouts = g1^.gsShutouts + g2^.gsShutouts
|
||||||
|
, _gsWins = g1^.gsWins + g2^.gsWins
|
||||||
|
, _gsLosses = g1^.gsLosses + g2^.gsLosses
|
||||||
|
, _gsTies = g1^.gsTies + g2^.gsTies
|
||||||
|
}
|
||||||
|
|
||||||
|
-- | Determines a goalie's average goals allowed per game.
|
||||||
|
gsAverage :: GoalieStats -> Rational
|
||||||
|
gsAverage gs = let
|
||||||
|
allowed = fromIntegral $ gs^.gsGoalsAllowed
|
||||||
|
mins = fromIntegral $ gs^.gsMinsPlayed
|
||||||
|
gLen = fromIntegral gameLength
|
||||||
|
in if mins == 0
|
||||||
|
then 0
|
||||||
|
else allowed / mins * gLen
|
||||||
|
|||||||
@@ -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 )
|
||||||
|
]
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
module FormatSpec (spec) where
|
module FormatSpec (spec) where
|
||||||
|
|
||||||
|
import Data.Ratio ((%))
|
||||||
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
||||||
|
|
||||||
import Mtlstats.Format
|
import Mtlstats.Format
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = describe "Mtlstats.Format" $ do
|
spec = describe "Mtlstats.Format" $ do
|
||||||
@@ -33,6 +35,12 @@ spec = describe "Mtlstats.Format" $ do
|
|||||||
centreSpec
|
centreSpec
|
||||||
overlaySpec
|
overlaySpec
|
||||||
monthSpec
|
monthSpec
|
||||||
|
labelTableSpec
|
||||||
|
numTableSpec
|
||||||
|
tableWithSpec
|
||||||
|
complexTableSpec
|
||||||
|
overlayLastSpec
|
||||||
|
showFloatingSpec
|
||||||
|
|
||||||
padNumSpec :: Spec
|
padNumSpec :: Spec
|
||||||
padNumSpec = describe "padNum" $ do
|
padNumSpec = describe "padNum" $ do
|
||||||
@@ -111,3 +119,120 @@ monthSpec = describe "month" $ do
|
|||||||
context "invalid" $
|
context "invalid" $
|
||||||
it "should return an empty string" $
|
it "should return an empty string" $
|
||||||
month 0 `shouldBe` ""
|
month 0 `shouldBe` ""
|
||||||
|
|
||||||
|
labelTableSpec :: Spec
|
||||||
|
labelTableSpec = describe "labelTable" $
|
||||||
|
it "should format the table" $ let
|
||||||
|
input =
|
||||||
|
[ ( "foo", "bar" )
|
||||||
|
, ( "baz", "quux" )
|
||||||
|
, ( "longer", "x" )
|
||||||
|
]
|
||||||
|
|
||||||
|
expected =
|
||||||
|
[ " foo: bar"
|
||||||
|
, " baz: quux"
|
||||||
|
, "longer: x"
|
||||||
|
]
|
||||||
|
|
||||||
|
in labelTable input `shouldBe` expected
|
||||||
|
|
||||||
|
numTableSpec :: Spec
|
||||||
|
numTableSpec = describe "numTable" $
|
||||||
|
it "should format the table" $ let
|
||||||
|
headers = ["foo", "bar", "baz"]
|
||||||
|
|
||||||
|
rows =
|
||||||
|
[ ( "quux", [ 1, 2, 3 ] )
|
||||||
|
, ( "xyzzy", [ 9, 99, 999 ] )
|
||||||
|
]
|
||||||
|
|
||||||
|
expected =
|
||||||
|
[ " foo bar baz"
|
||||||
|
, " quux 1 2 3"
|
||||||
|
, "xyzzy 9 99 999"
|
||||||
|
]
|
||||||
|
|
||||||
|
in numTable headers rows `shouldBe` expected
|
||||||
|
|
||||||
|
tableWithSpec :: Spec
|
||||||
|
tableWithSpec = describe "tableWith" $ let
|
||||||
|
vals =
|
||||||
|
[ [ "foo", "bar", "baz" ]
|
||||||
|
, [ "quux", "xyzzy", "x" ]
|
||||||
|
]
|
||||||
|
|
||||||
|
in mapM_
|
||||||
|
(\(label, func, expected) -> context label $
|
||||||
|
it "should format the table" $
|
||||||
|
tableWith func vals `shouldBe` expected)
|
||||||
|
[ ( "align left"
|
||||||
|
, left
|
||||||
|
, [ "foo bar baz"
|
||||||
|
, "quux xyzzy x "
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, ( "align right"
|
||||||
|
, right
|
||||||
|
, [ " foo bar baz"
|
||||||
|
, "quux xyzzy x"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
complexTableSpec :: Spec
|
||||||
|
complexTableSpec = describe "complexTable" $ mapM_
|
||||||
|
(\(label, pFuncs, cells, expected) -> context label $
|
||||||
|
it "should format correctly" $
|
||||||
|
complexTable pFuncs cells `shouldBe` expected)
|
||||||
|
[ ( "no fill"
|
||||||
|
, [left, right]
|
||||||
|
, [ [ CellText "foo", CellText "bar" ]
|
||||||
|
, [ CellText "baaz", CellText "quux" ]
|
||||||
|
]
|
||||||
|
, [ "foo bar"
|
||||||
|
, "baaz quux"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, ( "with fill"
|
||||||
|
, [left, left, left]
|
||||||
|
, [ [ CellText "foo", CellText "bar", CellText "baz" ]
|
||||||
|
, [ CellText "quux", CellFill '-', CellFill '@' ]
|
||||||
|
]
|
||||||
|
, [ "foo bar baz"
|
||||||
|
, "quux ----@@@"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
overlayLastSpec :: Spec
|
||||||
|
overlayLastSpec = describe "overlayLast" $ let
|
||||||
|
text = "foo"
|
||||||
|
|
||||||
|
sample =
|
||||||
|
[ "line 1"
|
||||||
|
, "line 2"
|
||||||
|
]
|
||||||
|
|
||||||
|
edited =
|
||||||
|
[ "line 1"
|
||||||
|
, "fooe 2"
|
||||||
|
]
|
||||||
|
|
||||||
|
in mapM_
|
||||||
|
(\(label, input, expected) -> context label $
|
||||||
|
it ("should be " ++ show expected) $
|
||||||
|
overlayLast text input `shouldBe` expected)
|
||||||
|
|
||||||
|
-- label, input, expected
|
||||||
|
[ ( "empty list", [], [] )
|
||||||
|
, ( "non-empty list", sample, edited )
|
||||||
|
]
|
||||||
|
|
||||||
|
showFloatingSpec :: Spec
|
||||||
|
showFloatingSpec = describe "showFloating" $ let
|
||||||
|
input = 3 % 2 :: Rational
|
||||||
|
expected = "1.50"
|
||||||
|
|
||||||
|
in it ("should be " ++ expected) $
|
||||||
|
showFloating input `shouldBe` expected
|
||||||
|
|||||||
66
test/Helpers/GoalieSpec.hs
Normal file
66
test/Helpers/GoalieSpec.hs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{-
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 2019 Rhéal Lamothe
|
||||||
|
<rheal.lamothe@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Helpers.GoalieSpec (spec) where
|
||||||
|
|
||||||
|
import Lens.Micro ((&), (.~), (%~))
|
||||||
|
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||||
|
|
||||||
|
import Mtlstats.Helpers.Goalie
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec = describe "Goalie"
|
||||||
|
goalieDetailsSpec
|
||||||
|
|
||||||
|
goalieDetailsSpec :: Spec
|
||||||
|
goalieDetailsSpec = describe "goalieDetails" $ let
|
||||||
|
input = newGoalie 1 "Joe"
|
||||||
|
& gYtd
|
||||||
|
%~ ( gsGames .~ 2 )
|
||||||
|
. ( gsMinsPlayed .~ 3 )
|
||||||
|
. ( gsGoalsAllowed .~ 4 )
|
||||||
|
. ( gsWins .~ 5 )
|
||||||
|
. ( gsLosses .~ 6 )
|
||||||
|
. ( gsTies .~ 7 )
|
||||||
|
& gLifetime
|
||||||
|
%~ ( gsGames .~ 8 )
|
||||||
|
. ( gsMinsPlayed .~ 9 )
|
||||||
|
. ( gsGoalsAllowed .~ 10 )
|
||||||
|
. ( gsWins .~ 11 )
|
||||||
|
. ( gsLosses .~ 12 )
|
||||||
|
. ( gsTies .~ 13 )
|
||||||
|
|
||||||
|
expected = unlines
|
||||||
|
[ "Number: 1"
|
||||||
|
, " Name: Joe"
|
||||||
|
, ""
|
||||||
|
, " YTD Lifetime"
|
||||||
|
, " Games played 2 8"
|
||||||
|
, " Mins played 3 9"
|
||||||
|
, "Goals allowed 4 10"
|
||||||
|
, " Wins 5 11"
|
||||||
|
, " Losses 6 12"
|
||||||
|
, " Ties 7 13"
|
||||||
|
]
|
||||||
|
|
||||||
|
in it "should format the output correctly" $
|
||||||
|
goalieDetails input `shouldBe` expected
|
||||||
61
test/Helpers/PlayerSpec.hs
Normal file
61
test/Helpers/PlayerSpec.hs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{-
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 2019 Rhéal Lamothe
|
||||||
|
<rheal.lamothe@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Helpers.PlayerSpec (spec) where
|
||||||
|
|
||||||
|
import Lens.Micro ((&), (.~))
|
||||||
|
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||||
|
|
||||||
|
import Mtlstats.Helpers.Player
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec = describe "Player"
|
||||||
|
playerDetailsSpec
|
||||||
|
|
||||||
|
playerDetailsSpec :: Spec
|
||||||
|
playerDetailsSpec = describe "playerDetails" $
|
||||||
|
it "should give a detailed description" $ let
|
||||||
|
|
||||||
|
p = newPlayer 1 "Joe" "centre"
|
||||||
|
& pYtd .~ PlayerStats
|
||||||
|
{ _psGoals = 2
|
||||||
|
, _psAssists = 3
|
||||||
|
, _psPMin = 4
|
||||||
|
}
|
||||||
|
& pLifetime .~ PlayerStats
|
||||||
|
{ _psGoals = 5
|
||||||
|
, _psAssists = 6
|
||||||
|
, _psPMin = 7
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = unlines
|
||||||
|
[ " Number: 1"
|
||||||
|
, " Name: Joe"
|
||||||
|
, "Position: centre"
|
||||||
|
, ""
|
||||||
|
, " YTD Lifetime"
|
||||||
|
, " Goals 2 5"
|
||||||
|
, " Assists 3 6"
|
||||||
|
, "Penalty mins 4 7"
|
||||||
|
]
|
||||||
|
|
||||||
|
in playerDetails p `shouldBe` expected
|
||||||
32
test/HelpersSpec.hs
Normal file
32
test/HelpersSpec.hs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{-
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 2019 Rhéal Lamothe
|
||||||
|
<rheal.lamothe@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
module HelpersSpec (spec) where
|
||||||
|
|
||||||
|
import Test.Hspec (Spec, describe)
|
||||||
|
|
||||||
|
import qualified Helpers.GoalieSpec as Goalie
|
||||||
|
import qualified Helpers.PlayerSpec as Player
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec = describe "Helper" $ do
|
||||||
|
Player.spec
|
||||||
|
Goalie.spec
|
||||||
@@ -28,9 +28,8 @@ import Mtlstats.Report
|
|||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = describe "Mtlstats.Report" $ do
|
spec = describe "Mtlstats.Report"
|
||||||
gameDateSpec
|
gameDateSpec
|
||||||
playerNameColWidthSpec
|
|
||||||
|
|
||||||
gameDateSpec :: Spec
|
gameDateSpec :: Spec
|
||||||
gameDateSpec = describe "gameDate" $ do
|
gameDateSpec = describe "gameDate" $ do
|
||||||
@@ -46,20 +45,3 @@ gameDateSpec = describe "gameDate" $ do
|
|||||||
context "invalid date" $
|
context "invalid date" $
|
||||||
it "should return an empty string" $
|
it "should return an empty string" $
|
||||||
gameDate newGameState `shouldBe` ""
|
gameDate newGameState `shouldBe` ""
|
||||||
|
|
||||||
playerNameColWidthSpec :: Spec
|
|
||||||
playerNameColWidthSpec = describe "playerNameColWidth" $ do
|
|
||||||
let
|
|
||||||
short1 = newPlayer 1 "short" "foo"
|
|
||||||
short2 = newPlayer 2 "shorty" "bar"
|
|
||||||
long = newPlayer 3 "123456789012345" "baz"
|
|
||||||
|
|
||||||
mapM_
|
|
||||||
(\(label, players, expected) -> context label $
|
|
||||||
it ("should be " ++ show expected) $
|
|
||||||
playerNameColWidth players `shouldBe` expected)
|
|
||||||
-- label, players, expected
|
|
||||||
[ ( "empty list", [], 10 )
|
|
||||||
, ( "short names", [short1, short2], 10 )
|
|
||||||
, ( "long name", [short1, long], 16 )
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import Test.Hspec (hspec)
|
|||||||
import qualified ActionsSpec as Actions
|
import qualified ActionsSpec as Actions
|
||||||
import qualified FormatSpec as Format
|
import qualified FormatSpec as Format
|
||||||
import qualified HandlersSpec as Handlers
|
import qualified HandlersSpec as Handlers
|
||||||
|
import qualified HelpersSpec as Helpers
|
||||||
import qualified ReportSpec as Report
|
import qualified ReportSpec as Report
|
||||||
import qualified TypesSpec as Types
|
import qualified TypesSpec as Types
|
||||||
import qualified UtilSpec as Util
|
import qualified UtilSpec as Util
|
||||||
@@ -31,6 +32,7 @@ import qualified UtilSpec as Util
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = hspec $ do
|
main = hspec $ do
|
||||||
Types.spec
|
Types.spec
|
||||||
|
Helpers.spec
|
||||||
Actions.spec
|
Actions.spec
|
||||||
Format.spec
|
Format.spec
|
||||||
Handlers.spec
|
Handlers.spec
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import Control.Monad (replicateM)
|
|||||||
import Data.Aeson (FromJSON, ToJSON, decode, encode, toJSON)
|
import Data.Aeson (FromJSON, ToJSON, decode, encode, toJSON)
|
||||||
import Data.Aeson.Types (Value (Object))
|
import Data.Aeson.Types (Value (Object))
|
||||||
import qualified Data.HashMap.Strict as HM
|
import qualified Data.HashMap.Strict as HM
|
||||||
|
import Data.Ratio ((%))
|
||||||
import Lens.Micro (Lens', (&), (^.), (.~), (?~))
|
import Lens.Micro (Lens', (&), (^.), (.~), (?~))
|
||||||
import System.Random (randomRIO)
|
import System.Random (randomRIO)
|
||||||
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
||||||
@@ -72,13 +73,15 @@ spec = describe "Mtlstats.Types" $ do
|
|||||||
playerSearchExactSpec
|
playerSearchExactSpec
|
||||||
modifyPlayerSpec
|
modifyPlayerSpec
|
||||||
playerSummarySpec
|
playerSummarySpec
|
||||||
playerDetailsSpec
|
|
||||||
playerIsActiveSpec
|
playerIsActiveSpec
|
||||||
psPointsSpec
|
psPointsSpec
|
||||||
addPlayerStatsSpec
|
addPlayerStatsSpec
|
||||||
goalieSearchSpec
|
goalieSearchSpec
|
||||||
goalieSearchExactSpec
|
goalieSearchExactSpec
|
||||||
goalieSummarySpec
|
goalieSummarySpec
|
||||||
|
goalieIsActiveSpec
|
||||||
|
addGoalieStatsSpec
|
||||||
|
gsAverageSpec
|
||||||
Menu.spec
|
Menu.spec
|
||||||
|
|
||||||
playerSpec :: Spec
|
playerSpec :: Spec
|
||||||
@@ -311,18 +314,20 @@ goalieStats n = newGoalieStats
|
|||||||
& gsGames .~ n
|
& gsGames .~ n
|
||||||
& gsMinsPlayed .~ n + 1
|
& gsMinsPlayed .~ n + 1
|
||||||
& gsGoalsAllowed .~ n + 2
|
& gsGoalsAllowed .~ n + 2
|
||||||
& gsWins .~ n + 3
|
& gsShutouts .~ n + 3
|
||||||
& gsLosses .~ n + 4
|
& gsWins .~ n + 4
|
||||||
& gsTies .~ n + 5
|
& gsLosses .~ n + 5
|
||||||
|
& gsTies .~ n + 6
|
||||||
|
|
||||||
goalieStatsJSON :: Int -> Value
|
goalieStatsJSON :: Int -> Value
|
||||||
goalieStatsJSON n = Object $ HM.fromList
|
goalieStatsJSON n = Object $ HM.fromList
|
||||||
[ ( "games", toJSON n )
|
[ ( "games", toJSON n )
|
||||||
, ( "mins_played", toJSON $ n + 1 )
|
, ( "mins_played", toJSON $ n + 1 )
|
||||||
, ( "goals_allowed", toJSON $ n + 2 )
|
, ( "goals_allowed", toJSON $ n + 2 )
|
||||||
, ( "wins", toJSON $ n + 3 )
|
, ( "shutouts", toJSON $ n + 3 )
|
||||||
, ( "losses", toJSON $ n + 4 )
|
, ( "wins", toJSON $ n + 4 )
|
||||||
, ( "ties", toJSON $ n + 5 )
|
, ( "losses", toJSON $ n + 5 )
|
||||||
|
, ( "ties", toJSON $ n + 6 )
|
||||||
]
|
]
|
||||||
|
|
||||||
gameStats :: Int -> GameStats
|
gameStats :: Int -> GameStats
|
||||||
@@ -586,7 +591,7 @@ playerSearchSpec = describe "playerSearch" $ mapM_
|
|||||||
ps = [joe, bob, steve]
|
ps = [joe, bob, steve]
|
||||||
in playerSearch sStr ps `shouldBe` expected)
|
in playerSearch sStr ps `shouldBe` expected)
|
||||||
-- search, result
|
-- search, result
|
||||||
[ ( "Joe", [(0, joe)] )
|
[ ( "joe", [(0, joe)] )
|
||||||
, ( "o", [(0, joe), (1, bob)] )
|
, ( "o", [(0, joe), (1, bob)] )
|
||||||
, ( "e", [(0, joe), (2, steve)] )
|
, ( "e", [(0, joe), (2, steve)] )
|
||||||
, ( "x", [] )
|
, ( "x", [] )
|
||||||
@@ -636,36 +641,6 @@ playerSummarySpec = describe "playerSummary" $
|
|||||||
it "should be \"Joe (2) center\"" $
|
it "should be \"Joe (2) center\"" $
|
||||||
playerSummary joe `shouldBe` "Joe (2) center"
|
playerSummary joe `shouldBe` "Joe (2) center"
|
||||||
|
|
||||||
playerDetailsSpec :: Spec
|
|
||||||
playerDetailsSpec = describe "playerDetails" $
|
|
||||||
it "should give a detailed description" $ let
|
|
||||||
|
|
||||||
p = newPlayer 1 "Joe" "centre"
|
|
||||||
& pYtd .~ PlayerStats
|
|
||||||
{ _psGoals = 2
|
|
||||||
, _psAssists = 3
|
|
||||||
, _psPMin = 4
|
|
||||||
}
|
|
||||||
& pLifetime .~ PlayerStats
|
|
||||||
{ _psGoals = 5
|
|
||||||
, _psAssists = 6
|
|
||||||
, _psPMin = 7
|
|
||||||
}
|
|
||||||
|
|
||||||
expected = unlines
|
|
||||||
[ " Number: 1"
|
|
||||||
, " Name: Joe"
|
|
||||||
, " Position: centre"
|
|
||||||
, " YTD goals: 2"
|
|
||||||
, " YTD assists: 3"
|
|
||||||
, " YTD penalty mins: 4"
|
|
||||||
, " Lifetime goals: 5"
|
|
||||||
, " Lifetime assists: 6"
|
|
||||||
, "Lifetime penalty mins: 7"
|
|
||||||
]
|
|
||||||
|
|
||||||
in playerDetails p `shouldBe` expected
|
|
||||||
|
|
||||||
playerIsActiveSpec :: Spec
|
playerIsActiveSpec :: Spec
|
||||||
playerIsActiveSpec = describe "playerIsActive" $ do
|
playerIsActiveSpec = describe "playerIsActive" $ do
|
||||||
let
|
let
|
||||||
@@ -750,8 +725,8 @@ goalieSearchSpec = describe "goalieSearch" $ do
|
|||||||
goalieSearch "x" goalies `shouldBe` []
|
goalieSearch "x" goalies `shouldBe` []
|
||||||
|
|
||||||
context "exact match" $
|
context "exact match" $
|
||||||
it "should return Steve" $
|
it "should return Bob" $
|
||||||
goalieSearch "Bob" goalies `shouldBe` [result 1]
|
goalieSearch "bob" goalies `shouldBe` [result 1]
|
||||||
|
|
||||||
goalieSearchExactSpec :: Spec
|
goalieSearchExactSpec :: Spec
|
||||||
goalieSearchExactSpec = describe "goalieSearchExact" $ do
|
goalieSearchExactSpec = describe "goalieSearchExact" $ do
|
||||||
@@ -782,6 +757,77 @@ goalieSummarySpec = describe "goalieSummary" $
|
|||||||
it "should provide a summary string" $
|
it "should provide a summary string" $
|
||||||
goalieSummary (newGoalie 2 "Joe") `shouldBe` "Joe (2)"
|
goalieSummary (newGoalie 2 "Joe") `shouldBe` "Joe (2)"
|
||||||
|
|
||||||
|
goalieIsActiveSpec :: Spec
|
||||||
|
goalieIsActiveSpec = describe "goalieIsActive" $ mapM_
|
||||||
|
(\(label, input, expected) -> context label $
|
||||||
|
it ("should be " ++ show expected) $
|
||||||
|
goalieIsActive input `shouldBe` expected)
|
||||||
|
|
||||||
|
-- label, input, expected
|
||||||
|
[ ( "inactive", inactive, False )
|
||||||
|
, ( "active", active, True )
|
||||||
|
]
|
||||||
|
|
||||||
|
where
|
||||||
|
inactive = newGoalie 1 "Joe"
|
||||||
|
& gLifetime.gsMinsPlayed .~ 1
|
||||||
|
|
||||||
|
active = inactive
|
||||||
|
& gYtd.gsMinsPlayed .~ 1
|
||||||
|
|
||||||
|
addGoalieStatsSpec :: Spec
|
||||||
|
addGoalieStatsSpec = describe "addGoalieStats" $ let
|
||||||
|
g1 = GoalieStats
|
||||||
|
{ _gsGames = 1
|
||||||
|
, _gsMinsPlayed = 2
|
||||||
|
, _gsGoalsAllowed = 3
|
||||||
|
, _gsShutouts = 4
|
||||||
|
, _gsWins = 5
|
||||||
|
, _gsLosses = 6
|
||||||
|
, _gsTies = 7
|
||||||
|
}
|
||||||
|
|
||||||
|
g2 = GoalieStats
|
||||||
|
{ _gsGames = 8
|
||||||
|
, _gsMinsPlayed = 9
|
||||||
|
, _gsGoalsAllowed = 10
|
||||||
|
, _gsShutouts = 11
|
||||||
|
, _gsWins = 12
|
||||||
|
, _gsLosses = 13
|
||||||
|
, _gsTies = 14
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = GoalieStats
|
||||||
|
{ _gsGames = 9
|
||||||
|
, _gsMinsPlayed = 11
|
||||||
|
, _gsGoalsAllowed = 13
|
||||||
|
, _gsShutouts = 15
|
||||||
|
, _gsWins = 17
|
||||||
|
, _gsLosses = 19
|
||||||
|
, _gsTies = 21
|
||||||
|
}
|
||||||
|
|
||||||
|
actual = g1 `addGoalieStats` g2
|
||||||
|
|
||||||
|
in it ("should be " ++ show expected) $
|
||||||
|
actual `shouldBe` expected
|
||||||
|
|
||||||
|
gsAverageSpec :: Spec
|
||||||
|
gsAverageSpec = describe "gsAverage" $ mapM_
|
||||||
|
(\(label, stats, expected) -> context label $
|
||||||
|
it ("should be " ++ show expected) $
|
||||||
|
gsAverage stats `shouldBe` expected)
|
||||||
|
|
||||||
|
-- label, stats, expected
|
||||||
|
[ ( "with minutes", gs, 3 % 2 )
|
||||||
|
, ( "no minutes", newGoalieStats , 0 )
|
||||||
|
]
|
||||||
|
|
||||||
|
where
|
||||||
|
gs = newGoalieStats
|
||||||
|
& gsMinsPlayed .~ 2 * gameLength
|
||||||
|
& gsGoalsAllowed .~ 3
|
||||||
|
|
||||||
joe :: Player
|
joe :: Player
|
||||||
joe = newPlayer 2 "Joe" "center"
|
joe = newPlayer 2 "Joe" "center"
|
||||||
|
|
||||||
@@ -824,7 +870,7 @@ makeGoalieStats = GoalieStats
|
|||||||
<*> makeNum
|
<*> makeNum
|
||||||
<*> makeNum
|
<*> makeNum
|
||||||
<*> makeNum
|
<*> makeNum
|
||||||
|
<*> makeNum
|
||||||
|
|
||||||
makeNum :: IO Int
|
makeNum :: IO Int
|
||||||
makeNum = randomRIO (1, 10)
|
makeNum = randomRIO (1, 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user