[API] more Metrics API refactoring (remove unused params)

parent 2082845d
Pipeline #7567 passed with stages
in 36 minutes and 42 seconds
...@@ -19,6 +19,7 @@ rec { ...@@ -19,6 +19,7 @@ rec {
ghc966 ghc966
cabal_install cabal_install
pkgs.haskellPackages.alex pkgs.haskellPackages.alex
pkgs.haskellPackages.ghcid
pkgs.haskellPackages.happy pkgs.haskellPackages.happy
pkgs.haskellPackages.pretty-show pkgs.haskellPackages.pretty-show
]; ];
......
...@@ -18,11 +18,10 @@ module Gargantext.API.Metrics ...@@ -18,11 +18,10 @@ module Gargantext.API.Metrics
import Control.Lens.Getter (Getting) import Control.Lens.Getter (Getting)
import Data.HashMap.Strict qualified as HashMap import Data.HashMap.Strict qualified as HashMap
import Data.Time (UTCTime)
import Data.Vector (Vector) import Data.Vector (Vector)
import Gargantext.API.HashedResponse (HashedResponse, constructHashedResponse, hash) import Gargantext.API.HashedResponse (HashedResponse, constructHashedResponse, hash)
import Gargantext.API.Ngrams.NgramsTree (NgramsTree) import Gargantext.API.Ngrams.NgramsTree (NgramsTree)
import Gargantext.API.Ngrams.Types (QueryParamR, TabType, ngramsTypeFromTabType, unNgramsTerm) import Gargantext.API.Ngrams.Types (TabType, ngramsTypeFromTabType, unNgramsTerm)
import Gargantext.API.Prelude (IsGargServer) import Gargantext.API.Prelude (IsGargServer)
import Gargantext.API.Routes.Named.Metrics qualified as Named import Gargantext.API.Routes.Named.Metrics qualified as Named
import Gargantext.Core.NodeStory (HasNodeStory) import Gargantext.Core.NodeStory (HasNodeStory)
...@@ -41,7 +40,6 @@ import Gargantext.Database.Query.Table.Node.Error (HasNodeError) ...@@ -41,7 +40,6 @@ import Gargantext.Database.Query.Table.Node.Error (HasNodeError)
import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata) import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata)
import Gargantext.Database.Schema.Node (node_hyperdata) import Gargantext.Database.Schema.Node (node_hyperdata)
import Gargantext.Prelude hiding (hash) import Gargantext.Prelude hiding (hash)
import Servant
import Servant.Server.Generic (AsServerT) import Servant.Server.Generic (AsServerT)
------------------------------------------------------------- -------------------------------------------------------------
...@@ -56,10 +54,9 @@ getScatter :: HasNodeStory env err m ...@@ -56,10 +54,9 @@ getScatter :: HasNodeStory env err m
=> CorpusId => CorpusId
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> Maybe Limit
-> m (HashedResponse Metrics) -> m (HashedResponse Metrics)
getScatter cId maybeListId tabType _maybeLimit = do getScatter cId maybeListId tabType = do
metricsGetter cId maybeListId tabType hl_scatter updateScatter' metricsGetter cId maybeListId tabType hl_scatter (\cId' ml tt -> updateScatter' cId' ml tt Nothing)
updateScatter :: HasNodeStory env err m updateScatter :: HasNodeStory env err m
=> CorpusId => CorpusId
...@@ -109,7 +106,7 @@ getScatterHash :: HasNodeStory env err m ...@@ -109,7 +106,7 @@ getScatterHash :: HasNodeStory env err m
-> TabType -> TabType
-> m Text -> m Text
getScatterHash cId maybeListId tabType = do getScatterHash cId maybeListId tabType = do
hash <$> getScatter cId maybeListId tabType Nothing hash <$> getScatter cId maybeListId tabType
------------------------------------------------------------- -------------------------------------------------------------
...@@ -123,38 +120,33 @@ chartApi id' = Named.ChartAPI ...@@ -123,38 +120,33 @@ chartApi id' = Named.ChartAPI
-- TODO add start / end -- TODO add start / end
getChart :: HasNodeStory env err m getChart :: HasNodeStory env err m
=> CorpusId => CorpusId
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> m (HashedResponse (ChartMetrics Histo)) -> m (HashedResponse (ChartMetrics Histo))
getChart cId _start _end maybeListId tabType = do getChart cId maybeListId tabType = do
metricsGetter cId maybeListId tabType hl_chart updateChart' metricsGetter cId maybeListId tabType hl_chart updateChart'
updateChart :: HasNodeError err updateChart :: HasNodeError err
=> CorpusId => CorpusId
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> Maybe Limit
-> DBCmd err () -> DBCmd err ()
updateChart cId maybeListId tabType maybeLimit = do updateChart cId maybeListId tabType = do
listId <- case maybeListId of listId <- case maybeListId of
Just lid -> pure lid Just lid -> pure lid
Nothing -> defaultList cId Nothing -> defaultList cId
printDebug "[updateChart] cId" cId printDebug "[updateChart] cId" cId
printDebug "[updateChart] listId" listId printDebug "[updateChart] listId" listId
printDebug "[updateChart] tabType" tabType printDebug "[updateChart] tabType" tabType
printDebug "[updateChart] maybeLimit" maybeLimit _ <- updateChart' cId listId tabType
_ <- updateChart' cId listId tabType maybeLimit
pure () pure ()
updateChart' :: HasNodeError err updateChart' :: HasNodeError err
=> CorpusId => CorpusId
-> ListId -> ListId
-> TabType -> TabType
-> Maybe Limit
-> DBCmd err (ChartMetrics Histo) -> DBCmd err (ChartMetrics Histo)
updateChart' cId listId tabType _maybeLimit = do updateChart' cId listId tabType = do
node <- getNodeWith listId (Proxy :: Proxy HyperdataList) node <- getNodeWith listId (Proxy :: Proxy HyperdataList)
let hl = node ^. node_hyperdata let hl = node ^. node_hyperdata
chartMap = hl ^. hl_chart chartMap = hl ^. hl_chart
...@@ -170,25 +162,9 @@ getChartHash :: HasNodeStory env err m ...@@ -170,25 +162,9 @@ getChartHash :: HasNodeStory env err m
-> TabType -> TabType
-> m Text -> m Text
getChartHash cId maybeListId tabType = do getChartHash cId maybeListId tabType = do
hash <$> getChart cId Nothing Nothing maybeListId tabType hash <$> getChart cId maybeListId tabType
------------------------------------------------------------- -------------------------------------------------------------
-- | Pie metrics API
type PieApi = Summary "Pie Chart"
:> QueryParam "from" UTCTime
:> QueryParam "to" UTCTime
:> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType
:> Get '[JSON] (HashedResponse (ChartMetrics Histo))
:<|> Summary "Pie Chart update"
:> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType
:> QueryParam "limit" Limit
:> Post '[JSON] ()
:<|> "hash" :> Summary "Pie Hash"
:> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType
:> Get '[JSON] Text
pieApi :: IsGargServer err env m => NodeId -> Named.PieAPI (AsServerT m) pieApi :: IsGargServer err env m => NodeId -> Named.PieAPI (AsServerT m)
pieApi id' = Named.PieAPI pieApi id' = Named.PieAPI
...@@ -199,38 +175,33 @@ pieApi id' = Named.PieAPI ...@@ -199,38 +175,33 @@ pieApi id' = Named.PieAPI
getPie :: HasNodeStory env err m getPie :: HasNodeStory env err m
=> CorpusId => CorpusId
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> m (HashedResponse (ChartMetrics Histo)) -> m (HashedResponse (ChartMetrics Histo))
getPie cId _start _end maybeListId tabType = do getPie cId maybeListId tabType = do
metricsGetter cId maybeListId tabType hl_pie updatePie' metricsGetter cId maybeListId tabType hl_pie updatePie'
updatePie :: HasNodeStory env err m updatePie :: HasNodeStory env err m
=> CorpusId => CorpusId
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> Maybe Limit
-> m () -> m ()
updatePie cId maybeListId tabType maybeLimit = do updatePie cId maybeListId tabType = do
listId <- case maybeListId of listId <- case maybeListId of
Just lid -> pure lid Just lid -> pure lid
Nothing -> defaultList cId Nothing -> defaultList cId
printDebug "[updatePie] cId" cId printDebug "[updatePie] cId" cId
printDebug "[updatePie] maybeListId" maybeListId printDebug "[updatePie] maybeListId" maybeListId
printDebug "[updatePie] tabType" tabType printDebug "[updatePie] tabType" tabType
printDebug "[updatePie] maybeLimit" maybeLimit _ <- updatePie' cId listId tabType
_ <- updatePie' cId listId tabType maybeLimit
pure () pure ()
updatePie' :: (HasNodeStory env err m) updatePie' :: (HasNodeStory env err m)
=> CorpusId => CorpusId
-> ListId -> ListId
-> TabType -> TabType
-> Maybe Limit
-> m (ChartMetrics Histo) -> m (ChartMetrics Histo)
updatePie' cId listId tabType _maybeLimit = do updatePie' cId listId tabType = do
node <- getNodeWith listId (Proxy :: Proxy HyperdataList) node <- getNodeWith listId (Proxy :: Proxy HyperdataList)
let hl = node ^. node_hyperdata let hl = node ^. node_hyperdata
pieMap = hl ^. hl_pie pieMap = hl ^. hl_pie
...@@ -246,7 +217,7 @@ getPieHash :: HasNodeStory env err m ...@@ -246,7 +217,7 @@ getPieHash :: HasNodeStory env err m
-> TabType -> TabType
-> m Text -> m Text
getPieHash cId maybeListId tabType = do getPieHash cId maybeListId tabType = do
hash <$> getPie cId Nothing Nothing maybeListId tabType hash <$> getPie cId maybeListId tabType
------------------------------------------------------------- -------------------------------------------------------------
-- | Tree metrics API -- | Tree metrics API
...@@ -259,14 +230,12 @@ treeApi id' = Named.TreeAPI ...@@ -259,14 +230,12 @@ treeApi id' = Named.TreeAPI
getTree :: HasNodeStory env err m getTree :: HasNodeStory env err m
=> CorpusId => CorpusId
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> ListType -> ListType
-> m (HashedResponse (ChartMetrics (Vector NgramsTree))) -> m (HashedResponse (ChartMetrics (Vector NgramsTree)))
getTree cId _start _end maybeListId tabType listType = do getTree cId maybeListId tabType listType = do
metricsGetter cId maybeListId tabType hl_tree (\cId' l tt _mLimit -> updateTree' cId' l tt listType) metricsGetter cId maybeListId tabType hl_tree (\cId' l tt -> updateTree' cId' l tt listType)
updateTree :: HasNodeStory env err m updateTree :: HasNodeStory env err m
=> CorpusId => CorpusId
...@@ -307,7 +276,7 @@ getTreeHash :: HasNodeStory env err m ...@@ -307,7 +276,7 @@ getTreeHash :: HasNodeStory env err m
-> ListType -> ListType
-> m Text -> m Text
getTreeHash cId maybeListId tabType listType = do getTreeHash cId maybeListId tabType listType = do
hash <$> getTree cId Nothing Nothing maybeListId tabType listType hash <$> getTree cId maybeListId tabType listType
-------- --------
...@@ -317,7 +286,7 @@ metricsGetter :: (HasNodeStory env err m, ToJSON a) ...@@ -317,7 +286,7 @@ metricsGetter :: (HasNodeStory env err m, ToJSON a)
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> Getting (HashMap.HashMap TabType a) HyperdataList (HashMap.HashMap TabType a) -> Getting (HashMap.HashMap TabType a) HyperdataList (HashMap.HashMap TabType a)
-> (CorpusId -> ListId -> TabType -> Maybe Limit -> m a) -> (CorpusId -> ListId -> TabType -> m a)
-> m (HashedResponse a) -> m (HashedResponse a)
metricsGetter cId mListId tabType l up = do metricsGetter cId mListId tabType l up = do
listId <- case mListId of listId <- case mListId of
...@@ -330,6 +299,6 @@ metricsGetter cId mListId tabType l up = do ...@@ -330,6 +299,6 @@ metricsGetter cId mListId tabType l up = do
metrics <- case mMetrics of metrics <- case mMetrics of
Just m -> pure m Just m -> pure m
Nothing -> do Nothing -> do
up cId listId tabType Nothing up cId listId tabType
pure $ constructHashedResponse metrics pure $ constructHashedResponse metrics
...@@ -133,7 +133,7 @@ catApi :: CorpusId -> GargServer CatApi ...@@ -133,7 +133,7 @@ catApi :: CorpusId -> GargServer CatApi
catApi cId cs' = do catApi cId cs' = do
ret <- nodeContextsCategory $ map (\n -> (cId, n, ntc_category cs')) (ntc_nodesId cs') ret <- nodeContextsCategory $ map (\n -> (cId, n, ntc_category cs')) (ntc_nodesId cs')
lId <- defaultList cId lId <- defaultList cId
_ <- updateChart cId (Just lId) Docs Nothing _ <- updateChart cId (Just lId) Docs
pure ret pure ret
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
...@@ -92,11 +92,11 @@ updateNode lId (UpdateNodeParamsList Advanced) jobHandle = do ...@@ -92,11 +92,11 @@ updateNode lId (UpdateNodeParamsList Advanced) jobHandle = do
_ <- case corpusId of _ <- case corpusId of
Just cId -> do Just cId -> do
_ <- Metrics.updatePie cId (Just lId) NgramsTypes.Authors Nothing _ <- Metrics.updatePie cId (Just lId) NgramsTypes.Authors
markProgress 1 jobHandle markProgress 1 jobHandle
_ <- Metrics.updateTree cId (Just lId) NgramsTypes.Institutes MapTerm _ <- Metrics.updateTree cId (Just lId) NgramsTypes.Institutes MapTerm
markProgress 1 jobHandle markProgress 1 jobHandle
_ <- Metrics.updatePie cId (Just lId) NgramsTypes.Sources Nothing _ <- Metrics.updatePie cId (Just lId) NgramsTypes.Sources
pure () pure ()
Nothing -> pure () Nothing -> pure ()
...@@ -197,7 +197,7 @@ updateDocs cId jobHandle = do ...@@ -197,7 +197,7 @@ updateDocs cId jobHandle = do
markProgress 1 jobHandle markProgress 1 jobHandle
_ <- updateContextScore cId lId _ <- updateContextScore cId lId
markProgress 1 jobHandle markProgress 1 jobHandle
_ <- Metrics.updateChart' cId lId NgramsTypes.Docs Nothing _ <- Metrics.updateChart' cId lId NgramsTypes.Docs
markProgress 1 jobHandle markProgress 1 jobHandle
-- printDebug "updateContextsScore" (cId, lId, u) -- printDebug "updateContextsScore" (cId, lId, u)
pure () pure ()
......
{-|
Module : Gargantext.API.Routes.Named.Metrics
Description : Server API
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Metrics API routes
-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module Gargantext.API.Routes.Named.Metrics ( module Gargantext.API.Routes.Named.Metrics (
...@@ -10,7 +23,6 @@ module Gargantext.API.Routes.Named.Metrics ( ...@@ -10,7 +23,6 @@ module Gargantext.API.Routes.Named.Metrics (
) where ) where
import Data.Text (Text) import Data.Text (Text)
import Data.Time (UTCTime)
import Data.Vector (Vector) import Data.Vector (Vector)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.API.HashedResponse (HashedResponse) import Gargantext.API.HashedResponse (HashedResponse)
...@@ -26,8 +38,6 @@ import Servant ...@@ -26,8 +38,6 @@ import Servant
data TreeAPI mode = TreeAPI data TreeAPI mode = TreeAPI
{ treeChartEp :: mode :- Summary " Tree API" { treeChartEp :: mode :- Summary " Tree API"
:> QueryParam "from" UTCTime
:> QueryParam "to" UTCTime
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> QueryParamR "listType" ListType :> QueryParamR "listType" ListType
...@@ -50,7 +60,6 @@ data ScatterAPI mode = ScatterAPI ...@@ -50,7 +60,6 @@ data ScatterAPI mode = ScatterAPI
{ sepGenEp :: mode :- Summary "SepGen IncExc metrics" { sepGenEp :: mode :- Summary "SepGen IncExc metrics"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> QueryParam "limit" Limit
:> Get '[JSON] (HashedResponse Metrics) :> Get '[JSON] (HashedResponse Metrics)
, scatterUpdateEp :: mode :- Summary "Scatter update" , scatterUpdateEp :: mode :- Summary "Scatter update"
:> QueryParam "list" ListId :> QueryParam "list" ListId
...@@ -67,15 +76,12 @@ data ScatterAPI mode = ScatterAPI ...@@ -67,15 +76,12 @@ data ScatterAPI mode = ScatterAPI
data PieAPI mode = PieAPI data PieAPI mode = PieAPI
{ getPieChartEp :: mode :- Summary "Pie Chart" { getPieChartEp :: mode :- Summary "Pie Chart"
:> QueryParam "from" UTCTime
:> QueryParam "to" UTCTime
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> Get '[JSON] (HashedResponse (ChartMetrics Histo)) :> Get '[JSON] (HashedResponse (ChartMetrics Histo))
, pieChartUpdateEp :: mode :- Summary "Pie Chart update" , pieChartUpdateEp :: mode :- Summary "Pie Chart update"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> QueryParam "limit" Limit
:> Post '[JSON] () :> Post '[JSON] ()
, pieHashEp :: mode :- "hash" , pieHashEp :: mode :- "hash"
:> Summary "Pie Hash" :> Summary "Pie Hash"
...@@ -87,15 +93,12 @@ data PieAPI mode = PieAPI ...@@ -87,15 +93,12 @@ data PieAPI mode = PieAPI
data ChartAPI mode = ChartAPI data ChartAPI mode = ChartAPI
{ getChartEp :: mode :- Summary " Chart API" { getChartEp :: mode :- Summary " Chart API"
:> QueryParam "from" UTCTime
:> QueryParam "to" UTCTime
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> Get '[JSON] (HashedResponse (ChartMetrics Histo)) :> Get '[JSON] (HashedResponse (ChartMetrics Histo))
, updateChartEp :: mode :- Summary "Chart update" , updateChartEp :: mode :- Summary "Chart update"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> QueryParam "limit" Limit
:> Post '[JSON] () :> Post '[JSON] ()
, chartHashEp :: mode :- "hash" , chartHashEp :: mode :- "hash"
:> Summary "Chart Hash" :> Summary "Chart Hash"
......
...@@ -101,7 +101,7 @@ tableNgramsPostChartsAsync utn jobHandle = do ...@@ -101,7 +101,7 @@ tableNgramsPostChartsAsync utn jobHandle = do
Authors -> do Authors -> do
-- printDebug "[tableNgramsPostChartsAsync] Authors, updating Pie, cId" cId -- printDebug "[tableNgramsPostChartsAsync] Authors, updating Pie, cId" cId
markStarted 1 jobHandle markStarted 1 jobHandle
_ <- Metrics.updatePie cId (Just listId) tabType Nothing _ <- Metrics.updatePie cId (Just listId) tabType
markComplete jobHandle markComplete jobHandle
Institutes -> do Institutes -> do
-- printDebug "[tableNgramsPostChartsAsync] Institutes, updating Tree, cId" cId -- printDebug "[tableNgramsPostChartsAsync] Institutes, updating Tree, cId" cId
...@@ -118,7 +118,7 @@ tableNgramsPostChartsAsync utn jobHandle = do ...@@ -118,7 +118,7 @@ tableNgramsPostChartsAsync utn jobHandle = do
Sources -> do Sources -> do
-- printDebug "[tableNgramsPostChartsAsync] Sources, updating chart, cId" cId -- printDebug "[tableNgramsPostChartsAsync] Sources, updating chart, cId" cId
markStarted 1 jobHandle markStarted 1 jobHandle
_ <- Metrics.updatePie cId (Just listId) tabType Nothing _ <- Metrics.updatePie cId (Just listId) tabType
markComplete jobHandle markComplete jobHandle
Terms -> do Terms -> do
-- printDebug "[tableNgramsPostChartsAsync] Terms, updating Metrics (Histo), cId" cId -- printDebug "[tableNgramsPostChartsAsync] Terms, updating Metrics (Histo), cId" cId
......
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