implemented homeTeam and awayTeam

This commit is contained in:
Jonathan Lamothe
2019-09-02 18:50:21 -04:00
parent f0e0d644d2
commit 6136151614
3 changed files with 87 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
{- |
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.Config (myTeam) where
-- | The name of the team whose stats we're tracking
myTeam :: String
myTeam = "MONTREAL"
+20
View File
@@ -97,6 +97,8 @@ module Mtlstats.Types (
-- ** GameState Helpers
teamScore,
otherScore,
homeTeam,
awayTeam,
gameWon,
gameLost,
gameTied,
@@ -124,6 +126,8 @@ import Lens.Micro (Lens', lens, (&), (^.), (.~))
import Lens.Micro.TH (makeLenses)
import UI.NCurses (Curses, Update)
import Mtlstats.Config
-- | Action which maintains program state
type Action a = StateT ProgState Curses a
@@ -509,6 +513,22 @@ otherScore s = case s ^. gameType of
Just AwayGame -> s ^. homeScore
Nothing -> Nothing
-- | Returns the name of the home team (or an empty string if
-- unavailable)
homeTeam :: GameState -> String
homeTeam gs = case gs^.gameType of
Just HomeGame -> myTeam
Just AwayGame -> gs^.otherTeam
Nothing -> ""
-- | Returns the name of the visiting team (or an empty string if
-- unavailable)
awayTeam :: GameState -> String
awayTeam gs = case gs^.gameType of
Just HomeGame -> gs^.otherTeam
Just AwayGame -> myTeam
Nothing -> ""
-- | Checks if the game was won
gameWon :: GameState -> Maybe Bool
gameWon gs = (>) <$> teamScore gs <*> otherScore gs