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
d18065e7
Commit
d18065e7
authored
10 years ago
by
Administrator
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'samuel'
Samuel's stuff integration
parents
96da88b7
bfdab6f5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
267 additions
and
238 deletions
+267
-238
urls.py
gargantext_web/urls.py
+4
-0
views.py
gargantext_web/views.py
+159
-0
corpus.html
templates/corpus.html
+63
-237
node-info.html
templates/node-info.html
+7
-1
subcorpus.html
templates/subcorpus.html
+34
-0
No files found.
gargantext_web/urls.py
View file @
d18065e7
...
...
@@ -30,6 +30,8 @@ urlpatterns = patterns('',
url
(
r'^project/(\d+)/corpus/(\d+)/delete/$'
,
views
.
delete_corpus
),
url
(
r'^project/(\d+)/corpus/(\d+)/corpus.csv$'
,
views
.
corpus_csv
),
url
(
r'^project/(\d+)/corpus/(\d+)/timerange/(\d+)/(\d+)$'
,
views
.
subcorpus
),
# Visualizations
url
(
r'^project/(\d+)/corpus/(\d+)/chart$'
,
views
.
chart
),
url
(
r'^corpus/(\d+)/explorer$'
,
views
.
graph
),
...
...
@@ -48,6 +50,8 @@ urlpatterns = patterns('',
url
(
r'^api/nodes/(\d+)$'
,
gargantext_web
.
api
.
Nodes
.
as_view
()),
url
(
r'^api/nodes$'
,
gargantext_web
.
api
.
NodesList
.
as_view
()),
url
(
r'^api/project/(\d+)/corpus/(\d+)/timerange/(\d+)/(\d+)$'
,
views
.
subcorpusJSON
),
url
(
r'^api/nodes/(\d+)/ngrams$'
,
gargantext_web
.
api
.
CorpusController
.
ngrams
),
url
(
r'^ngrams$'
,
views
.
ngrams
),
...
...
This diff is collapsed.
Click to expand it.
gargantext_web/views.py
View file @
d18065e7
...
...
@@ -363,6 +363,165 @@ def corpus(request, project_id, corpus_id):
return
HttpResponse
(
html
)
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
def
subcorpus
(
request
,
project_id
,
corpus_id
,
start
,
end
):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/login/?next=
%
s'
%
request
.
path
)
try
:
offset
=
str
(
project_id
)
offset
=
str
(
corpus_id
)
offset
=
str
(
start
)
offset
=
str
(
end
)
except
ValueError
:
raise
Http404
()
# parameters received via web. Format = (yearmonthday = 20150106 = 06 jan 2015)
import
datetime
dateini
=
datetime
.
datetime
.
strptime
(
str
(
start
),
'
%
Y
%
m
%
d'
)
.
date
()
datefin
=
datetime
.
datetime
.
strptime
(
str
(
end
),
'
%
Y
%
m
%
d'
)
.
date
()
t
=
get_template
(
'subcorpus.html'
)
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
project
=
Node
.
objects
.
get
(
id
=
project_id
)
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
# retrieving all the documents
documents
=
corpus
.
children
.
all
()
number
=
corpus
.
children
.
count
()
filtered_docs
=
[]
# filtering documents by range-date
for
doc
in
documents
:
if
"publication_date"
in
doc
.
metadata
:
realdate
=
doc
.
metadata
[
"publication_date"
]
.
split
(
" "
)[
0
]
# in database is = (year-month-day = 2015-01-06 00:00:00 = 06 jan 2015 00 hrs)
realdate
=
datetime
.
datetime
.
strptime
(
str
(
realdate
),
'
%
Y-
%
m-
%
d'
)
.
date
()
# finalform = (yearmonthday = 20150106 = 06 jan 2015)
if
dateini
<=
realdate
<=
datefin
:
doc
.
date
=
realdate
filtered_docs
.
append
(
doc
)
# ordering from most recent to the older.
ordered
=
sorted
(
filtered_docs
,
key
=
lambda
x
:
x
.
date
,
reverse
=
True
)
# pages of 10 elements. Like a sir.
paginator
=
Paginator
(
ordered
,
10
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
results
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
# If page is not an integer, deliver first page.
results
=
paginator
.
page
(
1
)
except
EmptyPage
:
# If page is out of range (e.g. 9999), deliver last page of results.
results
=
paginator
.
page
(
paginator
.
num_pages
)
html
=
t
.
render
(
Context
({
\
'user'
:
user
,
\
'date'
:
date
,
\
'project'
:
project
,
\
'corpus'
:
corpus
,
\
'documents'
:
results
,
\
# 'number' : len(filtered_docs),\
# 'dates' : chart,\
}))
return
HttpResponse
(
html
)
import
json
def
subcorpusJSON
(
request
,
project_id
,
corpus_id
,
start
,
end
):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/login/?next=
%
s'
%
request
.
path
)
try
:
offset
=
str
(
project_id
)
offset
=
str
(
corpus_id
)
offset
=
str
(
start
)
offset
=
str
(
end
)
except
ValueError
:
raise
Http404
()
# parameters received via web. Format = (yearmonthday = 20150106 = 06 jan 2015)
import
datetime
dateini
=
datetime
.
datetime
.
strptime
(
str
(
start
),
'
%
Y
%
m
%
d'
)
.
date
()
datefin
=
datetime
.
datetime
.
strptime
(
str
(
end
),
'
%
Y
%
m
%
d'
)
.
date
()
t
=
get_template
(
'subcorpus.html'
)
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
project
=
Node
.
objects
.
get
(
id
=
project_id
)
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
# retrieving all the documents
documents
=
corpus
.
children
.
all
()
number
=
corpus
.
children
.
count
()
filtered_docs
=
[]
# filtering documents by range-date
for
doc
in
documents
:
if
"publication_date"
in
doc
.
metadata
:
realdate
=
doc
.
metadata
[
"publication_date"
]
.
split
(
" "
)[
0
]
# in database is = (year-month-day = 2015-01-06 00:00:00 = 06 jan 2015 00 hrs)
realdate
=
datetime
.
datetime
.
strptime
(
str
(
realdate
),
'
%
Y-
%
m-
%
d'
)
.
date
()
# finalform = (yearmonthday = 20150106 = 06 jan 2015)
if
dateini
<=
realdate
<=
datefin
:
doc
.
date
=
realdate
filtered_docs
.
append
(
doc
)
# ordering from most recent to the older.
ordered
=
sorted
(
filtered_docs
,
key
=
lambda
x
:
x
.
date
,
reverse
=
True
)
# pages of 10 elements. Like a sir.
paginator
=
Paginator
(
ordered
,
10
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
results
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
# If page is not an integer, deliver first page.
results
=
paginator
.
page
(
1
)
except
EmptyPage
:
# If page is out of range (e.g. 9999), deliver last page of results.
results
=
paginator
.
page
(
paginator
.
num_pages
)
from
rest_framework.pagination
import
PaginationSerializer
serializer
=
PaginationSerializer
(
instance
=
results
)
print
(
serializer
.
data
)
html
=
t
.
render
(
Context
({
\
'user'
:
user
,
\
'date'
:
date
,
\
'corpus'
:
corpus
,
\
}))
# return HttpResponse(html)
return
HttpResponse
(
serializer
.
data
,
content_type
=
'application/json'
)
# for pagexample.html
from
django.core.paginator
import
Paginator
,
InvalidPage
,
EmptyPage
def
get_pagination_page
(
page
=
1
):
items
=
range
(
0
,
100
)
paginator
=
Paginator
(
items
,
10
)
try
:
page
=
int
(
page
)
except
ValueError
:
page
=
1
try
:
items
=
paginator
.
page
(
page
)
except
(
EmptyPage
,
InvalidPage
):
items
=
paginator
.
page
(
paginator
.
num_pages
)
return
items
def
delete_project
(
request
,
node_id
):
Node
.
objects
.
filter
(
id
=
node_id
)
.
all
()
.
delete
()
return
HttpResponseRedirect
(
'/projects/'
)
...
...
This diff is collapsed.
Click to expand it.
templates/corpus.html
View file @
d18065e7
...
...
@@ -75,23 +75,16 @@
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
<p class="btn btn-primary btn-lg" align="right">Read documents</h2></p>
<p
onclick="updateDocuments();"
class="btn btn-primary btn-lg" align="right">Read documents</h2></p>
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
<p align="right">
Page <a href="#">2</a> sur 100
</p>
</center>
{% if documents %}
<ul>
{% for doc in documents %}
<li> <b>{{ doc.date }}</b>, <a href="/admin/node/document/{{doc.id}}">{{ doc.title}}</a></li>
{% endfor %}
</ul>
{% endif %}
<!--{% include "subcorpus.html" %}-->
<div
id=
"subcorpusdiv"
></div>
</div>
</div>
...
...
@@ -150,6 +143,64 @@
<script>
var
datesbuffer
=
false
;
function
pr
(
msg
)
{
console
.
log
(
msg
)
}
function
dateToInt
(
todayTime
)
{
var
month
=
(
todayTime
.
getMonth
()
+
1
);
var
day
=
(
todayTime
.
getDate
());
var
year
=
(
todayTime
.
getFullYear
());
if
(
month
<
10
)
month
=
"0"
+
month
;
if
(
day
<
10
)
day
=
"0"
+
day
;
return
year
+
""
+
month
+
""
+
day
;
}
// I've clicked "Read Documents":
function
updateDocuments
(
pagenumber
,
pagenav
)
{
pagenav
=
(
pagenav
)?
pagenav
:
true
;
pagenumber
=
(
pagenumber
)?
pagenumber
:
1
;
pr
(
"in here pagenav:"
+
pagenav
+
" - pagenumber:"
+
pagenumber
)
pr
(
$
(
"#collapseOne"
).
height
())
// if "Read Documents" collapsible is close, then... show some me pubs!
if
(
pagenav
||
$
(
"#collapseOne"
).
height
()
<
50
)
{
// Here u ask for the server some paginated results (pubs)
// if u havent select a timerange from the blue chart, then show me all pubs
if
(
!
datesbuffer
)
{
console
.
log
(
"nothing cause dont wanna"
)
}
// there's some timerange selected in the blue chart, so show me the pubs of that period
else
{
var
dataini
=
dateToInt
(
datesbuffer
[
0
])
var
datafin
=
dateToInt
(
datesbuffer
[
1
])
//http://localhost:8000/project/37525/corpus/37526/timerange/20040117/20040125?page=1
var
base
=
window
.
location
.
href
;
var
theurl
=
base
+
"timerange/"
+
dataini
+
"/"
+
datafin
+
"?page="
+
pagenumber
;
pr
(
"theurl: "
+
theurl
)
$
.
ajax
({
url
:
theurl
,
success
:
function
(
data
)
{
// console.log(data)
$
(
'#subcorpusdiv'
).
html
(
data
);
}
});
}
}
//else: "Read Documents" collapsible is open!, so do nothing
}
// var gainOrLossChart = dc.pieChart("#gain-loss-chart");
...
...
@@ -182,44 +233,6 @@ d3.csv("/chart/corpus/{{ corpus.id }}/data.csv", function (data) {
var
ndx
=
crossfilter
(
data
);
var
all
=
ndx
.
groupAll
();
/*
var yearlyDimension = ndx.dimension(function (d) {
return d3.time.year(d.dd);
});
var yearlyPerformanceGroup = yearlyDimension.group().reduce(
//add
function (p, v) {
++p.count;
p.absGain += +v.close - +v.open;
p.fluctuation += Math.abs(+v.close - +v.open);
p.sumIndex += (+v.open + +v.close) / 2;
p.avgIndex = p.sumIndex / p.count;
p.percentageGain = (p.absGain / p.avgIndex) * 100;
p.fluctuationPercentage = (p.fluctuation / p.avgIndex) * 100;
return p;
},
//remove
function (p, v) {
--p.count;
p.absGain -= +v.close - +v.open;
p.fluctuation -= Math.abs(+v.close - +v.open);
p.sumIndex -= (+v.open + +v.close) / 2;
p.avgIndex = p.sumIndex / p.count;
p.percentageGain = (p.absGain / p.avgIndex) * 100;
p.fluctuationPercentage = (p.fluctuation / p.avgIndex) * 100;
return p;
},
//init
function () {
return {count: 0, absGain: 0, fluctuation: 0, fluctuationPercentage: 0, sumIndex: 0, avgIndex: 0, percentageGain: 0};
}
);
var dateDimension = ndx.dimension(function (d) {
return d.dd;
});
*/
//volumeChart:(1)
//moveChart:(1)
// monthly index avg fluctuation in percentage
...
...
@@ -257,153 +270,6 @@ d3.csv("/chart/corpus/{{ corpus.id }}/data.csv", function (data) {
}
);
/*
var gainOrLoss = ndx.dimension(function (d) {
return +d.open > +d.close ? "Loss" : "Gain";
});
var gainOrLossGroup = gainOrLoss.group();
var fluctuation = ndx.dimension(function (d) {
return Math.round((d.close - d.open) / d.open * 100);
});
var fluctuationGroup = fluctuation.group();
var quarter = ndx.dimension(function (d) {
var month = d.dd.getMonth();
if (month <= 3)
return "Q1";
else if (month > 3 && month <= 5)
return "Q2";
else if (month > 5 && month <= 7)
return "Q3";
else
return "Q4";
});
var quarterGroup = quarter.group().reduceSum(function (d) {
return d.volume;
});
var dayOfWeek = ndx.dimension(function (d) {
var day = d.dd.getDay();
switch (day) {
case 0:
return "0.Sun";
case 1:
return "1.Mon";
case 2:
return "2.Tue";
case 3:
return "3.Wed";
case 4:
return "4.Thu";
case 5:
return "5.Fri";
case 6:
return "6.Sat";
}
});
var dayOfWeekGroup = dayOfWeek.group();
*/
/*
yearlyBubbleChart.width(990)
.height(250)
.margins({top: 10, right: 50, bottom: 30, left: 40})
.dimension(yearlyDimension)
.group(yearlyPerformanceGroup)
.transitionDuration(1500)
.colors(["#a60000", "#ff0000", "#ff4040", "#ff7373", "#67e667", "#39e639", "#00cc00"])
.colorDomain([-12000, 12000])
.colorAccessor(function (d) {
return d.value.absGain;
})
.keyAccessor(function (p) {
return p.value.absGain;
})
.valueAccessor(function (p) {
return p.value.percentageGain;
})
.radiusValueAccessor(function (p) {
return p.value.fluctuationPercentage;
})
.maxBubbleRelativeSize(0.3)
.x(d3.scale.linear().domain([-2500, 2500]))
.y(d3.scale.linear().domain([-100, 100]))
.r(d3.scale.linear().domain([0, 4000]))
.elasticY(true)
.yAxisPadding(100)
.elasticX(true)
.xAxisPadding(500)
.renderHorizontalGridLines(true)
.renderVerticalGridLines(true)
.renderLabel(true)
.renderTitle(true)
.label(function (p) {
return p.key.getFullYear();
})
.title(function (p) {
return p.key.getFullYear()
+ "\n"
+ "Index Gain: " + numberFormat(p.value.absGain) + "\n"
+ "Index Gain in Percentage: " + numberFormat(p.value.percentageGain) + "%\n"
+ "Fluctuation / Index Ratio: " + numberFormat(p.value.fluctuationPercentage) + "%";
})
.yAxis().tickFormat(function (v) {
return v + "%";
});
*/
/*
gainOrLossChart.width(180)
.height(180)
.radius(80)
.dimension(gainOrLoss)
.group(gainOrLossGroup)
.label(function (d) {
return d.data.key + "(" + Math.floor(d.data.value / all.value() * 100) + "%)";
});
*/
/*
quarterChart.width(180)
.height(180)
.radius(80)
.innerRadius(30)
.dimension(quarter)
.group(quarterGroup);
*/
/*
dayOfWeekChart.width(180)
.height(180)
.margins({top: 20, left: 10, right: 10, bottom: 20})
.group(dayOfWeekGroup)
.dimension(dayOfWeek)
.colors(['#3182bd', '#6baed6', '#9ecae1', '#c6dbef', '#dadaeb'])
.label(function (d){
return d.key.split(".")[1];
})
.xAxis().ticks(4);
*/
/*
fluctuationChart.width(420)
.height(180)
.margins({top: 10, right: 50, bottom: 30, left: 40})
.dimension(fluctuation)
.group(fluctuationGroup)
.elasticY(true)
.centerBar(true)
.gap(1)
.round(dc.round.floor)
.x(d3.scale.linear().domain([-25, 25]))
.renderHorizontalGridLines(true)
.xAxis()
.tickFormat(function (v) {
return v + "%";
});
*/
moveChart
.
width
(
800
)
.
height
(
150
)
...
...
@@ -450,6 +316,7 @@ d3.csv("/chart/corpus/{{ corpus.id }}/data.csv", function (data) {
.
renderlet
(
function
(
chart
)
{
chart
.
select
(
"g.y"
).
style
(
"display"
,
"none"
);
moveChart
.
filter
(
chart
.
filter
());
datesbuffer
=
chart
.
filter
();
})
.
on
(
"filtered"
,
function
(
chart
)
{
dc
.
events
.
trigger
(
function
()
{
...
...
@@ -457,47 +324,6 @@ d3.csv("/chart/corpus/{{ corpus.id }}/data.csv", function (data) {
});
});
/*
dc.dataCount(".dc-data-count")
.dimension(ndx)
.group(all);
*/
/*
dc.dataTable(".dc-data-table")
.dimension(dateDimension)
.group(function (d) {
var format = d3.format("02d");
return d.dd.getFullYear() + "/" + format((d.dd.getMonth() + 1));
})
.size(10)
.columns([
function (d) {
return d.date;
},
function (d) {
return d.open;
},
function (d) {
return d.close;
},
function (d) {
return numberFormat(d.close - d.open);
},
function (d) {
return d.volume;
}
])
.sortBy(function (d) {
return d.dd;
})
.order(d3.ascending)
.renderlet(function (table) {
table.selectAll(".dc-table-group").classed("info", true);
});
*/
dc
.
renderAll
();
}
);
...
...
This diff is collapsed.
Click to expand it.
templates/node-info.html
View file @
d18065e7
...
...
@@ -81,9 +81,15 @@
output += "
<
div
class
=
'nodeinfo-container'
>
"
if(jsondata.title) output += "
<
div
class
=
'nodeinfo-elem'
>
<
div
class
=
'nodeinfo-head'
>
Title
<
/div> <div class='nodeinfo-content'>"+jsondata.title+"</
div
>
<
/div>"
;
if
(
jsondata
.
publication_date
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Publication Date</div> <div class='nodeinfo-content'>"
+
jsondata
.
publication_date
.
split
(
" "
)[
0
]
+
"</div> </div>"
;
if
(
jsondata
.
authors
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Authors</div> <div class='nodeinfo-content'>"
+
jsondata
.
authors
+
"</div> </div>"
;
if
(
jsondata
.
authors
&&
jsondata
.
authors
!=
"not found"
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Authors</div> <div class='nodeinfo-content'>"
+
jsondata
.
authors
+
"</div> </div>"
;
else
{
if
(
jsondata
.
source
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Published in</div> <div class='nodeinfo-content'>"
+
jsondata
.
source
+
"</div> </div>"
;
}
if
(
jsondata
.
fields
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Keywords</div> <div class='nodeinfo-content'>"
+
jsondata
.
fields
+
"</div> </div>"
;
if
(
jsondata
.
abstract
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Abstract</div> <div class='nodeinfo-content'>"
+
jsondata
.
abstract
+
"</div> </div>"
;
else
{
if
(
jsondata
.
text
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Abstract</div> <div class='nodeinfo-content'>"
+
jsondata
.
text
+
"</div> </div>"
;
}
output
+=
"</div>"
$
(
"#metadata"
).
html
(
output
);
...
...
This diff is collapsed.
Click to expand it.
templates/subcorpus.html
0 → 100644
View file @
d18065e7
{% if date %}
<p>
Today: {{date}}
</p>
{% endif %}
<div
class=
"pagination"
>
<span
class=
"step-links"
>
{% if documents.has_previous %}
<a
onclick=
"updateDocuments({{ documents.previous_page_number }},true);"
>
previous
</a>
{% endif %}
<span
class=
"current"
>
Page {{ documents.number }} of {{ documents.paginator.num_pages }}.
</span>
{% if documents.has_next %}
<a
onclick=
"updateDocuments({{ documents.next_page_number }},true);"
>
next
</a>
{% endif %}
</span>
</div>
{% if documents %}
<p>
Paginator stuff
</p>
<ul>
{% for doc in documents %}
{% if doc.date %}
<li>
<b>
{{ doc.date }}
</b>
,
<a
href=
"/admin/node/document/{{doc.id}}"
>
id:{{ doc.id}} title:{{ doc.name}}
</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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