Bladeren bron

Added new graph to display best seumers

Denis Merigoux 9 jaren geleden
bovenliggende
commit
afab1f400e
3 gewijzigde bestanden met toevoegingen van 41 en 3 verwijderingen
  1. 16 0
      counter/templates/homeTemplate.html
  2. 24 2
      counter/views.py
  3. 1 1
      seum/settings.py

+ 16 - 0
counter/templates/homeTemplate.html

74
 			</div>
74
 			</div>
75
 		</div>
75
 		</div>
76
 	</div>
76
 	</div>
77
+	<div class="row">
78
+		<div class="col-sm-12">
79
+			<div class="panel panel-default">
80
+				<div class="panel-heading">
81
+					<h2 class="panel-title">Meilleurs seumeurs</h2>
82
+				</div>
83
+				<div class="panel-body graphs">
84
+					{% if noBestSeum %}
85
+					<div class="text-center text-muted">
86
+						<p>Personne n'a eu le seum...</p>
87
+					</div>
88
+					{% else %} {{ best_chart.as_html }} {% endif %}
89
+				</div>
90
+			</div>
91
+		</div>
92
+	</div>
77
 </div>
93
 </div>
78
 {% endblock %}
94
 {% endblock %}

+ 24 - 2
counter/views.py

24
 def home(request):
24
 def home(request):
25
     # JSS above this limit will not be displayed on the col graph
25
     # JSS above this limit will not be displayed on the col graph
26
     JSS_limit = 7
26
     JSS_limit = 7
27
+    maxJSS = 0
28
+    bestSeumeursNumber = 15
27
     # Display counters
29
     # Display counters
28
     counters = Counter.objects.all()
30
     counters = Counter.objects.all()
29
     lastResets = []
31
     lastResets = []
30
     # Calculates infos for each counter
32
     # Calculates infos for each counter
31
-    maxJSS = 0
32
     timezero = timedelta(0)
33
     timezero = timedelta(0)
33
     for counter in counters:
34
     for counter in counters:
34
         lastReset = Reset.objects.filter(
35
         lastReset = Reset.objects.filter(
130
             'legend': 'none',
131
             'legend': 'none',
131
             'height': 90
132
             'height': 90
132
         })
133
         })
134
+    # Graph of greatest seumers
135
+    seumCounts = []
136
+    for counter in counters:
137
+        seumCounts.append([counter.trigramme, Reset.objects.filter(
138
+            counter=counter).count()])
139
+    if (len(seumCounts) == 0):
140
+        noBestSeum = True
141
+        best_chart = None
142
+    else:
143
+        seumCounts.sort(key=lambda x: -x[1])
144
+        noBestSeum = False
145
+        seumCounts.insert(0, ['Trigramme', 'Nombre de seums'])
146
+        best_data = SimpleDataSource(seumCounts[:bestSeumeursNumber])
147
+        best_chart = gchart.ColumnChart(best_data, options={
148
+            'title': '',
149
+            'legend': 'none',
150
+            'vAxis': {'title': 'Nombre de seums'},
151
+            'hAxis': {'title': 'Trigramme'},
152
+        })
133
 
153
 
134
     return render(request, 'homeTemplate.html', {
154
     return render(request, 'homeTemplate.html', {
135
         'counters': counters,
155
         'counters': counters,
136
         'col_chart': col_chart,
156
         'col_chart': col_chart,
137
         'line_chart': line_chart,
157
         'line_chart': line_chart,
158
+        'best_chart': best_chart,
138
         'noTimeline': noTimeline,
159
         'noTimeline': noTimeline,
139
-        'noGraph': noGraph
160
+        'noGraph': noGraph,
161
+        'noBestSeum': noBestSeum
140
     })
162
     })
141
 
163
 
142
 
164
 

+ 1 - 1
seum/settings.py

23
 SECRET_KEY = '(#lovv#uky9unr9azzqy14gktpf0(d&+cp@++l95*y4e%m%_ex'
23
 SECRET_KEY = '(#lovv#uky9unr9azzqy14gktpf0(d&+cp@++l95*y4e%m%_ex'
24
 
24
 
25
 # SECURITY WARNING: don't run with debug turned on in production!
25
 # SECURITY WARNING: don't run with debug turned on in production!
26
-DEBUG = False
26
+DEBUG = True
27
 
27
 
28
 ALLOWED_HOSTS = ['seum.merigoux.ovh']
28
 ALLOWED_HOSTS = ['seum.merigoux.ovh']
29
 
29