]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Metrics.hs
add a json conf to Main.hs and fix issue between foundations, roots & termLists
[gargantext.git] / src / Gargantext / API / Metrics.hs
1 {-|
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
8 Portability : POSIX
9
10 Metrics API
11
12 -}
13
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15
16 {-# LANGUAGE DataKinds #-}
17 {-# LANGUAGE DeriveGeneric #-}
18 {-# LANGUAGE FlexibleContexts #-}
19 {-# LANGUAGE NoImplicitPrelude #-}
20 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE RankNTypes #-}
22 {-# LANGUAGE TemplateHaskell #-}
23 {-# LANGUAGE TypeOperators #-}
24
25 module Gargantext.API.Metrics
26 where
27
28 import Data.Aeson.TH (deriveJSON)
29 import Data.Swagger
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)
41
42 data Metrics = Metrics
43 { metrics_data :: [Metric]}
44 deriving (Generic, Show)
45
46 instance ToSchema Metrics
47 instance Arbitrary Metrics
48 where
49 arbitrary = Metrics <$> arbitrary
50
51 data Metric = Metric
52 { m_label :: !Text
53 , m_x :: !Double
54 , m_y :: !Double
55 , m_cat :: !ListType
56 } deriving (Generic, Show)
57
58 instance ToSchema Metric
59 instance Arbitrary Metric
60 where
61 arbitrary = Metric <$> arbitrary
62 <*> arbitrary
63 <*> arbitrary
64 <*> arbitrary
65
66 deriveJSON (unPrefix "metrics_") ''Metrics
67 deriveJSON (unPrefix "m_") ''Metric
68
69
70 -------------------------------------------------------------
71
72 data ChartMetrics a = ChartMetrics { chartMetrics_data :: a }
73 deriving (Generic, Show)
74
75 instance (ToSchema a) => ToSchema (ChartMetrics a)
76 instance (Arbitrary a) => Arbitrary (ChartMetrics a)
77 where
78 arbitrary = ChartMetrics <$> arbitrary
79
80 deriveJSON (unPrefix "chartMetrics_") ''ChartMetrics
81
82 -------------------------------------------------------------
83 instance ToSchema Histo
84 instance Arbitrary Histo
85 where
86 arbitrary = elements [ Histo ["2012"] [1]
87 , Histo ["2013"] [1]
88 ]
89 deriveJSON (unPrefix "histo_") ''Histo
90
91
92 -- TODO add start / end
93 getChart :: CorpusId -> Maybe UTCTime -> Maybe UTCTime -> Cmd err (ChartMetrics Histo)
94 getChart cId _start _end = do
95 h <- histoData cId
96 pure (ChartMetrics h)
97
98
99
100 {-
101 data FacetChart = FacetChart { facetChart_time :: UTCTime'
102 , facetChart_count :: Double
103 }
104 deriving (Show, Generic)
105 $(deriveJSON (unPrefix "facetChart_") ''FacetChart)
106 instance ToSchema FacetChart
107
108 instance Arbitrary FacetChart where
109 arbitrary = FacetChart <$> arbitrary <*> arbitrary
110
111 -}
112