added _dbHomeGameStats and _dbAwayGameStats with associated lenses
This commit is contained in:
parent
3e4a9dd525
commit
13d422100b
@ -54,6 +54,8 @@ module Mtlstats.Types (
|
|||||||
dbPlayers,
|
dbPlayers,
|
||||||
dbGoalies,
|
dbGoalies,
|
||||||
dbGames,
|
dbGames,
|
||||||
|
dbHomeGameStats,
|
||||||
|
dbAwayGameStats,
|
||||||
-- ** Player Lenses
|
-- ** Player Lenses
|
||||||
pNumber,
|
pNumber,
|
||||||
pName,
|
pName,
|
||||||
@ -154,12 +156,16 @@ data GameType
|
|||||||
|
|
||||||
-- | Represents the database
|
-- | Represents the database
|
||||||
data Database = Database
|
data Database = Database
|
||||||
{ _dbPlayers :: [Player]
|
{ _dbPlayers :: [Player]
|
||||||
-- ^ The list of players
|
-- ^ The list of players
|
||||||
, _dbGoalies :: [Goalie]
|
, _dbGoalies :: [Goalie]
|
||||||
-- ^ The list of goalies
|
-- ^ The list of goalies
|
||||||
, _dbGames :: Int
|
, _dbGames :: Int
|
||||||
-- ^ The number of games recorded
|
-- ^ The number of games recorded
|
||||||
|
, _dbHomeGameStats :: GameStats
|
||||||
|
-- ^ Statistics for home games
|
||||||
|
, _dbAwayGameStats :: GameStats
|
||||||
|
-- ^ Statistics for away games
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
instance FromJSON Database where
|
instance FromJSON Database where
|
||||||
@ -167,17 +173,23 @@ instance FromJSON Database where
|
|||||||
<$> v .: "players"
|
<$> v .: "players"
|
||||||
<*> v .: "goalies"
|
<*> v .: "goalies"
|
||||||
<*> v .: "games"
|
<*> v .: "games"
|
||||||
|
<*> v .: "home_game_stats"
|
||||||
|
<*> v .: "away_game_stats"
|
||||||
|
|
||||||
instance ToJSON Database where
|
instance ToJSON Database where
|
||||||
toJSON (Database players goalies games) = object
|
toJSON (Database players goalies games hgs ags) = object
|
||||||
[ "players" .= players
|
[ "players" .= players
|
||||||
, "goalies" .= goalies
|
, "goalies" .= goalies
|
||||||
, "games" .= games
|
, "games" .= games
|
||||||
|
, "home_game_stats" .= hgs
|
||||||
|
, "away_game_stats" .= ags
|
||||||
]
|
]
|
||||||
toEncoding (Database players goalies games) = pairs $
|
toEncoding (Database players goalies games hgs ags) = pairs $
|
||||||
"players" .= players <>
|
"players" .= players <>
|
||||||
"goalies" .= goalies <>
|
"goalies" .= goalies <>
|
||||||
"games" .= games
|
"games" .= games <>
|
||||||
|
"home_game_stats" .= hgs <>
|
||||||
|
"away_game_stats" .= ags
|
||||||
|
|
||||||
-- | Represents a (non-goalie) player
|
-- | Represents a (non-goalie) player
|
||||||
data Player = Player
|
data Player = Player
|
||||||
@ -426,9 +438,11 @@ newGameState = GameState
|
|||||||
-- | Constructor for a 'Database'
|
-- | Constructor for a 'Database'
|
||||||
newDatabase :: Database
|
newDatabase :: Database
|
||||||
newDatabase = Database
|
newDatabase = Database
|
||||||
{ _dbPlayers = []
|
{ _dbPlayers = []
|
||||||
, _dbGoalies = []
|
, _dbGoalies = []
|
||||||
, _dbGames = 0
|
, _dbGames = 0
|
||||||
|
, _dbHomeGameStats = newGameStats
|
||||||
|
, _dbAwayGameStats = newGameStats
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Constructor for a 'Player'
|
-- | Constructor for a 'Player'
|
||||||
|
@ -312,13 +312,17 @@ gameStatsJSON n = Object $ HM.fromList
|
|||||||
|
|
||||||
db :: Database
|
db :: Database
|
||||||
db = newDatabase
|
db = newDatabase
|
||||||
& dbPlayers .~ [player]
|
& dbPlayers .~ [player]
|
||||||
& dbGoalies .~ [goalie]
|
& dbGoalies .~ [goalie]
|
||||||
& dbGames .~ 1
|
& dbGames .~ 1
|
||||||
|
& dbHomeGameStats .~ gameStats 1
|
||||||
|
& dbAwayGameStats .~ gameStats 2
|
||||||
|
|
||||||
dbJSON :: Value
|
dbJSON :: Value
|
||||||
dbJSON = Object $ HM.fromList
|
dbJSON = Object $ HM.fromList
|
||||||
[ ( "players", toJSON [playerJSON] )
|
[ ( "players", toJSON [playerJSON] )
|
||||||
, ( "goalies", toJSON [goalieJSON] )
|
, ( "goalies", toJSON [goalieJSON] )
|
||||||
, ( "games", toJSON (1 :: Int) )
|
, ( "games", toJSON (1 :: Int) )
|
||||||
|
, ( "home_game_stats", gameStatsJSON 1 )
|
||||||
|
, ( "away_game_stats", gameStatsJSON 2 )
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user