18 Commits
0.7.0 ... 0.8.0

Author SHA1 Message Date
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
8 changed files with 109 additions and 42 deletions

View File

@@ -1,5 +1,12 @@
# 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 ## 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.8.0
github: "mtlstats/mtlstats" github: "mtlstats/mtlstats"
license: GPL-3 license: GPL-3
author: "Jonathan Lamothe" author: "Jonathan Lamothe"

View File

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

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

@@ -125,9 +125,11 @@ 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 playerStats
++ [""] ++ [""]
++ goalieReport width goalieStats ++ gameGoalieReport width goalieStats
yearToDateStatsReport :: Int -> ProgState -> [String] yearToDateStatsReport :: Int -> ProgState -> [String]
yearToDateStatsReport width s = let yearToDateStatsReport width s = let
@@ -167,8 +169,18 @@ 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 =
filteredPlayerReport width label (const True) ps
filteredPlayerReport
:: Int
-> String
-> ((Player, PlayerStats) -> Bool)
-> [(Player, PlayerStats)]
-> [String]
filteredPlayerReport width label criteria 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 +208,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 '-')
@@ -240,7 +252,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
@@ -254,3 +266,27 @@ goalieReport width goalieData = let
$ overlayLast olayText $ overlayLast olayText
$ complexTable ([right, left] ++ repeat right) $ complexTable ([right, left] ++ repeat right)
$ header : body ++ [separator, summary] $ 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

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)
@@ -599,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
} }
@@ -904,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
@@ -967,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
@@ -1008,4 +1010,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

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