Commit acb2ceb7 authored by Administrator's avatar Administrator

[DESIGN] Templates and views: camembert (donut) to see composition of each...

[DESIGN] Templates and views: camembert (donut) to see composition of each project. Histogram to see one corpus.
parent 33be9b7d
...@@ -15,14 +15,17 @@ from django.contrib.auth.models import User ...@@ -15,14 +15,17 @@ from django.contrib.auth.models import User
import datetime import datetime
from itertools import * from itertools import *
from django.db import connection from dateutil.parser import parse
from django.db import connection
from django import forms from django import forms
from collections import defaultdict from collections import defaultdict
from parsing.FileParsers import * from parsing.FileParsers import *
# SOME FUNCTIONS # SOME FUNCTIONS
def query_to_dicts(query_string, *query_args): def query_to_dicts(query_string, *query_args):
...@@ -185,13 +188,21 @@ def project(request, project_id): ...@@ -185,13 +188,21 @@ def project(request, project_id):
else: else:
form = CorpusForm(request=request) form = CorpusForm(request=request)
formResource = ResourceForm() formResource = ResourceForm()
camembert = [
{'source': 'Science', 'count': 33, 'part': 3},
{'source': 'Press', 'count': 23, 'part': 3},
{'source': 'Web', 'count': 50, 'part': 3},
]
return render(request, 'project.html', { return render(request, 'project.html', {
'form': form, 'form': form,
'formResource': formResource, 'formResource': formResource,
'user': user, 'user': user,
'date': date, 'date': date,
'project': project, 'project': project,
'camembert' : camembert,
'board' : board, 'board' : board,
'number': number, 'number': number,
}) })
...@@ -215,7 +226,7 @@ def corpus(request, project_id, corpus_id): ...@@ -215,7 +226,7 @@ def corpus(request, project_id, corpus_id):
corpus = Node.objects.get(id=corpus_id) corpus = Node.objects.get(id=corpus_id)
#print(Document.objects.filter(corpus=c_id, user=request.user.pk).query) #print(Document.objects.filter(corpus=c_id, user=request.user.pk).query)
documents = corpus.children documents = corpus.children.all()
number = corpus.children.count() number = corpus.children.count()
try: try:
...@@ -234,19 +245,24 @@ def corpus(request, project_id, corpus_id): ...@@ -234,19 +245,24 @@ def corpus(request, project_id, corpus_id):
source_count['part'] = None source_count['part'] = None
source_count['source'] = source['source'] source_count['source'] = source['source']
sources_donut.append(source_count) sources_donut.append(source_count)
except: except:
sources_donut = [] sources_donut = []
try: try:
first = documents.first().date histo = [{'2001':12}, {'2002': 13}]
last = documents.last().date
first = parse(documents.first().metadata['publication_date'])
last = parse(documents.last().metadata['publication_date'])
duree = first - last duree = first - last
if duree.days > 365: if duree.days > 365:
date_format = 'YYYY' date_format = 'YYYY'
date_form = 'years' date_form = 'years'
for document in documents:
pass
elif duree.days > 60: elif duree.days > 60:
date_format = 'YYYY-MM' date_format = 'YYYY-MM'
date_form = 'months' date_form = 'months'
...@@ -257,28 +273,27 @@ def corpus(request, project_id, corpus_id): ...@@ -257,28 +273,27 @@ def corpus(request, project_id, corpus_id):
try: try:
dates = dict() dates = dict()
# query_to_dicts('''select to_char(t1.date, '%s'), count(*)
# from documents_document as t1
# INNER JOIN documents_document_corpus as t2
# ON ( t1.id = t2.document_id )
# WHERE ( t1.user_id = %d AND t2.corpus_id = %d )
# group by to_char(t1.date, '%s')
# order by 1 DESC;''' % (date_format, request.user.pk, int(corpus_id), date_format))
except: except:
pass pass
histo = []
# for e in date_range('1990-01', '1992-02', format=date_form): # for e in date_range('1990-01', '1992-02', format=date_form):
# print(e) # print(e)
# if date_format = 'YYYY': # if date_format = 'YYYY':
# while True: # while True:
# if d -histo.append(d) # if d -histo.append(d)
for d in dates: # for d in dates:
histo.append(d) # histo.append(d)
except: except:
histo = None histo = [
{'to_char': 2000, 'count': 13},
{'to_char': 2001, 'count': 20},
{'to_char': 2002, 'count': 5},
{'to_char': 2003, 'count': 130},
{'to_char': 2004, 'count': 300},
]
#histo = None
html = t.render(Context({\ html = t.render(Context({\
'user': user,\ 'user': user,\
...@@ -287,7 +302,6 @@ def corpus(request, project_id, corpus_id): ...@@ -287,7 +302,6 @@ def corpus(request, project_id, corpus_id):
'corpus' : corpus,\ 'corpus' : corpus,\
'documents': documents,\ 'documents': documents,\
'number' : number,\ 'number' : number,\
'sources_donut' : sources_donut,\
'dates' : histo,\ 'dates' : histo,\
})) }))
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<link rel="stylesheet" type="text/css" href="{% static "css/morris.css" %}"> <link rel="stylesheet" type="text/css" href="{% static "css/morris.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/jquery.easy-pie-chart.css"%}"> <link rel="stylesheet" type="text/css" href="{% static "css/jquery.easy-pie-chart.css"%}">
<script src="{% static "js/jquery-1.9.1.min.js"%}"></script> <script src="{% static "js/jquery/jquery-1.9.1.min.js"%}"></script>
<script src="{% static "js/raphael-min.js"%}"></script> <script src="{% static "js/raphael-min.js"%}"></script>
<script src="{% static "js/morris.min.js"%}"></script> <script src="{% static "js/morris.min.js"%}"></script>
...@@ -23,14 +23,12 @@ ...@@ -23,14 +23,12 @@
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
{% if project %} {% if project %}
<h1>{{ project.title }} </h1> <h1>{{ project.name }} </h1>
<p> {{ project.subtitle }}</p>
{% endif %} {% endif %}
{% if corpus %} {% if corpus %}
<h2>{{ corpus.title }} </h2> <h2>{{ corpus.name }} </h2>
<p>{{ corpus.subtitle }} </p> <p>Created on {{ corpus.date }}, ({{ number}} docs)</p>
<p>{{ corpus.date }}, {{ corpus.language }}, {{ corpus.database }} ({{ number}} docs)</p>
{% endif %} {% endif %}
{% if number > 0 %} {% if number > 0 %}
...@@ -57,9 +55,9 @@ ...@@ -57,9 +55,9 @@
<div class="jumbotron"> <div class="jumbotron">
<h3>Exploration</h3> <h3>Exploration</h3>
<ol> <ol>
<li>Feature</li> <li>Count frequency</li>
<li>Feature</li> <li>Configurable Charts</li>
<li>Feature</li> <li>Explore Matrix</li>
</ol> </ol>
</div> </div>
</div> </div>
...@@ -68,8 +66,8 @@ ...@@ -68,8 +66,8 @@
<div class="jumbotron"> <div class="jumbotron">
<h3>Cartography</h3> <h3>Cartography</h3>
<ol> <ol>
<li>Feature</li> <li>Socio-Semantic</li>
<li>Feature</li> <li>Graphs</li>
<li>Feature</li> <li>Feature</li>
</ol> </ol>
</div> </div>
...@@ -79,8 +77,8 @@ ...@@ -79,8 +77,8 @@
<div class="jumbotron"> <div class="jumbotron">
<h3>Dynamics</h3> <h3>Dynamics</h3>
<ol> <ol>
<li>Feature</li> <li>Dynamic maps</li>
<li>Feature</li> <li>Phylomemy</li>
<li>Feature</li> <li>Feature</li>
</ol> </ol>
</div> </div>
...@@ -98,8 +96,8 @@ ...@@ -98,8 +96,8 @@
element: 'hero-area', element: 'hero-area',
data: [ data: [
{% if dates %} {% if dates %}
{% for d in dates %} {% for date in dates %}
{Period: '{{ d.to_char }}', Quantity: '{{ d.count }}', Infos: '10'}, {Period: '{{ date.to_char }}', Quantity: '{{ date.count }}', Infos: '10'},
{% endfor %} {% endfor %}
{% endif %} {% endif %}
], ],
...@@ -112,23 +110,4 @@ ...@@ -112,23 +110,4 @@
}); });
</script> </script>
<script>
// Morris Donut Chart
Morris.Donut({
element: 'hero-donut',
data: [
{% if sources_donut %}
{% for source in sources_donut %}
{label: '{{ source.source }}, {{source.count}} docs', value: {{ source.part }} },
{% endfor %}
{% endif %}
],
colors: ["#939393", "#939555"],
//colors: ["#30a1ec", "#76bdee"],
formatter: function (y) { return y + "%" }
});
</script>
{% endblock %} {% endblock %}
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
<link rel="stylesheet" href="{% static "css/bootstrap.css" %}"> <link rel="stylesheet" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap-theme.min.css" %}"> <link rel="stylesheet" href="{% static "css/bootstrap-theme.min.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/morris.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/jquery.easy-pie-chart.css"%}">
<script src="{% static "js/jquery/jquery-1.9.1.min.js"%}"></script>
<script src="{% static "js/raphael-min.js"%}"></script>
<script src="{% static "js/morris.min.js"%}"></script>
{% endblock %} {% endblock %}
...@@ -25,8 +32,9 @@ ...@@ -25,8 +32,9 @@
<div class="col-md-4"> <div class="col-md-4">
<p> <p>
<br> <div id="hero-donut" style="height: 200px;"></div>
<button <center>
<button
type="button" type="button"
class="btn btn-primary btn-lg" class="btn btn-primary btn-lg"
data-container="body" data-container="body"
...@@ -44,11 +52,12 @@ ...@@ -44,11 +52,12 @@
{{ formResource.as_p}} {{ formResource.as_p}}
<input type="submit" class="btn" value="Add this corpus" /> <input type="submit" class="btn" value="Add this corpus" />
</form> </form>
</center>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
...@@ -80,4 +89,26 @@ ...@@ -80,4 +89,26 @@
</div> </div>
</div> </div>
<script>
// Morris Donut Chart
Morris.Donut({
element: 'hero-donut',
data: [
{% if camembert %}
{% for part in camembert %}
{label: '{{ part.source }}, {{part.count}} docs', value: {{ part.part }} },
{% endfor %}
{% endif %}
],
colors: ["#939393", "#939555"],
//colors: ["#30a1ec", "#76bdee"],
formatter: function (y) { return y + "%" }
});
</script>
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment