소스 검색

Added new graph to display best seumers

Denis Merigoux 9 년 전
부모
커밋
afab1f400e
3개의 변경된 파일41개의 추가작업 그리고 3개의 파일을 삭제
  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,5 +74,21 @@
74 74
 			</div>
75 75
 		</div>
76 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 93
 </div>
78 94
 {% endblock %}

+ 24 - 2
counter/views.py

@@ -24,11 +24,12 @@ class resetCounterForm(forms.ModelForm):
24 24
 def home(request):
25 25
     # JSS above this limit will not be displayed on the col graph
26 26
     JSS_limit = 7
27
+    maxJSS = 0
28
+    bestSeumeursNumber = 15
27 29
     # Display counters
28 30
     counters = Counter.objects.all()
29 31
     lastResets = []
30 32
     # Calculates infos for each counter
31
-    maxJSS = 0
32 33
     timezero = timedelta(0)
33 34
     for counter in counters:
34 35
         lastReset = Reset.objects.filter(
@@ -130,13 +131,34 @@ def home(request):
130 131
             'legend': 'none',
131 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 154
     return render(request, 'homeTemplate.html', {
135 155
         'counters': counters,
136 156
         'col_chart': col_chart,
137 157
         'line_chart': line_chart,
158
+        'best_chart': best_chart,
138 159
         'noTimeline': noTimeline,
139
-        'noGraph': noGraph
160
+        'noGraph': noGraph,
161
+        'noBestSeum': noBestSeum
140 162
     })
141 163
 
142 164
 

+ 1 - 1
seum/settings.py

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