Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
141
Issues
141
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
a6485d49
Commit
a6485d49
authored
Nov 05, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into dev-social-list
parents
62fcd6ea
6c14392e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
156 additions
and
49 deletions
+156
-49
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+77
-39
Types.hs
src/Gargantext/API/Ngrams/Types.hs
+16
-1
Routes.hs
src/Gargantext/API/Routes.hs
+2
-1
Node.hs
src/Gargantext/Database/Action/Node.hs
+4
-4
Config.hs
src/Gargantext/Database/Admin/Config.hs
+1
-1
Default.hs
src/Gargantext/Database/Admin/Types/Hyperdata/Default.hs
+1
-1
Node.hs
src/Gargantext/Database/Admin/Types/Node.hs
+2
-2
Job.hs
src/Gargantext/Prelude/Job.hs
+53
-0
No files found.
src/Gargantext/API/Ngrams.hs
View file @
a6485d49
...
...
@@ -108,31 +108,35 @@ import Formatting.Clock (timeSpecs)
import
GHC.Generics
(
Generic
)
import
Servant
hiding
(
Patch
)
import
System.Clock
(
getTime
,
TimeSpec
,
Clock
(
..
))
import
Servant.Job.Async
(
JobFunction
(
..
),
serveJobsAPI
)
import
System.IO
(
stderr
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
import
Prelude
(
error
)
import
Gargantext.Prelude
import
Gargantext.Prelude
hiding
(
log
)
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
(
..
),
AsyncJobs
)
import
Gargantext.API.Admin.Types
(
HasSettings
)
import
qualified
Gargantext.API.Metrics
as
Metrics
import
Gargantext.API.Ngrams.Types
import
Gargantext.Core.Types
(
ListType
(
..
),
NodeId
,
ListId
,
DocId
,
Limit
,
Offset
,
HasInvalidError
,
TODO
,
assertValid
)
import
Gargantext.API.Prelude
import
Gargantext.Core.Types
(
ListType
(
..
),
NodeId
,
ListId
,
DocId
,
Limit
,
Offset
,
TODO
,
assertValid
)
import
Gargantext.Core.Utils
(
something
)
-- import Gargantext.Core.Viz.Graph.API (recomputeGraph)
-- import Gargantext.Core.Viz.Graph.Distances (Distance(Conditional))
import
Gargantext.Database.Action.Flow.Types
import
Gargantext.Database.Action.Metrics.NgramsByNode
(
getOccByNgramsOnlyFast'
)
import
Gargantext.Database.Query.Table.Node.Select
import
Gargantext.Database.Query.Table.Ngrams
hiding
(
NgramsType
(
..
),
ngrams
,
ngramsType
,
ngrams_terms
)
import
Gargantext.Database.Admin.Config
(
userMaster
)
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
)
import
Gargantext.Database.Admin.Types.Node
(
NodeType
(
..
))
import
Gargantext.Database.Prelude
(
HasConnectionPool
,
HasConfig
)
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
)
import
Gargantext.Database.Query.Table.Node.Select
import
Gargantext.Database.Query.Table.Ngrams
hiding
(
NgramsType
(
..
),
ngrams
,
ngramsType
,
ngrams_terms
)
import
qualified
Gargantext.Database.Query.Table.Ngrams
as
TableNgrams
import
Gargantext.Database.Query.Table.Node
(
getNode
)
import
Gargantext.Database.Query.Tree.Error
(
HasTreeError
)
import
Gargantext.Database.Schema.Node
(
node_id
,
node_parentId
,
node_userId
)
import
Gargantext.Prelude.Job
{-
-- TODO sequences of modifications (Patchs)
...
...
@@ -319,13 +323,8 @@ tableNgramsPull listId ngramsType p_version = do
-- Apply the given patch to the DB and returns the patch to be applied on the
-- client.
-- TODO-ACCESS check
tableNgramsPut
::
(
HasNodeError
err
,
HasTreeError
err
,
HasInvalidError
err
,
HasConfig
env
,
HasConnectionPool
env
tableNgramsPut
::
(
FlowCmdM
env
err
m
,
HasSettings
env
,
RepoCmdM
env
err
m
)
=>
TabType
->
ListId
...
...
@@ -347,55 +346,87 @@ tableNgramsPut tabType listId (Versioned p_version p_table)
ret
<-
commitStatePatch
(
Versioned
p_version
p
)
<&>
v_data
%~
(
view
(
_PatchMap
.
at
ngramsType
.
_Just
.
_PatchMap
.
at
listId
.
_Just
))
pure
ret
tableNgramsPostChartsAsync
::
(
FlowCmdM
env
err
m
,
HasNodeError
err
,
HasSettings
env
)
=>
UpdateTableNgramsCharts
->
(
JobLog
->
m
()
)
->
m
JobLog
tableNgramsPostChartsAsync
utn
logStatus
=
do
let
tabType
=
utn
^.
utn_tab_type
let
listId
=
utn
^.
utn_list_id
node
<-
getNode
listId
let
nId
=
node
^.
node_id
_uId
=
node
^.
node_userId
mCId
=
node
^.
node_parentId
-- printDebug "[tableNgramsPut] updating graph with nId" nId
-- printDebug "[tableNgramsPut] updating graph with uId" uId
-- _ <- recomputeGraph uId nId Conditional
printDebug
"[tableNgramsPut] tabType"
tabType
printDebug
"[tableNgramsPut] listId"
listId
_
<-
case
mCId
of
case
mCId
of
Nothing
->
do
printDebug
"[tableNgramsPut] can't update charts, no parent, nId"
nId
pure
()
pure
$
jobLogFail
$
jobLogInit
1
Just
cId
->
do
case
tabType
of
Authors
->
do
-- printDebug "[tableNgramsPut] Authors, updating Pie, cId" cId
(
logRef
,
logRefSuccess
,
getRef
)
<-
runJobLog
1
logStatus
logRef
_
<-
Metrics
.
updatePie
cId
(
Just
listId
)
tabType
Nothing
pure
()
logRefSuccess
getRef
Institutes
->
do
-- printDebug "[tableNgramsPut] Institutes, updating Tree, cId" cId
-- printDebug "[tableNgramsPut] updating tree StopTerm, cId" cId
(
logRef
,
logRefSuccess
,
getRef
)
<-
runJobLog
3
logStatus
logRef
_
<-
Metrics
.
updateTree
cId
(
Just
listId
)
tabType
StopTerm
-- printDebug "[tableNgramsPut] updating tree CandidateTerm, cId" cId
logRefSuccess
_
<-
Metrics
.
updateTree
cId
(
Just
listId
)
tabType
CandidateTerm
-- printDebug "[tableNgramsPut] updating tree MapTerm, cId" cId
logRefSuccess
_
<-
Metrics
.
updateTree
cId
(
Just
listId
)
tabType
MapTerm
pure
()
logRefSuccess
getRef
Sources
->
do
-- printDebug "[tableNgramsPut] Sources, updating chart, cId" cId
(
logRef
,
logRefSuccess
,
getRef
)
<-
runJobLog
1
logStatus
logRef
_
<-
Metrics
.
updatePie
cId
(
Just
listId
)
tabType
Nothing
pure
()
logRefSuccess
getRef
Terms
->
do
-- printDebug "[tableNgramsPut] Terms, updating Metrics (Histo), cId" cId
(
logRef
,
logRefSuccess
,
getRef
)
<-
runJobLog
6
logStatus
logRef
_
<-
Metrics
.
updateChart
cId
(
Just
listId
)
tabType
Nothing
logRefSuccess
_
<-
Metrics
.
updatePie
cId
(
Just
listId
)
tabType
Nothing
logRefSuccess
_
<-
Metrics
.
updateScatter
cId
(
Just
listId
)
tabType
Nothing
logRefSuccess
_
<-
Metrics
.
updateTree
cId
(
Just
listId
)
tabType
StopTerm
logRefSuccess
_
<-
Metrics
.
updateTree
cId
(
Just
listId
)
tabType
CandidateTerm
logRefSuccess
_
<-
Metrics
.
updateTree
cId
(
Just
listId
)
tabType
MapTerm
pure
()
logRefSuccess
getRef
_
->
do
printDebug
"[tableNgramsPut] no update for tabType = "
tabType
pure
()
pure
()
pure
ret
pure
$
jobLogFail
$
jobLogInit
1
{-
{ _ne_list :: ListType
If we merge the parents/children we can potentially create cycles!
...
...
@@ -624,6 +655,13 @@ type TableNgramsApi = TableNgramsApiGet
:<|>
TableNgramsApiPut
:<|>
RecomputeScoresNgramsApiGet
:<|>
"version"
:>
TableNgramsApiGetVersion
:<|>
TableNgramsAsyncApi
type
TableNgramsAsyncApi
=
Summary
"Table Ngrams Async API"
:>
"async"
:>
"charts"
:>
"update"
:>
AsyncJobs
JobLog
'[
J
SON
]
UpdateTableNgramsCharts
JobLog
getTableNgramsCorpus
::
(
RepoCmdM
env
err
m
,
HasNodeError
err
,
HasConnectionPool
env
,
HasConfig
env
)
=>
NodeId
...
...
@@ -671,35 +709,35 @@ getTableNgramsDoc dId tabType listId limit_ offset listType minSize maxSize orde
apiNgramsTableCorpus
::
(
RepoCmdM
env
err
m
,
HasNodeError
err
,
HasTreeError
err
,
HasInvalidError
err
,
HasConnectionPool
env
,
HasConfig
env
,
HasSettings
env
apiNgramsTableCorpus
::
(
GargServerC
env
err
m
)
=>
NodeId
->
ServerT
TableNgramsApi
m
apiNgramsTableCorpus
cId
=
getTableNgramsCorpus
cId
:<|>
tableNgramsPut
:<|>
scoresRecomputeTableNgrams
cId
:<|>
getTableNgramsVersion
cId
:<|>
apiNgramsAsync
cId
apiNgramsTableDoc
::
(
RepoCmdM
env
err
m
,
HasNodeError
err
,
HasTreeError
err
,
HasInvalidError
err
,
HasConnectionPool
env
,
HasConfig
env
,
HasSettings
env
apiNgramsTableDoc
::
(
GargServerC
env
err
m
)
=>
DocId
->
ServerT
TableNgramsApi
m
apiNgramsTableDoc
dId
=
getTableNgramsDoc
dId
:<|>
tableNgramsPut
:<|>
scoresRecomputeTableNgrams
dId
:<|>
getTableNgramsVersion
dId
:<|>
apiNgramsAsync
dId
-- > index all the corpus accordingly (TODO AD)
apiNgramsAsync
::
NodeId
->
GargServer
TableNgramsAsyncApi
apiNgramsAsync
_dId
=
serveJobsAPI
$
JobFunction
$
\
i
log
->
let
log'
x
=
do
printDebug
"tableNgramsPostChartsAsync"
x
liftBase
$
log
x
in
tableNgramsPostChartsAsync
i
log'
-- Did the given list of ngrams changed since the given version?
-- The returned value is versioned boolean value, meaning that one always retrieve the
-- latest version.
...
...
src/Gargantext/API/Ngrams/Types.hs
View file @
a6485d49
...
...
@@ -38,6 +38,7 @@ import Data.Validity
import
Database.PostgreSQL.Simple.FromField
(
FromField
,
fromField
,
ResultError
(
ConversionFailed
),
returnError
)
import
GHC.Generics
(
Generic
)
import
Servant
hiding
(
Patch
)
import
Servant.Job.Utils
(
jsonOptions
)
import
System.FileLock
(
FileLock
)
import
Test.QuickCheck
(
elements
,
frequency
)
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
...
...
@@ -46,7 +47,7 @@ import Protolude (maybeToEither)
import
Gargantext.Prelude
import
Gargantext.Core.Text
(
size
)
import
Gargantext.Core.Types
(
ListType
(
..
),
NodeId
)
import
Gargantext.Core.Types
(
ListType
(
..
),
ListId
,
NodeId
)
import
Gargantext.Core.Types
(
TODO
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixUntagged
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Database.Prelude
(
fromField'
,
CmdM
'
)
...
...
@@ -735,3 +736,17 @@ ngramsTypeFromTabType tabType =
Terms
->
TableNgrams
.
NgramsTerms
_
->
panic
$
lieu
<>
"No Ngrams for this tab"
-- TODO: This `panic` would disapear with custom NgramsType.
----
-- Async task
data
UpdateTableNgramsCharts
=
UpdateTableNgramsCharts
{
_utn_tab_type
::
!
TabType
,
_utn_list_id
::
!
ListId
}
deriving
(
Eq
,
Show
,
Generic
)
makeLenses
''
U
pdateTableNgramsCharts
instance
FromJSON
UpdateTableNgramsCharts
where
parseJSON
=
genericParseJSON
$
jsonOptions
"_utn_"
instance
ToSchema
UpdateTableNgramsCharts
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_utn_"
)
src/Gargantext/API/Routes.hs
View file @
a6485d49
...
...
@@ -120,7 +120,8 @@ type GargPrivateAPI' =
-- Document endpoint
:<|>
"document"
:>
Summary
"Document endpoint"
:>
Capture
"doc_id"
DocId
:>
"ngrams"
:>
TableNgramsApi
:>
"ngrams"
:>
TableNgramsApi
-- :<|> "counts" :> Stream GET NewLineFraming '[JSON] Count :> CountAPI
-- TODO-SECURITY
...
...
src/Gargantext/Database/Action/Node.hs
View file @
a6485d49
...
...
@@ -56,8 +56,8 @@ mkNodeWithParent NodeFrameWrite i u n =
mkNodeWithParent
NodeFrameCalc
i
u
n
=
mkNodeWithParent_ConfigureHyperdata
NodeFrameCalc
i
u
n
mkNodeWithParent
NodeFrame
Code
i
u
n
=
mkNodeWithParent_ConfigureHyperdata
NodeFrame
Code
i
u
n
mkNodeWithParent
NodeFrame
Notebook
i
u
n
=
mkNodeWithParent_ConfigureHyperdata
NodeFrame
Notebook
i
u
n
...
...
@@ -78,8 +78,8 @@ mkNodeWithParent_ConfigureHyperdata NodeFrameWrite (Just i) uId name =
mkNodeWithParent_ConfigureHyperdata
NodeFrameCalc
(
Just
i
)
uId
name
=
mkNodeWithParent_ConfigureHyperdata'
NodeFrameCalc
(
Just
i
)
uId
name
mkNodeWithParent_ConfigureHyperdata
NodeFrame
Code
(
Just
i
)
uId
name
=
insertNode
NodeFrame
Code
(
Just
"Code"
)
(
Just
$
DefaultFrameCode
$
HyperdataFrame
"code
"
name
)
i
uId
mkNodeWithParent_ConfigureHyperdata
NodeFrame
Notebook
(
Just
i
)
uId
name
=
insertNode
NodeFrame
Notebook
(
Just
"Notebook"
)
(
Just
$
DefaultFrameCode
$
HyperdataFrame
"Notebook
"
name
)
i
uId
mkNodeWithParent_ConfigureHyperdata
_
_
_
_
=
nodeError
NotImplYet
...
...
src/Gargantext/Database/Admin/Config.hs
View file @
a6485d49
...
...
@@ -70,7 +70,7 @@ nodeTypeId n =
NodeFrameWrite
->
991
NodeFrameCalc
->
992
NodeFrame
Code
->
993
NodeFrame
Notebook
->
993
-- Cooccurrences -> 9
--
...
...
src/Gargantext/Database/Admin/Types/Hyperdata/Default.hs
View file @
a6485d49
...
...
@@ -115,6 +115,6 @@ defaultHyperdata NodeDashboard = DefaultDashboard defaultHyperdataDashboard
defaultHyperdata
NodeFrameWrite
=
DefaultFrameWrite
defaultHyperdataFrame
defaultHyperdata
NodeFrameCalc
=
DefaultFrameCalc
defaultHyperdataFrame
defaultHyperdata
NodeFrame
Code
=
DefaultFrameCalc
defaultHyperdataFrame
defaultHyperdata
NodeFrame
Notebook
=
DefaultFrameCalc
defaultHyperdataFrame
defaultHyperdata
NodeFile
=
DefaultFile
defaultHyperdataFile
src/Gargantext/Database/Admin/Types/Node.hs
View file @
a6485d49
...
...
@@ -257,7 +257,7 @@ data NodeType = NodeUser
-}
-- Optional Nodes
|
NodeFrameWrite
|
NodeFrameCalc
|
NodeFrame
Code
|
NodeFrameWrite
|
NodeFrameCalc
|
NodeFrame
Notebook
|
NodeFile
deriving
(
Show
,
Read
,
Eq
,
Generic
,
Bounded
,
Enum
)
...
...
@@ -292,7 +292,7 @@ defaultName NodePhylo = "Phylo"
defaultName
NodeFrameWrite
=
"Frame Write"
defaultName
NodeFrameCalc
=
"Frame Calc"
defaultName
NodeFrame
Code
=
"Frame Code"
defaultName
NodeFrame
Notebook
=
"Frame Code"
defaultName
NodeFile
=
"File"
...
...
src/Gargantext/Prelude/Job.hs
0 → 100644
View file @
a6485d49
module
Gargantext.Prelude.Job
where
import
Data.IORef
import
Data.Maybe
import
Gargantext.Prelude
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
(
..
))
jobLogInit
::
Int
->
JobLog
jobLogInit
rem
=
JobLog
{
_scst_succeeded
=
Just
0
,
_scst_remaining
=
Just
rem
,
_scst_failed
=
Just
0
,
_scst_events
=
Just
[]
}
jobLogSuccess
::
JobLog
->
JobLog
jobLogSuccess
(
JobLog
{
_scst_succeeded
=
mSucc
,
_scst_remaining
=
mRem
,
_scst_failed
=
mFail
,
_scst_events
=
evt
})
=
JobLog
{
_scst_succeeded
=
(
+
1
)
<$>
mSucc
,
_scst_remaining
=
(
\
x
->
x
-
1
)
<$>
mRem
,
_scst_failed
=
mFail
,
_scst_events
=
evt
}
jobLogFail
::
JobLog
->
JobLog
jobLogFail
(
JobLog
{
_scst_succeeded
=
mSucc
,
_scst_remaining
=
mRem
,
_scst_failed
=
mFail
,
_scst_events
=
evt
})
=
JobLog
{
_scst_succeeded
=
mSucc
,
_scst_remaining
=
(
\
x
->
x
-
1
)
<$>
mRem
,
_scst_failed
=
(
+
1
)
<$>
mFail
,
_scst_events
=
evt
}
runJobLog
::
MonadBase
IO
m
=>
Int
->
(
JobLog
->
m
()
)
->
m
(
m
()
,
m
()
,
m
JobLog
)
runJobLog
num
logStatus
=
do
jlRef
<-
liftBase
$
newIORef
$
jobLogInit
num
return
(
logRefF
jlRef
,
logRefSuccessF
jlRef
,
getRefF
jlRef
)
where
logRefF
ref
=
do
jl
<-
liftBase
$
readIORef
ref
logStatus
jl
logRefSuccessF
ref
=
do
jl
<-
liftBase
$
readIORef
ref
liftBase
$
writeIORef
ref
$
jobLogSuccess
jl
getRefF
ref
=
do
liftBase
$
readIORef
ref
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment