Merge pull request #70 from mtlstats/sort-players

subsort players by lifetime points
This commit is contained in:
Jonathan Lamothe 2020-01-31 22:18:58 -05:00 committed by GitHub
commit 607a78ccea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -3,6 +3,7 @@
## current ## current
- Edit lifetime stats on new player/goalie creation - Edit lifetime stats on new player/goalie creation
- Sort goalies by minutes played - Sort goalies by minutes played
- Subsort players by lifetime points
## 0.11.0 ## 0.11.0
- Added active flag to players/goalies - Added active flag to players/goalies

View File

@ -117,7 +117,7 @@ gameStatsReport width s = let
gs = s^.progMode.gameStateL gs = s^.progMode.gameStateL
db = s^.database db = s^.database
playerStats = mapMaybe playerStats = sortPlayers $ mapMaybe
(\(pid, stats) -> do (\(pid, stats) -> do
p <- nth pid $ db^.dbPlayers p <- nth pid $ db^.dbPlayers
Just (p, stats)) Just (p, stats))
@ -139,7 +139,7 @@ yearToDateStatsReport :: Int -> ProgState -> [String]
yearToDateStatsReport width s = let yearToDateStatsReport width s = let
db = s^.database db = s^.database
playerStats = sortOn (Down . psPoints . snd) playerStats = sortPlayers
$ map (\p -> (p, p^.pYtd)) $ map (\p -> (p, p^.pYtd))
$ filter playerIsActive $ filter playerIsActive
$ db^.dbPlayers $ db^.dbPlayers
@ -156,7 +156,7 @@ lifetimeStatsReport :: Int -> ProgState -> [String]
lifetimeStatsReport width s = let lifetimeStatsReport width s = let
db = s^.database db = s^.database
playerStats = sortOn (Down . psPoints . snd) playerStats = sortPlayers
$ map (\p -> (p, p^.pLifetime)) $ map (\p -> (p, p^.pLifetime))
$ db^.dbPlayers $ db^.dbPlayers
@ -335,6 +335,10 @@ gameGoalieReport width goalieData = let
$ complexTable ([right, left] ++ repeat right) $ complexTable ([right, left] ++ repeat right)
$ header : body $ header : body
sortPlayers :: [(Player, PlayerStats)] -> [(Player, PlayerStats)]
sortPlayers = sortOn $ Down . \(p, ps) ->
(psPoints ps, psPoints $ p^.pLifetime)
sortGoalies :: [(Goalie, GoalieStats)] -> [(Goalie, GoalieStats)] sortGoalies :: [(Goalie, GoalieStats)] -> [(Goalie, GoalieStats)]
sortGoalies = sortOn $ Down . \(g, gs) -> sortGoalies = sortOn $ Down . \(g, gs) ->
(gs^.gsMinsPlayed, g^.gLifetime.gsMinsPlayed) (gs^.gsMinsPlayed, g^.gLifetime.gsMinsPlayed)