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
208d9a22
Commit
208d9a22
authored
Nov 07, 2014
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] GRAPH adding url for json data.
parent
258483e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
29 deletions
+48
-29
urls.py
gargantext_web/urls.py
+2
-1
views.py
gargantext_web/views.py
+46
-28
No files found.
gargantext_web/urls.py
View file @
208d9a22
...
...
@@ -4,7 +4,7 @@ from django.contrib import admin
from
gargantext_web.views
import
home
,
projects
,
project
,
corpus
from
gargantext_web.views
import
delete_project
,
delete_corpus
from
gargantext_web.views
import
exploration
,
send_csv
from
gargantext_web.views
import
exploration
,
send_csv
,
send_graph
from
gargantext_web.views
import
explorer_graph
,
explorer_matrix
,
explorer_chart
admin
.
autodiscover
()
...
...
@@ -34,6 +34,7 @@ urlpatterns = patterns('',
url
(
r'^exploration$'
,
exploration
),
url
(
r'^data.csv$'
,
send_csv
),
url
(
r'^graph.json$'
,
send_graph
),
)
from
django.conf
import
settings
...
...
gargantext_web/views.py
View file @
208d9a22
...
...
@@ -414,49 +414,67 @@ def explorer_chart(request):
return
HttpResponse
(
html
)
import
csv
from
django.db
import
connection
cursor
=
connection
.
cursor
()
def
send_csv
(
request
):
'''
Create the HttpResponse object with the appropriate CSV header.
'''
response
=
HttpResponse
(
content_type
=
'text/csv'
)
response
[
'Content-Disposition'
]
=
'attachment; filename="
somefilename
.csv"'
response
[
'Content-Disposition'
]
=
'attachment; filename="
data
.csv"'
writer
=
csv
.
writer
(
response
)
# file = open('/srv/gargantext/static/js/d3/ndx.csv', 'r')
# for line in file.readlines():
# writer.writerow(line)
writer
.
writerow
([
'date'
,
'open'
,
'high'
,
'low'
,
'close'
,
'volume'
,
'oi'
])
# writer.writerow(['date','open','high','low','close','volume','oi'])
# writer.writerow(['12/19/2001','96.05','99.98','95.79','99.98','1260','0'])
# writer.writerow(['12/20/2001','104.3','104.39','99.98','104.39','197','0'])
# writer.writerow(['12/21/2001','109.07','109.13','103.73','109.13','28','0'])
# writer.writerow(['12/24/2001','113.57','114.55','109.13','114.55','32','0'])
# writer.writerow(['12/25/2001','120.09','120.25','114.55','120.25','15','0'])
# writer.writerow(['12/26/2001','125.27','125.27','120.25','125.27','100','0'])
# writer.writerow(['12/19/2002','96.05','99.98','95.79','99.98','1260','0'])
# writer.writerow(['12/20/2002','104.3','104.39','99.98','104.39','197','0'])
# writer.writerow(['12/21/2002','109.07','109.13','103.73','109.13','28','0'])
# writer.writerow(['12/24/2002','113.57','114.55','109.13','114.55','32','0'])
# writer.writerow(['12/25/2002','120.09','120.25','114.55','120.25','15','0'])
# writer.writerow(['12/26/2002','125.27','125.27','120.25','125.27','100','0'])
# writer.writerow(['12/19/2003','96.05','99.98','95.79','99.98','1260','0'])
# writer.writerow(['12/20/2003','104.3','104.39','99.98','104.39','197','0'])
# writer.writerow(['12/21/2003','109.07','109.13','103.73','109.13','28','0'])
# writer.writerow(['12/24/2003','113.57','114.55','109.13','114.55','32','0'])
# writer.writerow(['12/25/2003','120.09','120.25','114.55','120.25','15','0'])
# writer.writerow(['12/26/2003','125.27','125.27','120.25','125.27','100','0'])
# writer.writerow(['12/19/2004','96.05','99.98','95.79','99.98','1260','0'])
# writer.writerow(['12/20/2004','104.3','104.39','99.98','104.39','197','0'])
# writer.writerow(['12/21/2004','109.07','109.13','103.73','109.13','28','0'])
# writer.writerow(['12/24/2004','113.57','114.55','109.13','114.55','32','0'])
# writer.writerow(['12/25/2004','120.09','120.25','114.55','120.25','15','0'])
# writer.writerow(['12/26/2004','125.27','125.27','120.25','125.27','100','0'])
#
cursor
.
execute
(
"""
SELECT
metadata -> 'publication_year' as year,
metadata -> 'publication_month' as month,
metadata -> 'publication_day' as day,
COUNT(*)
FROM
node_node AS n
WHERE
n.parent_id =
%
s
GROUP BY
day, month, year
ORDER BY
year, month, day ASC
LIMIT
20
"""
,
[
5102
])
writer
.
writerow
([
'date'
,
'data'
])
while
True
:
row
=
cursor
.
fetchone
()
if
row
is
None
:
break
writer
.
writerow
([
row
[
0
]
+
'/'
+
row
[
1
]
+
'/'
+
row
[
2
]
+
','
+
str
(
row
[
3
])
])
return
response
def
send_graph
(
request
):
'''
Create the HttpResponse object with the graph dataset.
'''
response
=
HttpResponse
(
content_type
=
'text/json'
)
response
[
'Content-Disposition'
]
=
'attachment; filename="graph.json"'
writer
=
csv
.
writer
(
response
)
file
=
open
(
'/srv/gargantext/tests/graphsam/randomgraphgen.json'
,
'r'
)
for
line
in
file
.
readlines
():
writer
.
writerow
(
line
)
return
response
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