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 TemplateHaskell #-}
14 module Gargantext.Viz.Chart
17 import Data.List (unzip, sortOn)
18 import Data.Map (toList)
19 import qualified Data.List as List
20 import qualified Data.Map as Map
21 import Data.Maybe (catMaybes)
24 import Gargantext.Core.Types.Main
25 import Gargantext.Database.Admin.Config
26 import Gargantext.Database.Admin.Types.Node (CorpusId)
27 import Gargantext.Database.Prelude
28 import Gargantext.Database.Query.Table.Node
29 import Gargantext.Database.Query.Table.Node.Select
30 import Gargantext.Database.Query.Table.NodeNode (selectDocsDates)
31 import Gargantext.Database.Schema.Node
32 import Gargantext.Prelude
33 import Gargantext.Text.Metrics.Count (occurrencesWith)
36 import Gargantext.API.Ngrams.NTree
37 import Gargantext.API.Ngrams.Tools
38 import Gargantext.Core.Types
39 import Gargantext.Database.Action.Flow
40 import Gargantext.Database.Action.Metrics.NgramsByNode
41 import Gargantext.Database.Schema.Ngrams
42 import Gargantext.Viz.Types
44 histoData :: CorpusId -> Cmd err Histo
46 dates <- selectDocsDates cId
50 $ occurrencesWith identity dates
54 pieData :: FlowCmdM env err m
55 => CorpusId -> NgramsType -> ListType
57 pieData cId nt lt = do
58 ls' <- selectNodesWithUsername NodeList userMaster
59 ls <- map (_node_id) <$> getListsWithParentId cId
60 ts <- mapTermListRoot ls nt <$> getRepo
62 dico = filterListWithRoot lt ts
63 terms = catMaybes $ List.concat $ map (\(a,b) -> [Just a, b]) $ Map.toList dico
64 group dico' x = case Map.lookup x dico' of
66 Just x' -> maybe x identity x'
68 (_total,mapTerms) <- countNodesByNgramsWith (group dico)
69 <$> getNodesByNgramsOnlyUser cId (ls' <> ls) nt terms
70 let (dates, count) = unzip $ map (\(t,(d,_)) -> (t, d)) $ Map.toList mapTerms
71 pure (Histo dates (map round count))
76 treeData :: FlowCmdM env err m
77 => CorpusId -> NgramsType -> ListType
79 treeData cId nt lt = do
80 ls' <- selectNodesWithUsername NodeList userMaster
81 ls <- map (_node_id) <$> getListsWithParentId cId
82 ts <- mapTermListRoot ls nt <$> getRepo
85 dico = filterListWithRoot lt ts
86 terms = catMaybes $ List.concat $ map (\(a,b) -> [Just a, b]) $ Map.toList dico
88 cs' <- getNodesByNgramsOnlyUser cId (ls' <> ls) nt terms
90 m <- getListNgrams ls nt
91 pure $ toTree lt cs' m
94 treeData' :: FlowCmdM env ServerError m
95 => CorpusId -> NgramsType -> ListType
97 treeData' cId nt lt = do
98 ls' <- selectNodesWithUsername NodeList userMaster
99 ls <- map (_node_id) <$> getListsWithParentId cId
100 ts <- mapTermListRoot ls nt <$> getRepo
103 dico = filterListWithRoot lt ts
104 terms = catMaybes $ List.concat $ map (\(a,b) -> [Just a, b]) $ Map.toList dico
106 cs' <- getNodesByNgramsOnlyUser cId (ls' <> ls) nt terms
108 m <- getListNgrams ls nt
109 pure $ toTree lt cs' m