2 Module : Gargantext.API.Metrics
3 Description : Server API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE DataKinds #-}
17 {-# LANGUAGE DeriveGeneric #-}
18 {-# LANGUAGE FlexibleContexts #-}
19 {-# LANGUAGE NoImplicitPrelude #-}
20 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE RankNTypes #-}
22 {-# LANGUAGE TemplateHaskell #-}
23 {-# LANGUAGE TypeOperators #-}
25 module Gargantext.API.Metrics
28 import Data.Aeson.TH (deriveJSON)
30 import Data.Time (UTCTime)
31 import Data.Text (Text)
32 import GHC.Generics (Generic)
33 import Gargantext.Core.Types (ListType(..))
34 import Gargantext.Core.Utils.Prefix (unPrefix)
35 import Gargantext.Database.Utils
36 import Gargantext.Core.Types (CorpusId)
37 import Gargantext.Prelude
38 import Gargantext.Viz.Chart
39 import Test.QuickCheck (elements)
40 import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
42 data Metrics = Metrics
43 { metrics_data :: [Metric]}
44 deriving (Generic, Show)
46 instance ToSchema Metrics
47 instance Arbitrary Metrics
49 arbitrary = Metrics <$> arbitrary
56 } deriving (Generic, Show)
58 instance ToSchema Metric
59 instance Arbitrary Metric
61 arbitrary = Metric <$> arbitrary
66 deriveJSON (unPrefix "metrics_") ''Metrics
67 deriveJSON (unPrefix "m_") ''Metric
70 -------------------------------------------------------------
72 data ChartMetrics a = ChartMetrics { chartMetrics_data :: a }
73 deriving (Generic, Show)
75 instance (ToSchema a) => ToSchema (ChartMetrics a)
76 instance (Arbitrary a) => Arbitrary (ChartMetrics a)
78 arbitrary = ChartMetrics <$> arbitrary
80 deriveJSON (unPrefix "chartMetrics_") ''ChartMetrics
82 -------------------------------------------------------------
83 instance ToSchema Histo
84 instance Arbitrary Histo
86 arbitrary = elements [ Histo ["2012"] [1]
89 deriveJSON (unPrefix "histo_") ''Histo
92 -- TODO add start / end
93 getChart :: CorpusId -> Maybe UTCTime -> Maybe UTCTime -> Cmd err (ChartMetrics Histo)
94 getChart cId _start _end = do
101 data FacetChart = FacetChart { facetChart_time :: UTCTime'
102 , facetChart_count :: Double
104 deriving (Show, Generic)
105 $(deriveJSON (unPrefix "facetChart_") ''FacetChart)
106 instance ToSchema FacetChart
108 instance Arbitrary FacetChart where
109 arbitrary = FacetChart <$> arbitrary <*> arbitrary