45 Commits
0.7.0 ... 0.9.0

Author SHA1 Message Date
Jonathan Lamothe
89fe646d0e version 0.9.0 2019-12-27 00:54:08 -05:00
Jonathan Lamothe
b35136944c Merge pull request #53 from mtlstats/edit-menu
implement edit menu
2019-12-17 22:57:42 -05:00
Jonathan Lamothe
4d41c454a1 updated change log 2019-12-17 22:52:21 -05:00
Jonathan Lamothe
18ba758c0c changed return wording on player/goalie edit menus 2019-12-17 22:50:39 -05:00
Jonathan Lamothe
3aedd01b08 make player/goalie edit return to edit menu on completion 2019-12-17 22:47:17 -05:00
Jonathan Lamothe
235dd4e611 return to edit menu after player/goalie creation 2019-12-17 12:30:55 -05:00
Jonathan Lamothe
adf09c2cc4 moved player/goalie creation to edit menu 2019-12-17 12:23:53 -05:00
Jonathan Lamothe
a44ecc5e24 implemented edit 2019-12-17 12:16:26 -05:00
Jonathan Lamothe
9980a095ed added edit menu to main menu 2019-12-17 12:05:10 -05:00
Jonathan Lamothe
1d6a4aa7f3 implemented editMenu 2019-12-17 12:05:10 -05:00
Jonathan Lamothe
8988ad9146 implemented Mtlstats.Control.editMenuC 2019-12-17 11:38:35 -05:00
Jonathan Lamothe
59d48ec154 added EditMenu mode 2019-12-17 11:32:32 -05:00
Jonathan Lamothe
be990538bc Merge pull request #52 from mtlstats/hlint
hlint suggestions
2019-12-17 11:27:41 -05:00
Jonathan Lamothe
55c8806186 hlint suggestions
hlint didn't like reverse, and suggested using Data.Ord Down instead
2019-12-17 11:19:38 -05:00
Jonathan Lamothe
0ecf899b56 Merge pull request #51 from mtlstats/sort-players
sort players in YTD/lifetime reports by points
2019-12-15 13:30:47 -05:00
Jonathan Lamothe
2f06fd221d sort descending 2019-12-15 13:26:22 -05:00
Jonathan Lamothe
f1227da9ca sort players in YTD/lifetime reports by points 2019-12-15 13:19:12 -05:00
Jonathan Lamothe
38db3c8d8f Merge pull request #50 from mtlstats/no-totals
don't show totals in lifetime stats
2019-12-15 12:33:30 -05:00
Jonathan Lamothe
2b9a21c28b don't show totals in lifetime stats 2019-12-15 12:27:06 -05:00
Jonathan Lamothe
84c487dba5 typo in change log 2019-12-15 11:05:22 -05:00
Jonathan Lamothe
6345e3d5d8 Merge pull request #49 from mtlstats/auto-capitalize
Auto capitalize player/goalie names
2019-12-14 01:25:44 -05:00
Jonathan Lamothe
0ca03b7f21 updated change log 2019-12-14 01:19:18 -05:00
Jonathan Lamothe
482f42dca7 force proper name capitalization on player/goalie creation 2019-12-14 01:15:00 -05:00
Jonathan Lamothe
996bad94f1 force capitalization of player/goalie names in player selection 2019-12-14 01:09:40 -05:00
Jonathan Lamothe
4ca0b54de2 Merge pull request #48 from mtlstats/bugfix
Bugfix: display lifetime statistics in report instead of year-to-date
2019-12-14 00:16:55 -05:00
Jonathan Lamothe
3738088dde display lifetime stats in report 2019-12-13 11:43:22 -05:00
Jonathan Lamothe
1ec9e93f16 hlint recommenfations 2019-12-13 11:42:49 -05:00
Jonathan Lamothe
9534218797 version 0.8.0 2019-12-12 18:24:30 -05:00
Jonathan Lamothe
d7d3d1a4fd Merge pull request #47 from mtlstats/goalie-average
correctly calculate goalie average
2019-12-02 20:53:59 -05:00
Jonathan Lamothe
86c4fe316e correctly calculate goalie average 2019-12-02 20:48:09 -05:00
Jonathan Lamothe
d5ac42268f Merge pull request #46 from mtlstats/remove-extra-stats
removed unnecessary goalie stats from game report
2019-12-02 20:23:58 -05:00
Jonathan Lamothe
df26e9d265 removed unnecessary goalie stats from game report 2019-12-02 20:17:19 -05:00
Jonathan Lamothe
cb5f2d7d15 Merge pull request #45 from mtlstats/filter-game-stats
filter out players without points from game report
2019-12-02 15:20:03 -05:00
Jonathan Lamothe
152ea76bda filter out players without points from game report 2019-12-02 15:08:18 -05:00
Jonathan Lamothe
36ab31a17c Merge pull request #44 from mtlstats/bugfix-uppercase-team
bugfix: force other team name to uppercase
2019-12-02 14:54:07 -05:00
Jonathan Lamothe
768cb47fac bugfix: force other team name to uppercase 2019-12-02 14:43:08 -05:00
Jonathan Lamothe
427ad12603 Merge pull request #43 from mtlstats/bugfix-uc-hangs
bugfix: uppercase prompt hangs
2019-12-02 14:34:39 -05:00
Jonathan Lamothe
1ca2ffc378 bugfix: uppercase prompt hangs 2019-12-02 13:46:43 -05:00
Jonathan Lamothe
9e6b71c464 Merge pull request #42 from mtlstats/lower-case
allow lower case player names
2019-11-30 21:53:07 -05:00
Jonathan Lamothe
2f4e963e41 update change log 2019-11-30 21:09:24 -05:00
Jonathan Lamothe
05af939963 force player position to upper case 2019-11-30 13:02:42 -05:00
Jonathan Lamothe
8af7974c8f made playerSearch and goalieSearch case insensitive 2019-11-30 12:54:50 -05:00
Jonathan Lamothe
f7cfd5d835 allow lower case
- allow strPrompt to accept lower case letters
- implemented ucStrPrompt which forces characters to upper case
2019-11-30 11:52:06 -05:00
Jonathan Lamothe
cc495fa589 Merge pull request #41 from mtlstats/bugfix
bugfix: removed quotation makrks from goalie name in report
2019-11-29 20:20:06 -05:00
Jonathan Lamothe
9c5d166f31 bugfix: removed quotation makrks from goalie name in report 2019-11-29 20:12:45 -05:00
18 changed files with 299 additions and 83 deletions

