Merge pull request #83 from mtlstats/active-player-search
only search for active players/goalies on game input
This commit is contained in:
commit
85a8e3baf1
|
@ -1,5 +1,8 @@
|
||||||
# Changelog for mtlstats
|
# Changelog for mtlstats
|
||||||
|
|
||||||
|
## current
|
||||||
|
- only search for active players/goalies on game data input
|
||||||
|
|
||||||
## 0.15.0
|
## 0.15.0
|
||||||
- Ask for database to load on start-up
|
- Ask for database to load on start-up
|
||||||
- Add page break to report file
|
- Add page break to report file
|
||||||
|
|
|
@ -43,7 +43,9 @@ module Mtlstats.Prompt (
|
||||||
goalieNumPrompt,
|
goalieNumPrompt,
|
||||||
goalieNamePrompt,
|
goalieNamePrompt,
|
||||||
selectPlayerPrompt,
|
selectPlayerPrompt,
|
||||||
|
selectActivePlayerPrompt,
|
||||||
selectGoaliePrompt,
|
selectGoaliePrompt,
|
||||||
|
selectActiveGoaliePrompt,
|
||||||
selectPositionPrompt,
|
selectPositionPrompt,
|
||||||
playerToEditPrompt
|
playerToEditPrompt
|
||||||
) where
|
) where
|
||||||
|
@ -263,18 +265,21 @@ goalieNamePrompt :: Prompt
|
||||||
goalieNamePrompt = namePrompt "Goalie name: " $
|
goalieNamePrompt = namePrompt "Goalie name: " $
|
||||||
modify . (progMode.createGoalieStateL.cgsName .~)
|
modify . (progMode.createGoalieStateL.cgsName .~)
|
||||||
|
|
||||||
-- | Selects a player (creating one if necessary)
|
-- | Selects a player using a specified search function (creating the
|
||||||
selectPlayerPrompt
|
-- player if necessary)
|
||||||
:: String
|
selectPlayerPromptWith
|
||||||
|
:: (String -> [Player] -> [(Int, Player)])
|
||||||
|
-- ^ The search function
|
||||||
|
-> String
|
||||||
-- ^ The prompt string
|
-- ^ The prompt string
|
||||||
-> (Maybe Int -> Action ())
|
-> (Maybe Int -> Action ())
|
||||||
-- ^ The callback to run (takes the index number of the payer as
|
-- ^ The callback to run (takes the index number of the payer as
|
||||||
-- input)
|
-- input)
|
||||||
-> Prompt
|
-> Prompt
|
||||||
selectPlayerPrompt pStr callback = selectPrompt SelectParams
|
selectPlayerPromptWith sFunc pStr callback = selectPrompt SelectParams
|
||||||
{ spPrompt = pStr
|
{ spPrompt = pStr
|
||||||
, spSearchHeader = "Player select:"
|
, spSearchHeader = "Player select:"
|
||||||
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
|
, spSearch = \sStr db -> sFunc 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
|
, spProcessChar = capitalizeName
|
||||||
|
@ -292,18 +297,41 @@ selectPlayerPrompt pStr callback = selectPrompt SelectParams
|
||||||
modify $ progMode .~ CreatePlayer cps
|
modify $ progMode .~ CreatePlayer cps
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Selects a goalie (creating one if necessary)
|
-- | Selects a player (creating one if necessary)
|
||||||
selectGoaliePrompt
|
selectPlayerPrompt
|
||||||
:: String
|
:: String
|
||||||
-- ^ The prompt string
|
-- ^ The prompt string
|
||||||
-> (Maybe Int -> Action ())
|
-> (Maybe Int -> Action ())
|
||||||
|
-- ^ The callback to run (takes the index number of the payer as
|
||||||
|
-- input)
|
||||||
|
-> Prompt
|
||||||
|
selectPlayerPrompt = selectPlayerPromptWith playerSearch
|
||||||
|
|
||||||
|
-- | Selects an active player (creating one if necessary)
|
||||||
|
selectActivePlayerPrompt
|
||||||
|
:: String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (Maybe Int -> Action ())
|
||||||
|
-- ^ The callback to run (takes the index number of the payer as
|
||||||
|
-- input)
|
||||||
|
-> Prompt
|
||||||
|
selectActivePlayerPrompt = selectPlayerPromptWith activePlayerSearch
|
||||||
|
|
||||||
|
-- | Selects a goalie with a specified search criteria (creating the
|
||||||
|
-- goalie if necessary)
|
||||||
|
selectGoaliePromptWith
|
||||||
|
:: (String -> [Goalie] -> [(Int, Goalie)])
|
||||||
|
-- ^ The search criteria
|
||||||
|
-> String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (Maybe Int -> Action ())
|
||||||
-- ^ The callback to run (takes the index number of the goalie as
|
-- ^ The callback to run (takes the index number of the goalie as
|
||||||
-- input)
|
-- input)
|
||||||
-> Prompt
|
-> Prompt
|
||||||
selectGoaliePrompt pStr callback = selectPrompt SelectParams
|
selectGoaliePromptWith criteria pStr callback = selectPrompt SelectParams
|
||||||
{ spPrompt = pStr
|
{ spPrompt = pStr
|
||||||
, spSearchHeader = "Goalie select:"
|
, spSearchHeader = "Goalie select:"
|
||||||
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
|
, spSearch = \sStr db -> criteria 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
|
, spProcessChar = capitalizeName
|
||||||
|
@ -321,6 +349,26 @@ selectGoaliePrompt pStr callback = selectPrompt SelectParams
|
||||||
modify $ progMode .~ CreateGoalie cgs
|
modify $ progMode .~ CreateGoalie cgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Selects a goalie (creating one if necessary)
|
||||||
|
selectGoaliePrompt
|
||||||
|
:: String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (Maybe Int -> Action ())
|
||||||
|
-- ^ The callback to run (takes the index number of the goalie as
|
||||||
|
-- input)
|
||||||
|
-> Prompt
|
||||||
|
selectGoaliePrompt = selectGoaliePromptWith goalieSearch
|
||||||
|
|
||||||
|
-- | Selects an active goalie (creating one if necessary)
|
||||||
|
selectActiveGoaliePrompt
|
||||||
|
:: String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (Maybe Int -> Action ())
|
||||||
|
-- ^ The callback to run (takes the index number of the goalie as
|
||||||
|
-- input)
|
||||||
|
-> Prompt
|
||||||
|
selectActiveGoaliePrompt = selectGoaliePromptWith activeGoalieSearch
|
||||||
|
|
||||||
-- | Selects (or creates) a player position
|
-- | Selects (or creates) a player position
|
||||||
selectPositionPrompt
|
selectPositionPrompt
|
||||||
:: String
|
:: String
|
||||||
|
|
|
@ -76,7 +76,7 @@ recordGoalPrompt
|
||||||
-> Int
|
-> Int
|
||||||
-- ^ The goal number
|
-- ^ The goal number
|
||||||
-> Prompt
|
-> Prompt
|
||||||
recordGoalPrompt game goal = selectPlayerPrompt
|
recordGoalPrompt game goal = selectActivePlayerPrompt
|
||||||
( "*** GAME " ++ padNum 2 game ++ " ***\n"
|
( "*** GAME " ++ padNum 2 game ++ " ***\n"
|
||||||
++ "Who scored goal number " ++ show goal ++ "? "
|
++ "Who scored goal number " ++ show goal ++ "? "
|
||||||
) $ modify . (progMode.gameStateL.goalBy .~)
|
) $ modify . (progMode.gameStateL.goalBy .~)
|
||||||
|
@ -90,7 +90,7 @@ recordAssistPrompt
|
||||||
-> Int
|
-> Int
|
||||||
-- ^ The assist number
|
-- ^ The assist number
|
||||||
-> Prompt
|
-> Prompt
|
||||||
recordAssistPrompt game goal assist = selectPlayerPrompt
|
recordAssistPrompt game goal assist = selectActivePlayerPrompt
|
||||||
( "*** GAME " ++ padNum 2 game ++ " ***\n"
|
( "*** GAME " ++ padNum 2 game ++ " ***\n"
|
||||||
++ "Goal: " ++ show goal ++ "\n"
|
++ "Goal: " ++ show goal ++ "\n"
|
||||||
++ "Assist #" ++ show assist ++ ": "
|
++ "Assist #" ++ show assist ++ ": "
|
||||||
|
@ -104,7 +104,7 @@ recordAssistPrompt game goal assist = selectPlayerPrompt
|
||||||
|
|
||||||
-- | Prompts for the player to assign penalty minutes to
|
-- | Prompts for the player to assign penalty minutes to
|
||||||
pMinPlayerPrompt :: Prompt
|
pMinPlayerPrompt :: Prompt
|
||||||
pMinPlayerPrompt = selectPlayerPrompt
|
pMinPlayerPrompt = selectActivePlayerPrompt
|
||||||
"Assign penalty minutes to: " $
|
"Assign penalty minutes to: " $
|
||||||
\case
|
\case
|
||||||
Nothing -> modify $ progMode.gameStateL.gamePMinsRecorded .~ True
|
Nothing -> modify $ progMode.gameStateL.gamePMinsRecorded .~ True
|
||||||
|
|
|
@ -36,7 +36,8 @@ import Mtlstats.Types
|
||||||
|
|
||||||
-- | Prompts for a goalie who played in the game
|
-- | Prompts for a goalie who played in the game
|
||||||
selectGameGoaliePrompt :: Prompt
|
selectGameGoaliePrompt :: Prompt
|
||||||
selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $
|
selectGameGoaliePrompt = selectActiveGoaliePrompt
|
||||||
|
"Which goalie played this game: " $
|
||||||
\case
|
\case
|
||||||
Nothing -> modify finishGoalieEntry
|
Nothing -> modify finishGoalieEntry
|
||||||
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n
|
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n
|
||||||
|
|
|
@ -176,6 +176,7 @@ module Mtlstats.Types (
|
||||||
addGameStats,
|
addGameStats,
|
||||||
-- ** Player Helpers
|
-- ** Player Helpers
|
||||||
playerSearch,
|
playerSearch,
|
||||||
|
activePlayerSearch,
|
||||||
playerSearchExact,
|
playerSearchExact,
|
||||||
modifyPlayer,
|
modifyPlayer,
|
||||||
playerSummary,
|
playerSummary,
|
||||||
|
@ -185,6 +186,7 @@ module Mtlstats.Types (
|
||||||
addPlayerStats,
|
addPlayerStats,
|
||||||
-- ** Goalie Helpers
|
-- ** Goalie Helpers
|
||||||
goalieSearch,
|
goalieSearch,
|
||||||
|
activeGoalieSearch,
|
||||||
goalieSearchExact,
|
goalieSearchExact,
|
||||||
goalieSummary,
|
goalieSummary,
|
||||||
goalieIsActive,
|
goalieIsActive,
|
||||||
|
@ -1003,6 +1005,23 @@ addGameStats s1 s2 = GameStats
|
||||||
, _gmsGoalsAgainst = s1^.gmsGoalsAgainst + s2^.gmsGoalsAgainst
|
, _gmsGoalsAgainst = s1^.gmsGoalsAgainst + s2^.gmsGoalsAgainst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Searches through a list of players with a specified criteria
|
||||||
|
playerSearchWith
|
||||||
|
:: (Player -> Bool)
|
||||||
|
-- ^ The search criteria
|
||||||
|
-> String
|
||||||
|
-- ^ The search string
|
||||||
|
-> [Player]
|
||||||
|
-- ^ The list of players to search
|
||||||
|
-> [(Int, Player)]
|
||||||
|
-- ^ The matching players with their index numbers
|
||||||
|
playerSearchWith criteria sStr =
|
||||||
|
filter match . zip [0..]
|
||||||
|
where
|
||||||
|
match (_, p)
|
||||||
|
= map toUpper sStr `isInfixOf` map toUpper (p^.pName)
|
||||||
|
&& criteria p
|
||||||
|
|
||||||
-- | Searches through a list of players
|
-- | Searches through a list of players
|
||||||
playerSearch
|
playerSearch
|
||||||
:: String
|
:: String
|
||||||
|
@ -1011,9 +1030,17 @@ playerSearch
|
||||||
-- ^ The list of players to search
|
-- ^ The list of players to search
|
||||||
-> [(Int, Player)]
|
-> [(Int, Player)]
|
||||||
-- ^ The matching players with their index numbers
|
-- ^ The matching players with their index numbers
|
||||||
playerSearch sStr =
|
playerSearch = playerSearchWith $ const True
|
||||||
filter match . zip [0..]
|
|
||||||
where match (_, p) = map toUpper sStr `isInfixOf` map toUpper (p^.pName)
|
-- | Searches through a list of players for an active player
|
||||||
|
activePlayerSearch
|
||||||
|
:: String
|
||||||
|
-- ^ The search string
|
||||||
|
-> [Player]
|
||||||
|
-- ^ The list of players to search
|
||||||
|
-> [(Int, Player)]
|
||||||
|
-- ^ The matching players with their index numbers
|
||||||
|
activePlayerSearch = playerSearchWith (^.pActive)
|
||||||
|
|
||||||
-- | Searches for a player by exact match on name
|
-- | Searches for a player by exact match on name
|
||||||
playerSearchExact
|
playerSearchExact
|
||||||
|
@ -1068,6 +1095,23 @@ addPlayerStats s1 s2 = newPlayerStats
|
||||||
& psAssists .~ s1^.psAssists + s2^.psAssists
|
& psAssists .~ s1^.psAssists + s2^.psAssists
|
||||||
& psPMin .~ s1^.psPMin + s2^.psPMin
|
& psPMin .~ s1^.psPMin + s2^.psPMin
|
||||||
|
|
||||||
|
-- | Searches a list of goalies with a search criteria
|
||||||
|
goalieSearchWith
|
||||||
|
:: (Goalie -> Bool)
|
||||||
|
-- ^ The search criteria
|
||||||
|
-> String
|
||||||
|
-- ^ The search string
|
||||||
|
-> [Goalie]
|
||||||
|
-- ^ The list to search
|
||||||
|
-> [(Int, Goalie)]
|
||||||
|
-- ^ The search results with their corresponding index numbers
|
||||||
|
goalieSearchWith criteria sStr =
|
||||||
|
filter match . zip [0..]
|
||||||
|
where
|
||||||
|
match (_, g)
|
||||||
|
= map toUpper sStr `isInfixOf` map toUpper (g^.gName)
|
||||||
|
&& criteria g
|
||||||
|
|
||||||
-- | Searches a list of goalies
|
-- | Searches a list of goalies
|
||||||
goalieSearch
|
goalieSearch
|
||||||
:: String
|
:: String
|
||||||
|
@ -1076,9 +1120,17 @@ 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 =
|
goalieSearch = goalieSearchWith $ const True
|
||||||
filter match . zip [0..]
|
|
||||||
where match (_, g) = map toUpper sStr `isInfixOf` map toUpper (g^.gName)
|
-- | Searches a list of goalies for an active goalie
|
||||||
|
activeGoalieSearch
|
||||||
|
:: String
|
||||||
|
-- ^ The search string
|
||||||
|
-> [Goalie]
|
||||||
|
-- ^ The list to search
|
||||||
|
-> [(Int, Goalie)]
|
||||||
|
-- ^ The search results with their corresponding index numbers
|
||||||
|
activeGoalieSearch = goalieSearchWith (^.gActive)
|
||||||
|
|
||||||
-- | Searches a list of goalies for an exact match
|
-- | Searches a list of goalies for an exact match
|
||||||
goalieSearchExact
|
goalieSearchExact
|
||||||
|
|
|
@ -73,6 +73,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||||
gmsPointsSpec
|
gmsPointsSpec
|
||||||
addGameStatsSpec
|
addGameStatsSpec
|
||||||
playerSearchSpec
|
playerSearchSpec
|
||||||
|
activePlayerSearchSpec
|
||||||
playerSearchExactSpec
|
playerSearchExactSpec
|
||||||
modifyPlayerSpec
|
modifyPlayerSpec
|
||||||
playerSummarySpec
|
playerSummarySpec
|
||||||
|
@ -80,6 +81,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||||
psPointsSpec
|
psPointsSpec
|
||||||
addPlayerStatsSpec
|
addPlayerStatsSpec
|
||||||
goalieSearchSpec
|
goalieSearchSpec
|
||||||
|
activeGoalieSearchSpec
|
||||||
goalieSearchExactSpec
|
goalieSearchExactSpec
|
||||||
goalieSummarySpec
|
goalieSummarySpec
|
||||||
goalieIsActiveSpec
|
goalieIsActiveSpec
|
||||||
|
@ -647,6 +649,19 @@ playerSearchSpec = describe "playerSearch" $ mapM_
|
||||||
, ( "x", [] )
|
, ( "x", [] )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
activePlayerSearchSpec :: Spec
|
||||||
|
activePlayerSearchSpec = describe "activePlayerSearch" $ mapM_
|
||||||
|
(\(sStr, expected) -> context sStr $
|
||||||
|
it ("should return " ++ show expected) $ let
|
||||||
|
ps = [joe, bob, steve & pActive .~ False]
|
||||||
|
in activePlayerSearch sStr ps `shouldBe` expected)
|
||||||
|
-- search, result
|
||||||
|
[ ( "joe", [(0, joe)] )
|
||||||
|
, ( "o", [(0, joe), (1, bob)] )
|
||||||
|
, ( "e", [(0, joe)] )
|
||||||
|
, ( "x", [] )
|
||||||
|
]
|
||||||
|
|
||||||
playerSearchExactSpec :: Spec
|
playerSearchExactSpec :: Spec
|
||||||
playerSearchExactSpec = describe "playerSearchExact" $ mapM_
|
playerSearchExactSpec = describe "playerSearchExact" $ mapM_
|
||||||
(\(sStr, expected) -> context sStr $
|
(\(sStr, expected) -> context sStr $
|
||||||
|
@ -778,6 +793,28 @@ goalieSearchSpec = describe "goalieSearch" $ do
|
||||||
it "should return Bob" $
|
it "should return Bob" $
|
||||||
goalieSearch "bob" goalies `shouldBe` [result 1]
|
goalieSearch "bob" goalies `shouldBe` [result 1]
|
||||||
|
|
||||||
|
activeGoalieSearchSpec :: Spec
|
||||||
|
activeGoalieSearchSpec = describe "activeGoalieSearch" $ do
|
||||||
|
let
|
||||||
|
goalies =
|
||||||
|
[ newGoalie 2 "Joe"
|
||||||
|
, newGoalie 3 "Bob"
|
||||||
|
, newGoalie 5 "Steve" & gActive .~ False
|
||||||
|
]
|
||||||
|
result n = (n, goalies!!n)
|
||||||
|
|
||||||
|
context "partial match" $
|
||||||
|
it "should return Joe" $
|
||||||
|
activeGoalieSearch "e" goalies `shouldBe` [result 0]
|
||||||
|
|
||||||
|
context "no match" $
|
||||||
|
it "should return an empty list" $
|
||||||
|
activeGoalieSearch "x" goalies `shouldBe` []
|
||||||
|
|
||||||
|
context "exact match" $
|
||||||
|
it "should return Bob" $
|
||||||
|
activeGoalieSearch "bob" goalies `shouldBe` [result 1]
|
||||||
|
|
||||||
goalieSearchExactSpec :: Spec
|
goalieSearchExactSpec :: Spec
|
||||||
goalieSearchExactSpec = describe "goalieSearchExact" $ do
|
goalieSearchExactSpec = describe "goalieSearchExact" $ do
|
||||||
let
|
let
|
||||||
|
|
Loading…
Reference in New Issue
Block a user