2 Module : Gargantext.Viz.Chart
3 Description : Graph utils
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE DeriveGeneric #-}
13 {-# LANGUAGE FlexibleContexts #-}
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE RankNTypes #-}
16 {-# LANGUAGE TemplateHaskell #-}
18 module Gargantext.Viz.Chart
21 import Data.List (unzip, sortOn)
22 import Data.Map (toList)
23 import qualified Data.List as List
24 import qualified Data.Map as Map
25 import Data.Maybe (catMaybes)
28 import Gargantext.Core.Types.Main
29 import Gargantext.Database.Admin.Config
30 import Gargantext.Database.Admin.Types.Node (CorpusId)
31 import Gargantext.Database.Prelude
32 import Gargantext.Database.Query.Table.Node
33 import Gargantext.Database.Query.Table.Node.Select
34 import Gargantext.Database.Query.Table.NodeNode (selectDocsDates)
35 import Gargantext.Database.Schema.Node
36 import Gargantext.Prelude
37 import Gargantext.Text.Metrics.Count (occurrencesWith)
40 import Gargantext.API.Ngrams.NTree
41 import Gargantext.API.Ngrams.Tools
42 import Gargantext.Core.Types
43 import Gargantext.Database.Action.Flow
44 import Gargantext.Database.Action.Metrics.NgramsByNode
45 import Gargantext.Database.Schema.Ngrams
46 import Gargantext.Viz.Types
48 histoData :: CorpusId -> Cmd err Histo
50 dates <- selectDocsDates cId
54 $ occurrencesWith identity dates
58 pieData :: FlowCmdM env err m
59 => CorpusId -> NgramsType -> ListType
61 pieData cId nt lt = do
62 ls' <- selectNodesWithUsername NodeList userMaster
63 ls <- map (_node_id) <$> getListsWithParentId cId
64 ts <- mapTermListRoot ls nt <$> getRepo
66 dico = filterListWithRoot lt ts
67 terms = catMaybes $ List.concat $ map (\(a,b) -> [Just a, b]) $ Map.toList dico
68 group dico' x = case Map.lookup x dico' of
70 Just x' -> maybe x identity x'
72 (_total,mapTerms) <- countNodesByNgramsWith (group dico)
73 <$> getNodesByNgramsOnlyUser cId (ls' <> ls) nt terms
74 let (dates, count) = unzip $ map (\(t,(d,_)) -> (t, d)) $ Map.toList mapTerms
75 pure (Histo dates (map round count))
80 treeData :: FlowCmdM env err m
81 => CorpusId -> NgramsType -> ListType
83 treeData cId nt lt = do
84 ls' <- selectNodesWithUsername NodeList userMaster
85 ls <- map (_node_id) <$> getListsWithParentId cId
86 ts <- mapTermListRoot ls nt <$> getRepo
89 dico = filterListWithRoot lt ts
90 terms = catMaybes $ List.concat $ map (\(a,b) -> [Just a, b]) $ Map.toList dico
92 cs' <- getNodesByNgramsOnlyUser cId (ls' <> ls) nt terms
94 m <- getListNgrams ls nt
95 pure $ toTree lt cs' m
98 treeData' :: FlowCmdM env ServerError m
99 => CorpusId -> NgramsType -> ListType
101 treeData' cId nt lt = do
102 ls' <- selectNodesWithUsername NodeList userMaster
103 ls <- map (_node_id) <$> getListsWithParentId cId
104 ts <- mapTermListRoot ls nt <$> getRepo
107 dico = filterListWithRoot lt ts
108 terms = catMaybes $ List.concat $ map (\(a,b) -> [Just a, b]) $ Map.toList dico
110 cs' <- getNodesByNgramsOnlyUser cId (ls' <> ls) nt terms
112 m <- getListNgrams ls nt
113 pure $ toTree lt cs' m