View File

@@ -1,5 +1,19 @@
# Changelog for mtlstats # Changelog for mtlstats
## 0.9.0
- Bugfix: Display lifetime stats in report, not YTD
- Force expected capitalization on player/goalie names
- Don't show lifetime totals in report
- Sort players in YTD and lifetime reports by points
- Moved player/goalie creation/editing to edit submenu
## 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 ## 0.7.0
- Shortened views to fit within 25 lines - Shortened views to fit within 25 lines
- Implemented goalie reports - Implemented goalie reports

View File

@@ -1,5 +1,5 @@
name: mtlstats name: mtlstats
version: 0.7.0 version: 0.9.0
github: "mtlstats/mtlstats" github: "mtlstats/mtlstats"
license: GPL-3 license: GPL-3
author: "Jonathan Lamothe" author: "Jonathan Lamothe"

View File

@@ -30,6 +30,7 @@ module Mtlstats.Actions
, removeChar , removeChar
, createPlayer , createPlayer
, createGoalie , createGoalie
, edit
, editPlayer , editPlayer
, editGoalie , editGoalie
, addPlayer , addPlayer
@@ -82,7 +83,7 @@ removeChar = inputBuffer %~ \case
-- | Starts player creation mode -- | Starts player creation mode
createPlayer :: ProgState -> ProgState createPlayer :: ProgState -> ProgState
createPlayer = let createPlayer = let
callback = modify $ progMode .~ MainMenu callback = modify edit
cps = newCreatePlayerState cps = newCreatePlayerState
& cpsSuccessCallback .~ callback & cpsSuccessCallback .~ callback
& cpsFailureCallback .~ callback & cpsFailureCallback .~ callback
@@ -91,12 +92,16 @@ createPlayer = let
-- | Starts goalie creation mode -- | Starts goalie creation mode
createGoalie :: ProgState -> ProgState createGoalie :: ProgState -> ProgState
createGoalie = let createGoalie = let
callback = modify $ progMode .~ MainMenu callback = modify edit
cgs = newCreateGoalieState cgs = newCreateGoalieState
& cgsSuccessCallback .~ callback & cgsSuccessCallback .~ callback
& cgsFailureCallback .~ callback & cgsFailureCallback .~ callback
in progMode .~ CreateGoalie cgs in progMode .~ CreateGoalie cgs
-- | Launches the edit menu
edit :: ProgState -> ProgState
edit = progMode .~ EditMenu
-- | Starts the player editing process -- | Starts the player editing process
editPlayer :: ProgState -> ProgState editPlayer :: ProgState -> ProgState
editPlayer = progMode .~ EditPlayer newEditPlayerState editPlayer = progMode .~ EditPlayer newEditPlayerState

