[NGRAMS,METRICS] JSON instances and ngramsType

parent c2d21d28
...@@ -28,9 +28,10 @@ module Gargantext.API.Metrics ...@@ -28,9 +28,10 @@ module Gargantext.API.Metrics
import Data.Text (Text) import Data.Text (Text)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.Prelude import Gargantext.Prelude
import Data.Aeson (ToJSON) import Data.Aeson.TH (deriveJSON)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary) import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import Gargantext.Core.Types (ListType(..)) import Gargantext.Core.Types (ListType(..))
import Gargantext.Core.Utils.Prefix (unPrefix)
import Data.Swagger import Data.Swagger
...@@ -38,7 +39,6 @@ data Metrics = Metrics ...@@ -38,7 +39,6 @@ data Metrics = Metrics
{ metrics_data :: [Metric]} { metrics_data :: [Metric]}
deriving (Generic) deriving (Generic)
instance ToJSON Metrics
instance ToSchema Metrics instance ToSchema Metrics
instance Arbitrary Metrics instance Arbitrary Metrics
where where
...@@ -51,7 +51,6 @@ data Metric = Metric ...@@ -51,7 +51,6 @@ data Metric = Metric
, m_cat :: !ListType , m_cat :: !ListType
} deriving (Generic) } deriving (Generic)
instance ToJSON Metric
instance ToSchema Metric instance ToSchema Metric
instance Arbitrary Metric instance Arbitrary Metric
where where
...@@ -60,4 +59,5 @@ instance Arbitrary Metric ...@@ -60,4 +59,5 @@ instance Arbitrary Metric
<*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary
deriveJSON (unPrefix "metrics_") ''Metrics
deriveJSON (unPrefix "m_") ''Metric
...@@ -41,7 +41,7 @@ import Data.Text (Text()) ...@@ -41,7 +41,7 @@ import Data.Text (Text())
import Data.Time (UTCTime) import Data.Time (UTCTime)
import Debug.Trace (trace) import Debug.Trace (trace)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, TableNgramsApiGet, tableNgramsPatch, getTableNgrams, HasRepo) import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, TableNgramsApiGet, tableNgramsPatch, getTableNgrams, HasRepo, ngramsTypeFromTabType)
import Gargantext.API.Ngrams.Tools import Gargantext.API.Ngrams.Tools
import Gargantext.API.Search ( SearchAPI, searchIn, SearchInQuery) import Gargantext.API.Search ( SearchAPI, searchIn, SearchInQuery)
import Gargantext.API.Metrics import Gargantext.API.Metrics
...@@ -389,24 +389,26 @@ query s = pure s ...@@ -389,24 +389,26 @@ query s = pure s
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
type MetricsAPI = Summary "SepGen IncExc metrics" type MetricsAPI = Summary "SepGen IncExc metrics"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParam "limit" Int :> QueryParam "ngramsType" TabType
:> QueryParam "limit" Int
:> Get '[JSON] Metrics :> Get '[JSON] Metrics
getMetrics :: NodeId -> GargServer MetricsAPI getMetrics :: NodeId -> GargServer MetricsAPI
getMetrics cId maybeListId maybeLimit = do getMetrics cId maybeListId maybeTabType maybeLimit = do
lId <- case maybeListId of lId <- case maybeListId of
Nothing -> defaultList cId Nothing -> defaultList cId
Just lId' -> pure lId' Just lId' -> pure lId'
let ngramsType = ngramsTypeFromTabType maybeTabType
-- TODO all terms -- TODO all terms
ngs' <- mapTermListRoot [lId] NgramsTerms ngs' <- mapTermListRoot [lId] ngramsType
let ngs = Map.unions $ map (\t -> filterListWithRoot t ngs') [GraphTerm, StopTerm, CandidateTerm] let ngs = Map.unions $ map (\t -> filterListWithRoot t ngs') [GraphTerm, StopTerm, CandidateTerm]
myCooc <- Map.filter (>1) <$> getCoocByNgrams myCooc <- Map.filter (>1) <$> getCoocByNgrams
<$> groupNodesByNgrams ngs <$> groupNodesByNgrams ngs
<$> getNodesByNgramsOnlyUser cId NgramsTerms (Map.keys ngs) <$> getNodesByNgramsOnlyUser cId ngramsType (Map.keys ngs)
let let
metrics = map (\(Scored t s1 s2) -> Metric t s1 s2 (listType t ngs')) $ scored myCooc metrics = map (\(Scored t s1 s2) -> Metric t s1 s2 (listType t ngs')) $ scored myCooc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment