Bläddra i källkod

Seum timeline on the home page

Denis Merigoux 9 år sedan
förälder
incheckning
5e819c5c1f
2 ändrade filer med 37 tillägg och 6 borttagningar
  1. 14 2
      counter/templates/homeTemplate.html
  2. 23 4
      counter/views.py

+ 14 - 2
counter/templates/homeTemplate.html

@@ -1,6 +1,6 @@
1 1
 {% extends 'baseTemplate.html' %} {% block title %}Compteurs{% endblock %} {% block content %}
2 2
 <div class="text-center">
3
-	<h1>Compteurs de seum</h1>
3
+	<h1>Seum Center</h1>
4 4
 </div>
5 5
 <div class="container-fluid">
6 6
 	<div class="row">
@@ -45,7 +45,19 @@
45 45
 					<h2 class="panel-title">Graphe du seum</h2>
46 46
 				</div>
47 47
 				<div class="panel-body graphs">
48
-					{{ chart.as_html }}
48
+					{{ col_chart.as_html }}
49
+				</div>
50
+			</div>
51
+		</div>
52
+	</div>
53
+	<div class="row">
54
+		<div class="col-sm-12">
55
+			<div class="panel panel-default">
56
+				<div class="panel-heading">
57
+					<h2 class="panel-title">Timeline du seum</h2>
58
+				</div>
59
+				<div class="panel-body timeline graphs">
60
+					{{ line_chart.as_html }}
49 61
 				</div>
50 62
 			</div>
51 63
 		</div>

+ 23 - 4
counter/views.py

@@ -39,12 +39,31 @@ def home(request):
39 39
             counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr',threshold=1)
40 40
         counter.isHidden = "hidden"
41 41
     counters = sorted(counters,key=lambda t: -t.lastReset.delta)
42
-    #Generate graph
42
+    #Column graph
43 43
     lastResets.sort(key=lambda x: x[1]['v'])
44 44
     lastResets.insert(0,['Trigramme','Jours sans seum'])
45
-    data = SimpleDataSource(lastResets)
46
-    chart = gchart.ColumnChart(data,options={'title' : '', 'legend' : 'none','vAxis' : { 'viewWindow' : { 'max' : max(maxJSS,1) , 'min' : 0} , 'ticks' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],'title' : 'Jours sans seum' }, 'hAxis' : {'title' : 'Trigramme' }})
47
-    return render(request,'homeTemplate.html', {'counters' : counters, 'chart' : chart})
45
+    col_data = SimpleDataSource(lastResets)
46
+    col_chart = gchart.ColumnChart(col_data,options={'title' : '', 'legend' : 'none','vAxis' : { 'viewWindow' : { 'max' : max(maxJSS,1) , 'min' : 0} , 'ticks' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],'title' : 'Jours sans seum' }, 'hAxis' : {'title' : 'Trigramme' }})
47
+
48
+    ###Timeline graph
49
+    #Data pre-processing
50
+    resets = Reset.objects.filter(timestamp__gte=datetime.now() - timedelta(days=1))
51
+    for reset in resets:
52
+        reset.timestamp={'v' : reset.timestamp.timestamp(), 'f' : "Il y a "+format_timedelta(datetime.now()-reset.timestamp.replace(tzinfo=None),locale='fr',threshold=1) }
53
+        reset.Seum={'v' : 0, 'f' : reset.counter.trigramme+" : "+reset.reason}
54
+    #Drawing the graph
55
+    line_data = ModelDataSource(resets,fields=['timestamp','Seum'])
56
+    line_chart = gchart.LineChart(line_data, options={
57
+        'lineWidth' : 0,
58
+        'pointSize' : 10,
59
+        'title' : '',
60
+        'vAxis' : { 'ticks' : []},
61
+        'hAxis' : {'ticks' : [{'v' : (datetime.now() - timedelta(days=1)).timestamp(), 'f' : 'Il y a 24 h' }, { 'v' :datetime.now().timestamp(), 'f' : 'Présent'}]},
62
+        'legend' : 'none',
63
+        'height' : 90
64
+    })
65
+
66
+    return render(request,'homeTemplate.html', {'counters' : counters, 'col_chart' : col_chart, 'line_chart' : line_chart})
48 67
 
49 68
 def resetCounter(request):
50 69
     #Update Form counter