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
Show 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
...
@@ -32,7 +32,7 @@ import Test.QuickCheck.Arbitrary
...
@@ -32,7 +32,7 @@ import Test.QuickCheck.Arbitrary
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck
(
elements
)
import
Data.List
(
repeat
,
permutations
)
import
Data.List
(
repeat
,
permutations
)
-----------------------------------------------------------------------
-----------------------------------------------------------------------
type
CountAPI
=
Post
'[
J
SON
]
[
Count
]
type
CountAPI
=
Post
'[
J
SON
]
Counts
-----------------------------------------------------------------------
-----------------------------------------------------------------------
data
Scraper
=
Pubmed
|
Hal
|
IsTex
|
Isidore
data
Scraper
=
Pubmed
|
Hal
|
IsTex
|
Isidore
...
@@ -78,60 +78,59 @@ instance Arbitrary Query where
...
@@ -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
type
Error
=
Text
arbitrary
=
elements
errorMessages
type
Errors
=
[
Error
]
instance
FromJSON
ErrorMessage
data
Message
=
Message
Integer
Errors
instance
ToJSON
ErrorMessage
-----------------------------------------------------------------------
data
Error
=
Error
{
error_message
::
ErrorMessage
,
error_code
::
Int
}
deriving
(
Eq
,
Show
,
Generic
)
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Error
instance
ToJSON
Error
errorCodes
::
[
Int
]
toMessage
::
[(
Integer
,
[
Text
])]
->
[
Message
]
errorCodes
=
[
200
,
300
,
400
,
500
]
toMessage
=
map
(
\
(
c
,
es
)
->
Message
c
es
)
errors
::
[
Error
]
messages
::
[
Message
]
errors
=
[
Error
m
c
|
m
<-
errorMessages
messages
=
toMessage
$
[
(
400
,
[
"Ill formed query "
])
,
c
<-
errorCodes
,
(
300
,
[
"API connexion error "
])
]
,
(
300
,
[
"Internal Gargantext Error "
])
,
(
300
,
[
"Connexion to Gargantext Error"
])
,
(
300
,
[
"Token has expired "
])
]
<>
take
10
(
repeat
(
200
,
[
""
]))
instance
Arbitrary
Message
where
arbitrary
=
elements
messages
instance
Arbitrary
Error
wher
e
instance
FromJSON
Messag
e
arbitrary
=
elements
errors
instance
ToJSON
Message
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
data
Counts
=
Counts
[
Count
]
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Counts
instance
ToJSON
Counts
data
Count
=
Count
{
count_name
::
Scraper
data
Count
=
Count
{
count_name
::
Scraper
,
count_count
::
Maybe
Int
,
count_count
::
Maybe
Int
,
count_
errors
::
Maybe
[
Error
]
,
count_
message
::
Maybe
Message
}
}
deriving
(
Eq
,
Show
,
Generic
)
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Count
instance
FromJSON
Count
instance
ToJSON
Count
instance
ToJSON
Count
instance
Arbitrary
Count
where
instance
Arbitrary
Counts
where
arbitrary
=
elements
[
Count
n
(
Just
c
)
(
Just
[
e
])
|
n
<-
scrapers
arbitrary
=
elements
$
select
,
c
<-
[
100
..
1000
]
$
map
Counts
,
e
<-
errors
$
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
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