module TD.Data.StoryStatistics
(StoryStatistics(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.StatisticalGraph as StatisticalGraph
data StoryStatistics
= StoryStatistics
{ StoryStatistics -> Maybe StatisticalGraph
story_interaction_graph :: Maybe StatisticalGraph.StatisticalGraph
, StoryStatistics -> Maybe StatisticalGraph
story_reaction_graph :: Maybe StatisticalGraph.StatisticalGraph
}
deriving (StoryStatistics -> StoryStatistics -> Bool
(StoryStatistics -> StoryStatistics -> Bool)
-> (StoryStatistics -> StoryStatistics -> Bool)
-> Eq StoryStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryStatistics -> StoryStatistics -> Bool
== :: StoryStatistics -> StoryStatistics -> Bool
$c/= :: StoryStatistics -> StoryStatistics -> Bool
/= :: StoryStatistics -> StoryStatistics -> Bool
Eq, Int -> StoryStatistics -> ShowS
[StoryStatistics] -> ShowS
StoryStatistics -> String
(Int -> StoryStatistics -> ShowS)
-> (StoryStatistics -> String)
-> ([StoryStatistics] -> ShowS)
-> Show StoryStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryStatistics -> ShowS
showsPrec :: Int -> StoryStatistics -> ShowS
$cshow :: StoryStatistics -> String
show :: StoryStatistics -> String
$cshowList :: [StoryStatistics] -> ShowS
showList :: [StoryStatistics] -> ShowS
Show)
instance I.ShortShow StoryStatistics where
shortShow :: StoryStatistics -> String
shortShow StoryStatistics
{ story_interaction_graph :: StoryStatistics -> Maybe StatisticalGraph
story_interaction_graph = Maybe StatisticalGraph
story_interaction_graph_
, story_reaction_graph :: StoryStatistics -> Maybe StatisticalGraph
story_reaction_graph = Maybe StatisticalGraph
story_reaction_graph_
}
= String
"StoryStatistics"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"story_interaction_graph" String -> Maybe StatisticalGraph -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StatisticalGraph
story_interaction_graph_
, String
"story_reaction_graph" String -> Maybe StatisticalGraph -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StatisticalGraph
story_reaction_graph_
]
instance AT.FromJSON StoryStatistics where
parseJSON :: Value -> Parser StoryStatistics
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"storyStatistics" -> Value -> Parser StoryStatistics
parseStoryStatistics Value
v
String
_ -> Parser StoryStatistics
forall a. Monoid a => a
mempty
where
parseStoryStatistics :: A.Value -> AT.Parser StoryStatistics
parseStoryStatistics :: Value -> Parser StoryStatistics
parseStoryStatistics = String
-> (Object -> Parser StoryStatistics)
-> Value
-> Parser StoryStatistics
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryStatistics" ((Object -> Parser StoryStatistics)
-> Value -> Parser StoryStatistics)
-> (Object -> Parser StoryStatistics)
-> Value
-> Parser StoryStatistics
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe StatisticalGraph
story_interaction_graph_ <- Object
o Object -> Key -> Parser (Maybe StatisticalGraph)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"story_interaction_graph"
Maybe StatisticalGraph
story_reaction_graph_ <- Object
o Object -> Key -> Parser (Maybe StatisticalGraph)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"story_reaction_graph"
StoryStatistics -> Parser StoryStatistics
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryStatistics -> Parser StoryStatistics)
-> StoryStatistics -> Parser StoryStatistics
forall a b. (a -> b) -> a -> b
$ StoryStatistics
{ story_interaction_graph :: Maybe StatisticalGraph
story_interaction_graph = Maybe StatisticalGraph
story_interaction_graph_
, story_reaction_graph :: Maybe StatisticalGraph
story_reaction_graph = Maybe StatisticalGraph
story_reaction_graph_
}
parseJSON Value
_ = Parser StoryStatistics
forall a. Monoid a => a
mempty