Explorar o código

Chart for JSS

Denis Merigoux %!s(int64=9) %!d(string=hai) anos
pai
achega
205d54c02a

+ 19 - 18
counter/templates/baseTemplate.html

1
 <!DOCTYPE html>
1
 <!DOCTYPE html>
2
 <html>
2
 <html>
3
+
3
 <head>
4
 <head>
4
-	<meta charset="UTF-8"/>
5
-	<meta name="author" content="Seum Man"/>
6
-	<meta name="keywords" content="seum compteur"/>
7
-	<meta name="description" content="Compteur de seum"/>
5
+	<meta charset="UTF-8" />
6
+	<meta name="author" content="Seum Man" />
7
+	<meta name="keywords" content="seum compteur" />
8
+	<meta name="description" content="Compteurs de seum" />
8
 
9
 
9
 	<title>Seum – {% block title %}{% endblock %}</title>
10
 	<title>Seum – {% block title %}{% endblock %}</title>
10
 
11
 
11
-	{# Load the tag library #}
12
-	{% load bootstrap3 %}
13
-
14
-	{# Load CSS and JavaScript #}
15
-	{% bootstrap_css %}
16
-	{% bootstrap_javascript %}
17
-
18
-	{# Display django.contrib.messages as Bootstrap alerts #}
19
-	{% bootstrap_messages %}
12
+	{# Load the tag library #} {% load bootstrap3 %} {# Load CSS and JavaScript #} {% bootstrap_css %} {% bootstrap_javascript %} {# Display django.contrib.messages as Bootstrap alerts #} {% bootstrap_messages %}
20
 
13
 
21
 	<style>
14
 	<style>
22
 		.seum-counter {
15
 		.seum-counter {
23
-			height:125px;
16
+			height: 125px;
24
 			overflow: auto;
17
 			overflow: auto;
25
-			margin-bottom:15px;
18
+			margin-bottom: 15px;
26
 		}
19
 		}
27
 	</style>
20
 	</style>
21
+
22
+	<script type="text/javascript" src="https://www.google.com/jsapi"></script>
23
+	<script type="text/javascript">
24
+		google.load("visualization", "1", {
25
+			packages: ["corechart"]
26
+		});
27
+	</script>
28
 </head>
28
 </head>
29
-	<section id="content">
30
-		{% block content %}{% endblock %}
31
-	</section>
29
+<section id="content">
30
+	{% block content %}{% endblock %}
31
+</section>
32
 </body>
32
 </body>
33
+
33
 </html>
34
 </html>

+ 3 - 2
counter/templates/counterTemplate.html

37
 		</div>
37
 		</div>
38
 		{% endfor %}
38
 		{% endfor %}
39
 	</div>
39
 	</div>
40
-</div>
41
-{% endblock %}
40
+			{{ chart.as_html }}
41
+	</div>
42
+	{% endblock %}

+ 13 - 1
counter/views.py

5
 from django import forms
5
 from django import forms
6
 from django.http import HttpResponseRedirect
6
 from django.http import HttpResponseRedirect
7
 from django.core import serializers
7
 from django.core import serializers
8
+from graphos.renderers import gchart
9
+from graphos.sources.simple import SimpleDataSource
8
 
10
 
9
 class resetCounterForm(forms.ModelForm):
11
 class resetCounterForm(forms.ModelForm):
10
     class Meta:
12
     class Meta:
15
 def home(request):
17
 def home(request):
16
     #Display counters
18
     #Display counters
17
     counters = Counter.objects.all()
19
     counters = Counter.objects.all()
20
+    lastResets = [['Trigramme','Jours sans seum']]
21
+    #Calculates infos for each counter
22
+    maxJSS = 0
18
     for counter in counters:
23
     for counter in counters:
19
         lastReset = Reset.objects.filter(counter=counter).order_by('-timestamp')
24
         lastReset = Reset.objects.filter(counter=counter).order_by('-timestamp')
20
         if (lastReset.count() == 0):
25
         if (lastReset.count() == 0):
22
         else:
27
         else:
23
             counter.lastReset = lastReset[0]
28
             counter.lastReset = lastReset[0]
24
             counter.lastReset.delta = datetime.now()-counter.lastReset.timestamp.replace(tzinfo=None)
29
             counter.lastReset.delta = datetime.now()-counter.lastReset.timestamp.replace(tzinfo=None)
30
+            lastResets.append([counter.trigramme,(counter.lastReset.delta.total_seconds())/(24*3600)])
31
+            if (counter.lastReset.delta.total_seconds())/(24*3600) > maxJSS:
32
+                maxJSS = (counter.lastReset.delta.total_seconds())/(24*3600)
25
             counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr')
33
             counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr')
26
         counter.isHidden = "hidden"
34
         counter.isHidden = "hidden"
27
-    return render(request,'counterTemplate.html', {'counters' : counters})
35
+
36
+    #Generate graph
37
+    data = SimpleDataSource(lastResets)
38
+    chart = gchart.ColumnChart(data,options={'title' : 'Graphe du seum', 'legend' : 'none','vAxis' : { 'viewWindow' : { 'max' : maxJSS+0.25} , 'ticks' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],'title' : 'Jours sans seum' }, 'hAxis' : {'title' : 'Trigramme' }})
39
+    return render(request,'counterTemplate.html', {'counters' : counters, 'chart' : chart})
28
 
40
 
29
 def resetCounter(request):
41
 def resetCounter(request):
30
     #Update Form counter
42
     #Update Form counter

+ 1 - 0
requirements.txt

1
 django
1
 django
2
 babel
2
 babel
3
 django-bootstrap3
3
 django-bootstrap3
4
+django-graphos-3

+ 1 - 0
seum/settings.py

32
 
32
 
33
 INSTALLED_APPS = [
33
 INSTALLED_APPS = [
34
     'babel',
34
     'babel',
35
+    'graphos',
35
     'bootstrap3',
36
     'bootstrap3',
36
     'django.contrib.admin',
37
     'django.contrib.admin',
37
     'django.contrib.auth',
38
     'django.contrib.auth',