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
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
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
fd38823e
Commit
fd38823e
authored
Feb 23, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MOCK] More credible count.
parent
e4cedde5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
46 deletions
+45
-46
Count.hs
src/Gargantext/API/Count.hs
+45
-46
No files found.
src/Gargantext/API/Count.hs
View file @
fd38823e
...
...
@@ -11,11 +11,11 @@ Count API part of Gargantext.
-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DataKinds
#-}
{-# LANGUAGE TemplateHaskell
#-}
{-# LANGUAGE TypeOperators
#-}
{-# LANGUAGE DeriveGeneric
#-}
{-# LANGUAGE DeriveAnyClass
#-}
module
Gargantext.API.Count
where
...
...
@@ -32,7 +32,7 @@ import Test.QuickCheck.Arbitrary
import
Test.QuickCheck
(
elements
)
import
Data.List
(
repeat
,
permutations
)
-----------------------------------------------------------------------
type
CountAPI
=
Post
'[
J
SON
]
[
Count
]
type
CountAPI
=
Post
'[
J
SON
]
Counts
-----------------------------------------------------------------------
data
Scraper
=
Pubmed
|
Hal
|
IsTex
|
Isidore
...
...
@@ -78,60 +78,59 @@ instance Arbitrary Query where
-----------------------------------------------------------------------
-----------------------------------------------------------------------
data
ErrorMessage
=
ErrorMessage
Text
deriving
(
Eq
,
Show
,
Generic
)
errorMessages
::
[
ErrorMessage
]
errorMessages
=
map
(
\
m
->
ErrorMessage
(
pack
m
))
$
[
"Ill formed query "
,
"API connexion error "
,
"Internal Gargantext Error "
,
"Connexion to Gargantext Error"
-- , "Token has expired "
]
<>
take
100
(
repeat
(
"No Error"
))
instance
Arbitrary
ErrorMessage
where
arbitrary
=
elements
errorMessages
type
Error
=
Text
type
Errors
=
[
Error
]
instance
FromJSON
ErrorMessage
instance
ToJSON
ErrorMessage
data
Message
=
Message
Integer
Errors
deriving
(
Eq
,
Show
,
Generic
)
-----------------------------------------------------------------------
data
Error
=
Error
{
error_message
::
ErrorMessage
,
error_code
::
Int
}
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Error
instance
ToJSON
Error
toMessage
::
[(
Integer
,
[
Text
])]
->
[
Message
]
toMessage
=
map
(
\
(
c
,
es
)
->
Message
c
es
)
errorCodes
::
[
Int
]
errorCodes
=
[
200
,
300
,
400
,
500
]
messages
::
[
Message
]
messages
=
toMessage
$
[
(
400
,
[
"Ill formed query "
])
,
(
300
,
[
"API connexion error "
])
,
(
300
,
[
"Internal Gargantext Error "
])
,
(
300
,
[
"Connexion to Gargantext Error"
])
,
(
300
,
[
"Token has expired "
])
]
<>
take
10
(
repeat
(
200
,
[
""
]))
errors
::
[
Error
]
errors
=
[
Error
m
c
|
m
<-
errorMessages
,
c
<-
errorCodes
]
instance
Arbitrary
Message
where
arbitrary
=
elements
messages
instance
Arbitrary
Error
wher
e
arbitrary
=
elements
errors
instance
FromJSON
Messag
e
instance
ToJSON
Message
-----------------------------------------------------------------------
-----------------------------------------------------------------------
data
Count
=
Count
{
count_name
::
Scraper
,
count_count
::
Maybe
Int
,
count_errors
::
Maybe
[
Error
]
}
data
Counts
=
Counts
[
Count
]
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Counts
instance
ToJSON
Counts
data
Count
=
Count
{
count_name
::
Scraper
,
count_count
::
Maybe
Int
,
count_message
::
Maybe
Message
}
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Count
instance
ToJSON
Count
instance
Arbitrary
Count
where
arbitrary
=
elements
[
Count
n
(
Just
c
)
(
Just
[
e
])
|
n
<-
scrapers
,
c
<-
[
100
..
1000
]
,
e
<-
errors
]
instance
Arbitrary
Counts
where
arbitrary
=
elements
$
select
$
map
Counts
$
map
(
\
xs
->
zipWith
(
\
s
(
c
,
m
)
->
Count
s
c
m
)
scrapers
xs
)
$
chunkAlong
(
length
scrapers
)
1
$
(
map
filter'
countOrErrors
)
where
select
xs
=
(
take
10
xs
)
<>
(
take
10
$
drop
100
xs
)
countOrErrors
=
[
(
c
,
e
)
|
c
<-
[
500
..
1000
],
e
<-
reverse
messages
]
filter'
(
c
,
e
)
=
case
e
of
Message
200
_
->
(
Just
c
,
Nothing
)
message
->
(
Nothing
,
Just
message
)
-----------------------------------------------------------------------
count
::
Query
->
Handler
[
Count
]
count
::
Query
->
Handler
Counts
count
_
=
undefined
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