View File

@@ -41,9 +41,10 @@ import Mtlstats.Types
-- run -- run
dispatch :: ProgState -> Controller dispatch :: ProgState -> Controller
dispatch s = case s^.progMode of dispatch s = case s^.progMode of
MainMenu -> mainMenuC MainMenu -> mainMenuC
NewSeason -> newSeasonC NewSeason -> newSeasonC
NewGame gs -> newGameC gs NewGame gs -> newGameC gs
EditMenu -> editMenuC
CreatePlayer cps CreatePlayer cps
| null $ cps^.cpsNumber -> getPlayerNumC | null $ cps^.cpsNumber -> getPlayerNumC
| null $ cps^.cpsName -> getPlayerNameC | null $ cps^.cpsName -> getPlayerNameC
@@ -70,6 +71,9 @@ newSeasonC = Controller
return True return True
} }
editMenuC :: Controller
editMenuC = menuController editMenu
getPlayerNumC :: Controller getPlayerNumC :: Controller
getPlayerNumC = Controller getPlayerNumC = Controller
{ drawController = drawPrompt playerNumPrompt { drawController = drawPrompt playerNumPrompt

View File

@@ -26,6 +26,7 @@ module Mtlstats.Format
, left , left
, right , right
, centre , centre
, padRight
, overlay , overlay
, month , month
, labelTable , labelTable
@@ -87,6 +88,16 @@ centre n str = let
pad = replicate pLen ' ' pad = replicate pLen ' '
in take n $ pad ++ str ++ repeat ' ' in take n $ pad ++ str ++ repeat ' '
-- | Pads text on the right with spaces to fit a minimum width
padRight
:: Int
-- ^ The width to pad to
-> String
-- ^ The text to pad
-> String
padRight width str =
overlay str $ replicate width ' '
-- | Overlays one string on top of another -- | Overlays one string on top of another
overlay overlay
:: String :: String

View File

@@ -31,7 +31,8 @@ module Mtlstats.Menu (
newSeasonMenu, newSeasonMenu,
gameMonthMenu, gameMonthMenu,
gameTypeMenu, gameTypeMenu,
gameGoalieMenu gameGoalieMenu,
editMenu
) where ) where
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
@@ -113,14 +114,8 @@ mainMenu = Menu "*** MAIN MENU ***" True
modify startNewSeason >> return True modify startNewSeason >> return True
, MenuItem '2' "New Game" $ , MenuItem '2' "New Game" $
modify startNewGame >> return True modify startNewGame >> return True
, MenuItem '3' "Create Player" $ , MenuItem '3' "Edit" $
modify createPlayer >> return True modify edit >> return True
, MenuItem '4' "Create Goalie" $
modify createGoalie >> return True
, MenuItem '5' "Edit Player" $
modify editPlayer >> return True
, MenuItem '6' "Edit Goalie" $
modify editGoalie >> return True
, MenuItem 'X' "Exit" $ do , MenuItem 'X' "Exit" $ do
db <- gets $ view database db <- gets $ view database
liftIO $ do liftIO $ do
@@ -186,3 +181,18 @@ gameGoalieMenu s = let
(\(ch, (gid, goalie)) -> MenuItem ch (goalieSummary goalie) $ (\(ch, (gid, goalie)) -> MenuItem ch (goalieSummary goalie) $
modify $ GI.setGameGoalie gid) $ modify $ GI.setGameGoalie gid) $
zip ['1'..] goalies zip ['1'..] goalies
-- | The edit menu
editMenu :: Menu ()
editMenu = Menu "*** EDIT ***" ()
[ MenuItem '1' "Create Player" $
modify createPlayer
, MenuItem '2' "Create Goalie" $
modify createGoalie
, MenuItem '3' "Edit Player" $
modify editPlayer
, MenuItem '4' "Edit Goalie" $
modify editGoalie
, MenuItem 'R' "Return to Main Menu" $
modify backHome
]

View File

@@ -26,25 +26,25 @@ module Mtlstats.Menu.EditGoalie
) where ) where
import Control.Monad.Trans.State (modify) import Control.Monad.Trans.State (modify)
import Data.Maybe (maybe)
import Lens.Micro ((.~)) import Lens.Micro ((.~))
import Mtlstats.Actions
import Mtlstats.Types import Mtlstats.Types
import Mtlstats.Types.Menu import Mtlstats.Types.Menu
-- | The 'Goalie' edit menu -- | The 'Goalie' edit menu
editGoalieMenu :: Menu () editGoalieMenu :: Menu ()
editGoalieMenu = Menu "*** EDIT GOALTENDER ***" () $ map editGoalieMenu = Menu "*** EDIT GOALTENDER ***" () $ map
(\(key, label, val) -> MenuItem key label $ modify $ maybe (\(ch, label, mode) -> MenuItem ch label $
(progMode .~ MainMenu) modify $ case mode of
(progMode.editGoalieStateL.egsMode .~) Nothing -> edit
val) Just m -> progMode.editGoalieStateL.egsMode .~ m)
-- key, label, value -- key, label, value
[ ( '1', "Edit number", Just EGNumber ) [ ( '1', "Edit number", Just EGNumber )
, ( '2', "Edit name", Just EGName ) , ( '2', "Edit name", Just EGName )
, ( '3', "Edit YTD stats", Just EGYtd ) , ( '3', "Edit YTD stats", Just EGYtd )
, ( '4', "Edit Lifetime stats", Just EGLifetime ) , ( '4', "Edit Lifetime stats", Just EGLifetime )
, ( 'R', "Return to Main Menu", Nothing ) , ( 'R', "Return to Edit Menu", Nothing )
] ]
-- | The 'Goalie' YTD edit menu -- | The 'Goalie' YTD edit menu

View File

@@ -28,22 +28,24 @@ module Mtlstats.Menu.EditPlayer
import Control.Monad.Trans.State (modify) import Control.Monad.Trans.State (modify)
import Lens.Micro ((.~)) import Lens.Micro ((.~))
import Mtlstats.Actions
import Mtlstats.Types import Mtlstats.Types
import Mtlstats.Types.Menu import Mtlstats.Types.Menu
-- | The 'Player' edit menu -- | The 'Player' edit menu
editPlayerMenu :: Menu () editPlayerMenu :: Menu ()
editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
(\(ch, label, mode) -> MenuItem ch label $ case mode of (\(ch, label, mode) -> MenuItem ch label $
Nothing -> modify $ progMode .~ MainMenu modify $ case mode of
Just m -> modify $ progMode.editPlayerStateL.epsMode .~ m) Nothing -> edit
Just m -> progMode.editPlayerStateL.epsMode .~ m)
-- key, label, value -- key, label, value
[ ( '1', "Edit number", Just EPNumber ) [ ( '1', "Edit number", Just EPNumber )
, ( '2', "Edit name", Just EPName ) , ( '2', "Edit name", Just EPName )
, ( '3', "Edit position", Just EPPosition ) , ( '3', "Edit position", Just EPPosition )
, ( '4', "Edit YTD stats", Just EPYtd ) , ( '4', "Edit YTD stats", Just EPYtd )
, ( '5', "Edit lifetime stats", Just EPLifetime ) , ( '5', "Edit lifetime stats", Just EPLifetime )
, ( 'R', "Finished editing", Nothing ) , ( 'R', "Return to Edit Menu", Nothing )
] ]
-- | The 'Player' YTD stats edit menu -- | The 'Player' YTD stats edit menu

View File

@@ -28,6 +28,8 @@ module Mtlstats.Prompt (
promptControllerWith, promptControllerWith,
promptController, promptController,
strPrompt, strPrompt,
ucStrPrompt,
namePrompt,
numPrompt, numPrompt,
selectPrompt, selectPrompt,
-- * Individual prompts -- * Individual prompts
@@ -46,7 +48,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 +70,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 +111,33 @@ 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]) }
-- | Creates a prompt which forces capitalization of input to
-- accomodate a player or goalie name
namePrompt
:: String
-- ^ The prompt string
-> (String -> Action ())
-- ^ The callback function for the result
-> Prompt
namePrompt pStr act = (strPrompt pStr act)
{ promptProcessChar = capitalizeName }
-- | Builds a numeric prompt -- | Builds a numeric prompt
numPrompt numPrompt
:: String :: String
@@ -125,10 +146,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 +169,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 = spProcessChar params
, promptAction = \sStr -> if null sStr , promptAction = \sStr -> if null sStr
then spCallback params Nothing then spCallback params Nothing
else do else do
@@ -175,12 +198,12 @@ playerNumPrompt = numPrompt "Player number: " $
-- | Prompts for a new player's name -- | Prompts for a new player's name
playerNamePrompt :: Prompt playerNamePrompt :: Prompt
playerNamePrompt = strPrompt "Player name: " $ playerNamePrompt = namePrompt "Player name: " $
modify . (progMode.createPlayerStateL.cpsName .~) modify . (progMode.createPlayerStateL.cpsName .~)
-- | 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
@@ -190,7 +213,7 @@ goalieNumPrompt = numPrompt "Goalie number: " $
-- | Prompts for the goalie's name -- | Prompts for the goalie's name
goalieNamePrompt :: Prompt goalieNamePrompt :: Prompt
goalieNamePrompt = strPrompt "Goalie name: " $ goalieNamePrompt = namePrompt "Goalie name: " $
modify . (progMode.createGoalieStateL.cgsName .~) modify . (progMode.createGoalieStateL.cgsName .~)
-- | Selects a player (creating one if necessary) -- | Selects a player (creating one if necessary)
@@ -207,6 +230,7 @@ selectPlayerPrompt pStr callback = selectPrompt SelectParams
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers) , spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
, spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers) , spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
, spElemDesc = playerSummary , spElemDesc = playerSummary
, spProcessChar = capitalizeName
, spCallback = callback , spCallback = callback
, spNotFound = \sStr -> do , spNotFound = \sStr -> do
mode <- gets (^.progMode) mode <- gets (^.progMode)
@@ -235,6 +259,7 @@ selectGoaliePrompt pStr callback = selectPrompt SelectParams
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies) , spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies) , spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
, spElemDesc = goalieSummary , spElemDesc = goalieSummary
, spProcessChar = capitalizeName
, spCallback = callback , spCallback = callback
, spNotFound = \sStr -> do , spNotFound = \sStr -> do
mode <- gets (^.progMode) mode <- gets (^.progMode)

View File

@@ -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

View File

@@ -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

View File

