Bladeren bron

Chart for JSS

Denis Merigoux 9 jaren geleden
bovenliggende
commit
205d54c02a
5 gewijzigde bestanden met toevoegingen van 37 en 21 verwijderingen
  1. 19 18
      counter/templates/baseTemplate.html
  2. 3 2
      counter/templates/counterTemplate.html
  3. 13 1
      counter/views.py
  4. 1 0
      requirements.txt
  5. 1 0
      seum/settings.py

+ 19 - 18
counter/templates/baseTemplate.html

@@ -1,33 +1,34 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3
+
3 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 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 14
 	<style>
22 15
 		.seum-counter {
23
-			height:125px;
16
+			height: 125px;
24 17
 			overflow: auto;
25
-			margin-bottom:15px;
18
+			margin-bottom: 15px;
26 19
 		}
27 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 28
 </head>
29
-	<section id="content">
30
-		{% block content %}{% endblock %}
31
-	</section>
29
+<section id="content">
30
+	{% block content %}{% endblock %}
31
+</section>
32 32
 </body>
33
+
33 34
 </html>

+ 3 - 2
counter/templates/counterTemplate.html

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

+ 13 - 1
counter/views.py

@@ -5,6 +5,8 @@ from datetime import datetime
5 5
 from django import forms
6 6
 from django.http import HttpResponseRedirect
7 7
 from django.core import serializers
8
+from graphos.renderers import gchart
9
+from graphos.sources.simple import SimpleDataSource
8 10
 
9 11
 class resetCounterForm(forms.ModelForm):
10 12
     class Meta:
@@ -15,6 +17,9 @@ class resetCounterForm(forms.ModelForm):
15 17
 def home(request):
16 18
     #Display counters
17 19
     counters = Counter.objects.all()
20
+    lastResets = [['Trigramme','Jours sans seum']]
21
+    #Calculates infos for each counter
22
+    maxJSS = 0
18 23
     for counter in counters:
19 24
         lastReset = Reset.objects.filter(counter=counter).order_by('-timestamp')
20 25
         if (lastReset.count() == 0):
@@ -22,9 +27,16 @@ def home(request):
22 27
         else:
23 28
             counter.lastReset = lastReset[0]
24 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 33
             counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr')
26 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 41
 def resetCounter(request):
30 42
     #Update Form counter

+ 1 - 0
requirements.txt

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

+ 1 - 0
seum/settings.py

@@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
32 32
 
33 33
 INSTALLED_APPS = [
34 34
     'babel',
35
+    'graphos',
35 36
     'bootstrap3',
36 37
     'django.contrib.admin',
37 38
     'django.contrib.auth',