Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
33de2f36
Commit
33de2f36
authored
Jul 08, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add compress_graph routine to send more compact data to tinaweb
parent
b760c8e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
rest.py
graph/rest.py
+18
-1
No files found.
graph/rest.py
View file @
33de2f36
...
...
@@ -8,6 +8,20 @@ from gargantext.util.http import APIView, APIException\
from
traceback
import
format_tb
def
compress_graph
(
graphdata
):
"""
graph data is usually a dict with 2 slots:
"nodes": [{"id":4103, "type":"terms", "attributes":{"clust_default": 0}, "size":29, "label":"regard"},...]
"links": [{"t": 998,"s": 768,"w": 0.0425531914893617},...]
To send this data over the net, this function can reduce some of its size:
- keep less decimals for float value of each link's weight
- (TODO) have shorter names for node properties (eg: s/clust_default/cd/)
"""
for
link
in
graphdata
[
'links'
]:
link
[
'w'
]
=
format
(
link
[
'w'
],
'.3f'
)
# keep only 3 decimals
return
graphdata
# TODO check authentication
class
Graph
(
APIView
):
...
...
@@ -104,7 +118,10 @@ class Graph(APIView):
if
len
(
data
[
'nodes'
])
>
0
and
len
(
data
[
'links'
])
>
0
:
# normal case --------------------------------
if
format_
==
'json'
:
return
JsonHttpResponse
(
data
,
status
=
200
)
return
JsonHttpResponse
(
compress_graph
(
data
),
status
=
200
)
# --------------------------------------------
else
:
# empty data case
...
...
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