@@ -21,8 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Report (report, gameDate) where module Mtlstats.Report (report, gameDate) where
import Data.List (sortOn)
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe (fromMaybe, mapMaybe) import Data.Maybe (fromMaybe, mapMaybe)
import Data.Ord (Down (Down))
import Lens.Micro ((^.)) import Lens.Micro ((^.))
import Mtlstats.Config import Mtlstats.Config
@@ -125,15 +127,18 @@ gameStatsReport width s = let
Just (g, stats)) Just (g, stats))
(M.toList $ gs^.gameGoalieStats) (M.toList $ gs^.gameGoalieStats)
in playerReport width "GAME" playerStats criteria (_, ps) = psPoints ps > 0
in filteredPlayerReport width "GAME" criteria True playerStats
++ [""] ++ [""]
++ goalieReport width goalieStats ++ gameGoalieReport width goalieStats
yearToDateStatsReport :: Int -> ProgState -> [String] yearToDateStatsReport :: Int -> ProgState -> [String]
yearToDateStatsReport width s = let yearToDateStatsReport width s = let
db = s^.database db = s^.database
playerStats = map (\p -> (p, p^.pYtd)) playerStats = sortOn (Down . psPoints . snd)
$ map (\p -> (p, p^.pYtd))
$ filter playerIsActive $ filter playerIsActive
$ db^.dbPlayers $ db^.dbPlayers
@@ -141,23 +146,24 @@ yearToDateStatsReport width s = let
$ filter goalieIsActive $ filter goalieIsActive
$ db^.dbGoalies $ db^.dbGoalies
in playerReport width "YEAR TO DATE" playerStats in playerReport width "YEAR TO DATE" True playerStats
++ [""] ++ [""]
++ goalieReport width goalieStats ++ goalieReport width True goalieStats
lifetimeStatsReport :: Int -> ProgState -> [String] lifetimeStatsReport :: Int -> ProgState -> [String]
lifetimeStatsReport width s = let lifetimeStatsReport width s = let
db = s^.database db = s^.database
playerStats = map (\p -> (p, p^.pYtd)) playerStats = sortOn (Down . psPoints . snd)
$ map (\p -> (p, p^.pLifetime))
$ db^.dbPlayers $ db^.dbPlayers
goalieStats = map (\g -> (g, g^.gYtd)) goalieStats = map (\g -> (g, g^.gLifetime))
$ db^.dbGoalies $ db^.dbGoalies
in playerReport width "LIFETIME" playerStats in playerReport width "LIFETIME" False playerStats
++ [""] ++ [""]
++ goalieReport width goalieStats ++ goalieReport width False goalieStats
gameDate :: GameState -> String gameDate :: GameState -> String
gameDate gs = fromMaybe "" $ do gameDate gs = fromMaybe "" $ do
@@ -166,9 +172,25 @@ gameDate gs = fromMaybe "" $ do
d <- padNum 2 <$> gs^.gameDay d <- padNum 2 <$> gs^.gameDay
Just $ m ++ " " ++ d ++ " " ++ y Just $ m ++ " " ++ d ++ " " ++ y
playerReport :: Int -> String -> [(Player, PlayerStats)] -> [String] playerReport
playerReport width label ps = let :: Int
-> String
-> Bool
-> [(Player, PlayerStats)]
-> [String]
playerReport width label =
filteredPlayerReport width label (const True)
filteredPlayerReport
:: Int
-> String
-> ((Player, PlayerStats) -> Bool)
-> Bool
-> [(Player, PlayerStats)]
-> [String]
filteredPlayerReport width label criteria showTotals ps = let
tStats = foldl addPlayerStats newPlayerStats $ map snd ps tStats = foldl addPlayerStats newPlayerStats $ map snd ps
fps = filter criteria ps
rHeader = rHeader =
[ centre width (label ++ " STATISTICS") [ centre width (label ++ " STATISTICS")
@@ -196,7 +218,7 @@ playerReport width label ps = let
[ CellText $ show (p^.pNumber) ++ " " [ CellText $ show (p^.pNumber) ++ " "
, CellText $ p^.pName , CellText $ p^.pName
] ++ statsCells stats) ] ++ statsCells stats)
ps fps
separator = replicate 2 (CellText "") ++ replicate 4 (CellFill '-') separator = replicate 2 (CellText "") ++ replicate 4 (CellFill '-')
@@ -205,23 +227,35 @@ playerReport width label ps = let
, CellText "" , CellText ""
] ++ statsCells tStats ] ++ statsCells tStats
table = overlayLast (label ++ " TOTALS") olayText = if showTotals
then label ++ " TOTALS"
else ""
table = overlayLast olayText
$ map (centre width) $ map (centre width)
$ complexTable ([right, left] ++ repeat right) $ complexTable ([right, left] ++ repeat right)
$ tHeader : body ++ [separator, totals] $ tHeader : body ++ if showTotals
then [separator, totals]
else []
in rHeader ++ table in rHeader ++ table
goalieReport :: Int -> [(Goalie, GoalieStats)] -> [String] goalieReport
goalieReport width goalieData = let :: Int
olayText = "GOALTENDING TOTALS" -> Bool
-> [(Goalie, GoalieStats)]
-> [String]
goalieReport width showTotals goalieData = let
olayText = if showTotals
then "GOALTENDING TOTALS"
else ""
tData = foldl addGoalieStats newGoalieStats tData = foldl addGoalieStats newGoalieStats
$ map snd goalieData $ map snd goalieData
header = header =
[ CellText "NO." [ CellText "NO."
, CellText $ left (length olayText) "GOALTENDER" , CellText $ padRight (length olayText) "GOALTENDER"
, CellText "GP" , CellText "GP"
, CellText " MIN" , CellText " MIN"
, CellText " GA" , CellText " GA"
@@ -240,7 +274,7 @@ goalieReport width goalieData = let
body = map body = map
(\(goalie, stats) -> (\(goalie, stats) ->
[ CellText $ show (goalie^.gNumber) ++ " " [ CellText $ show (goalie^.gNumber) ++ " "
, CellText $ show $ goalie^.gName , CellText $ goalie^.gName
] ++ rowCells stats) ] ++ rowCells stats)
goalieData goalieData
@@ -253,4 +287,30 @@ goalieReport width goalieData = let
in map (centre width) in map (centre width)
$ overlayLast olayText $ overlayLast olayText
$ complexTable ([right, left] ++ repeat right) $ complexTable ([right, left] ++ repeat right)
$ header : body ++ [separator, summary] $ header : body ++ if showTotals
then [separator, summary]
else []
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

View File

@@ -192,6 +192,7 @@ import Data.Aeson
, (.!=) , (.!=)
, (.=) , (.=)
) )
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)
@@ -229,6 +230,7 @@ data ProgMode
= MainMenu = MainMenu
| NewSeason | NewSeason
| NewGame GameState | NewGame GameState
| EditMenu
| CreatePlayer CreatePlayerState | CreatePlayer CreatePlayerState
| CreateGoalie CreateGoalieState | CreateGoalie CreateGoalieState
| EditPlayer EditPlayerState | EditPlayer EditPlayerState
@@ -238,6 +240,7 @@ instance Show ProgMode where
show MainMenu = "MainMenu" show MainMenu = "MainMenu"
show NewSeason = "NewSeason" show NewSeason = "NewSeason"
show (NewGame _) = "NewGame" show (NewGame _) = "NewGame"
show EditMenu = "EditMenu"
show (CreatePlayer _) = "CreatePlayer" show (CreatePlayer _) = "CreatePlayer"
show (CreateGoalie _) = "CreateGoalie" show (CreateGoalie _) = "CreateGoalie"
show (EditPlayer _) = "EditPlayer" show (EditPlayer _) = "EditPlayer"
@@ -599,13 +602,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
} }
@@ -621,6 +624,8 @@ data SelectParams a = SelectParams
-- ^ Search function looking for an exact match -- ^ Search function looking for an exact match
, spElemDesc :: a -> String , spElemDesc :: a -> String
-- ^ Provides a string description of an element -- ^ Provides a string description of an element
, spProcessChar :: Char -> String -> String
-- ^ Processes a character entered by the user
, spCallback :: Maybe Int -> Action () , spCallback :: Maybe Int -> Action ()
-- ^ The function when the selection is made -- ^ The function when the selection is made
, spNotFound :: String -> Action () , spNotFound :: String -> Action ()
@@ -904,7 +909,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
@@ -967,8 +972,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
@@ -1008,4 +1014,10 @@ addGoalieStats g1 g2 = GoalieStats
-- | Determines a goalie's average goals allowed per game. -- | Determines a goalie's average goals allowed per game.
gsAverage :: GoalieStats -> Rational gsAverage :: GoalieStats -> Rational
gsAverage gs = fromIntegral (gs^.gsGoalsAllowed) / fromIntegral (gs^.gsGames) gsAverage gs = let
allowed = fromIntegral $ gs^.gsGoalsAllowed
mins = fromIntegral $ gs^.gsMinsPlayed
gLen = fromIntegral gameLength
in if mins == 0
then 0
else allowed / mins * gLen

View File

@@ -19,8 +19,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
-} -}
module Mtlstats.Util (nth, modifyNth, updateMap, slice) where module Mtlstats.Util
( nth
, modifyNth
, updateMap
, slice
, capitalizeName
) where
import Data.Char (isSpace, toUpper)
import qualified Data.Map as M import qualified Data.Map as M
-- | Attempt to select the element from a list at a given index -- | Attempt to select the element from a list at a given index
@@ -75,3 +82,25 @@ slice
-- ^ The list to take a subset of -- ^ The list to take a subset of
-> [a] -> [a]
slice offset len = take len . drop offset slice offset len = take len . drop offset
-- | Name capitalization function for a player
capitalizeName
:: Char
-- ^ The character being input
-> String
-- ^ The current string
-> String
-- ^ The resulting string
capitalizeName ch str = str ++ [ch']
where
ch' = if lockFlag str
then toUpper ch
else ch
lockFlag "" = True
lockFlag (c:cs)
| c == ',' = lockFlag' cs
| otherwise = lockFlag cs
lockFlag' "" = True
lockFlag' (c:cs)
| isSpace c = lockFlag' cs
| otherwise = False

View File

@@ -52,6 +52,7 @@ spec = describe "Mtlstats.Actions" $ do
removeCharSpec removeCharSpec
createPlayerSpec createPlayerSpec
createGoalieSpec createGoalieSpec
editSpec
editPlayerSpec editPlayerSpec
editGoalieSpec editGoalieSpec
addPlayerSpec addPlayerSpec
@@ -198,6 +199,12 @@ createGoalieSpec = describe "createGoalie" $
s = createGoalie newProgState s = createGoalie newProgState
in show (s^.progMode) `shouldBe` "CreateGoalie" in show (s^.progMode) `shouldBe` "CreateGoalie"
editSpec :: Spec
editSpec = describe "edit" $
it "should change the mode to EditMenu" $ let
ps = edit newProgState
in show (ps^.progMode) `shouldBe` "EditMenu"
editPlayerSpec :: Spec editPlayerSpec :: Spec
editPlayerSpec = describe "editPlayer" $ editPlayerSpec = describe "editPlayer" $
it "should change the mode appropriately" $ let it "should change the mode appropriately" $ let

View File

@@ -33,6 +33,7 @@ spec = describe "Mtlstats.Format" $ do
leftSpec leftSpec
rightSpec rightSpec
centreSpec centreSpec
padRightSpec
overlaySpec overlaySpec
monthSpec monthSpec
labelTableSpec labelTableSpec
@@ -98,6 +99,16 @@ centreSpec = describe "centre" $ do
it "should truncate the text" $ it "should truncate the text" $
centre 2 "foo" `shouldBe` "fo" centre 2 "foo" `shouldBe` "fo"
padRightSpec :: Spec
padRightSpec = describe "padRight" $ mapM_
(\(label, width, str, expected) -> context label $
it ("should be " ++ show expected) $
padRight width str `shouldBe` expected)
-- label, width, input string, expected
[ ( "text shorter", 5, "foo", "foo " )
, ( "text longer", 3, "foobar", "foobar" )
]
overlaySpec :: Spec overlaySpec :: Spec
overlaySpec = describe "overlay" $ do overlaySpec = describe "overlay" $ do

View File

@@ -591,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", [] )
@@ -725,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
@@ -813,15 +813,20 @@ addGoalieStatsSpec = describe "addGoalieStats" $ let
actual `shouldBe` expected actual `shouldBe` expected
gsAverageSpec :: Spec gsAverageSpec :: Spec
gsAverageSpec = describe "gsAverage" $ let gsAverageSpec = describe "gsAverage" $ mapM_
gs = newGoalieStats (\(label, stats, expected) -> context label $
& gsGames .~ 2 it ("should be " ++ show expected) $
& gsGoalsAllowed .~ 3 gsAverage stats `shouldBe` expected)
expected = 3 % 2 -- label, stats, expected
[ ( "with minutes", gs, 3 % 2 )
, ( "no minutes", newGoalieStats , 0 )
]
in it ("should be " ++ show expected) $ where
gsAverage gs `shouldBe` expected gs = newGoalieStats
& gsMinsPlayed .~ 2 * gameLength
& gsGoalsAllowed .~ 3
joe :: Player joe :: Player
joe = newPlayer 2 "Joe" "center" joe = newPlayer 2 "Joe" "center"

View File

@@ -32,6 +32,7 @@ spec = describe "Mtlstats.Util" $ do
modifyNthSpec modifyNthSpec
updateMapSpec updateMapSpec
sliceSpec sliceSpec
capitalizeNameSpec
nthSpec :: Spec nthSpec :: Spec
nthSpec = describe "nth" $ mapM_ nthSpec = describe "nth" $ mapM_
@@ -93,3 +94,23 @@ sliceSpec = describe "slice" $ do
context "negative offset" $ context "negative offset" $
it "should return the correct number of elements from the beginning" $ it "should return the correct number of elements from the beginning" $
slice (-10) 2 list `shouldBe` [2, 4] slice (-10) 2 list `shouldBe` [2, 4]
capitalizeNameSpec :: Spec
capitalizeNameSpec = describe "capitalizeName" $ mapM_
(\(label, ch, str, expected) -> context label $
it ("should be " ++ expected) $
capitalizeName ch str `shouldBe` expected)
-- label, character, string, expected
[ ( "initial lower", 'a', "", "A" )
, ( "initial upper", 'A', "", "A" )
, ( "initial non-alpha", '0', "", "0" )
, ( "pre-comma lower", 'a', "A", "AA" )
, ( "pre-comma upper", 'A', "A", "AA" )
, ( "pre-comma non-alpha", '0', "A", "A0" )
, ( "post-comma first lower", 'a', "FOO, ", "FOO, A" )
, ( "post-comma first upper", 'A', "FOO, ", "FOO, A" )
, ( "post-comma first non-alpha", '0', "FOO, ", "FOO, 0" )
, ( "unrestricted upper", 'A', "FOO, A", "FOO, AA" )
, ( "unrestricted lower", 'a', "FOO, A", "FOO, Aa" )
, ( "unrestricted non-alpha", '0', "FOO, A", "FOO, A0" )
]