Kaynağa Gözat

Changed graphs

Denis Merigoux 9 yıl önce
ebeveyn
işleme
64cd1076e1
2 değiştirilmiş dosya ile 110 ekleme ve 54 silme
  1. 40 8
      counter/templates/homeTemplate.html
  2. 70 46
      counter/views.py

+ 40 - 8
counter/templates/homeTemplate.html

155
 		<div class="col-sm-12">
155
 		<div class="col-sm-12">
156
 			<div class="panel panel-info">
156
 			<div class="panel panel-info">
157
 				<div class="panel-heading">
157
 				<div class="panel-heading">
158
-					<h2 class="panel-title">Graphe des jours sans seum</h2>
158
+					<h2 class="panel-title">Meilleurs seumeurs</h2>
159
 				</div>
159
 				</div>
160
 				<div class="panel-body graphs">
160
 				<div class="panel-body graphs">
161
-					{% if noGraph %}
161
+					{% if noBestSeum %}
162
 					<div class="text-center text-muted">
162
 					<div class="text-center text-muted">
163
-						<p>Personne n'a le seum...</p>
163
+						<p>Personne n'a eu le seum...</p>
164
 					</div>
164
 					</div>
165
-					{% else %} {{ col_chart.as_html }} {% endif %}
165
+					{% else %} {{ best_chart.as_html }} {% endif %}
166
 				</div>
166
 				</div>
167
 			</div>
167
 			</div>
168
 		</div>
168
 		</div>
171
 		<div class="col-sm-12">
171
 		<div class="col-sm-12">
172
 			<div class="panel panel-info">
172
 			<div class="panel panel-info">
173
 				<div class="panel-heading">
173
 				<div class="panel-heading">
174
-					<h2 class="panel-title">Meilleurs seumeurs</h2>
174
+					<h2 class="panel-title">Seumeurs les plus likés</h2>
175
 				</div>
175
 				</div>
176
 				<div class="panel-body graphs">
176
 				<div class="panel-body graphs">
177
-					{% if noBestSeum %}
177
+					{% if noBestLikees %}
178
 					<div class="text-center text-muted">
178
 					<div class="text-center text-muted">
179
-						<p>Personne n'a eu le seum...</p>
179
+						<p>Personne n'a liké...</p>
180
 					</div>
180
 					</div>
181
-					{% else %} {{ best_chart.as_html }} {% endif %}
181
+					{% else %} {{ likees_chart.as_html }} {% endif %}
182
+				</div>
183
+			</div>
184
+		</div>
185
+	</div>
186
+	<div class="row">
187
+		<div class="col-sm-12">
188
+			<div class="panel panel-info">
189
+				<div class="panel-heading">
190
+					<h2 class="panel-title">Hashtags les plus populaires</h2>
191
+				</div>
192
+				<div class="panel-body graphs">
193
+					{% if noBestHashtags %}
194
+					<div class="text-center text-muted">
195
+						<p>Personne n'a utilisé de hashtags...</p>
196
+					</div>
197
+					{% else %} {{ hashtags_chart.as_html }} {% endif %}
198
+				</div>
199
+			</div>
200
+		</div>
201
+	</div>
202
+	<div class="row">
203
+		<div class="col-sm-12">
204
+			<div class="panel panel-info">
205
+				<div class="panel-heading">
206
+					<h2 class="panel-title">Meilleurs likeurs de seum</h2>
207
+				</div>
208
+				<div class="panel-body graphs">
209
+					{% if noBestLikers %}
210
+					<div class="text-center text-muted">
211
+						<p>Personne n'a liké...</p>
212
+					</div>
213
+					{% else %} {{ likers_chart.as_html }} {% endif %}
182
 				</div>
214
 				</div>
183
 			</div>
215
 			</div>
184
 		</div>
216
 		</div>

+ 70 - 46
counter/views.py

20
 from django.utils import timezone
20
 from django.utils import timezone
21
 from counter.utils import parseSeumReason
21
 from counter.utils import parseSeumReason
22
 
22
 
23
-# JSS above this limit will not be displayed on the home page col graph
24
-JSS_limit = 7
25
 # Number of counters displayed on the home page's best seumeurs graph
23
 # Number of counters displayed on the home page's best seumeurs graph
26
 bestSeumeursNumber = 15
24
 bestSeumeursNumber = 15
27
 
25
 
29
 @login_required
27
 @login_required
30
 def home(request):
28
 def home(request):
31
     # Used later to keep track of the maximum JSS
29
     # Used later to keep track of the maximum JSS
32
-    maxJSS = 0
33
     lastResets = []
30
     lastResets = []
34
     no_seum_delta = timedelta.max
31
     no_seum_delta = timedelta.max
35
 
32
 
89
             counter.lastReset.noSeum = False
86
             counter.lastReset.noSeum = False
90
             counter.lastReset.delta = datetime.now(
87
             counter.lastReset.delta = datetime.now(
91
             ) - counter.lastReset.timestamp.replace(tzinfo=None)
88
             ) - counter.lastReset.timestamp.replace(tzinfo=None)
92
-            if ((counter.lastReset.delta.total_seconds()) / (24 * 3600) <
93
-                    JSS_limit):
94
-                # Less than 7 JSS -> display on graph
95
-                lastResets.append(
96
-                    [counter.trigramme,
97
-                     {'v': (counter.lastReset.delta.total_seconds()) /
98
-                      (24 * 3600),
99
-                      'f': str(round(
100
-                          (counter.lastReset.delta.total_seconds()) /
101
-                          (24 * 3600), 1))}])
102
-                # Updating the max JSS displayed on the graph to compute scale
103
-                if (counter.lastReset.delta.total_seconds() / (24 * 3600) >
104
-                        maxJSS):
105
-                    maxJSS = (counter.lastReset.delta.total_seconds() /
106
-                              (24 * 3600))
107
             # Defining CSS attributes for the counter
89
             # Defining CSS attributes for the counter
108
             if counter.id == myCounter.id:
90
             if counter.id == myCounter.id:
109
                 counter.CSSclass = 'primary'
91
                 counter.CSSclass = 'primary'
126
 
108
 
127
     if myCounter.sort_by_score:
109
     if myCounter.sort_by_score:
128
         # Now we sort the counters according to a reddit-like ranking formula
110
         # Now we sort the counters according to a reddit-like ranking formula
129
-        # We take into account the number of likes of a reset and its recentness
111
+        # We take into account the number of likes of a reset and recentness
130
         # The log on the score will give increased value to the first likes
112
         # The log on the score will give increased value to the first likes
131
-        # The negative exp for the time with a characteristic time of 1 day will
132
-        # cause that after 1 day the « recentness score drops from 1 to 0.36
133
         # The counters with no seum have a like count of -1 by convention
113
         # The counters with no seum have a like count of -1 by convention
134
         counters = sorted(counters, key=lambda t: - (
114
         counters = sorted(counters, key=lambda t: - (
135
             math.log(t.likeCount + 2) /
115
             math.log(t.likeCount + 2) /
139
         counters = sorted(counters, key=lambda t: +
119
         counters = sorted(counters, key=lambda t: +
140
                           t.lastReset.delta.total_seconds())
120
                           t.lastReset.delta.total_seconds())
141
 
121
 
142
-        # Column graph
143
-    if (len(lastResets) == 0):
144
-        noGraph = True
145
-        col_chart = None
146
-    else:
147
-        noGraph = False
148
-        lastResets.sort(key=lambda x: x[1]['v'])
149
-        lastResets.insert(0, ['Trigramme', 'Jours sans seum'])
150
-        col_data = SimpleDataSource(lastResets)
151
-        col_chart = gchart.ColumnChart(col_data, options={
152
-            'title': '',
153
-            'legend': 'none',
154
-            'vAxis': {
155
-                'viewWindow': {
156
-                    'max': max(maxJSS, 1),
157
-                    'min': 0
158
-                },
159
-                'ticks': [1, 2, 3, 4, 5, 6, 7],
160
-                'title': 'Jours sans seum'
161
-            },
162
-            'hAxis': {'title': 'Trigramme'},
163
-        })
164
-
165
     # Timeline graph
122
     # Timeline graph
166
     resets = Reset.objects.filter(
123
     resets = Reset.objects.filter(
167
         timestamp__gte=timezone.now() - timedelta(days=1))
124
         timestamp__gte=timezone.now() - timedelta(days=1))
253
             'hAxis': {'title': 'Mois'},
210
             'hAxis': {'title': 'Mois'},
254
         })
211
         })
255
 
212
 
213
+    # Graph of best likers
214
+    likersCounts = []
215
+    for counter in counters:
216
+        likersCounts.append(
217
+            [counter.trigramme, Like.objects.filter(liker=counter).count()])
218
+    if (len(likersCounts) == 0):
219
+        noBestLikers = True
220
+        likers_chart = None
221
+    else:
222
+        likersCounts.sort(key=lambda x: -x[1])
223
+        noBestLikers = False
224
+        likersCounts.insert(0, ['Trigramme', 'Nombre de likes distribués'])
225
+        likers_data = SimpleDataSource(likersCounts[:bestSeumeursNumber])
226
+        likers_chart = gchart.ColumnChart(likers_data, options={
227
+            'title': '',
228
+            'legend': 'none',
229
+            'vAxis': {'title': 'Nombre de likes distribués'},
230
+            'hAxis': {'title': 'Trigramme'},
231
+        })
232
+
233
+    # Graph of popular hashtags
234
+    hashtagsCounts = []
235
+    keywords = Keyword.objects.all()
236
+    for keyword in keywords:
237
+        hashtagsCounts.append(
238
+            ['#' + keyword.text,
239
+             Hashtag.objects.filter(keyword=keyword).count()])
240
+    if (len(hashtagsCounts) == 0):
241
+        noBestHashtags = True
242
+        hashtags_chart = None
243
+    else:
244
+        hashtagsCounts.sort(key=lambda x: -x[1])
245
+        noBestHashtags = False
246
+        hashtagsCounts.insert(0, ['Trigramme', 'Nombre de likes distribués'])
247
+        hashtags_data = SimpleDataSource(hashtagsCounts[:bestSeumeursNumber])
248
+        hashtags_chart = gchart.ColumnChart(hashtags_data, options={
249
+            'title': '',
250
+            'legend': 'none',
251
+            'vAxis': {'title': 'Nombre de seums contenant le hashtag'},
252
+            'hAxis': {'title': 'Hashtag'},
253
+        })
254
+
255
+    # Graph of best likee
256
+    likeesCounts = []
257
+    for counter in counters:
258
+        likeesCounts.append(
259
+            [counter.trigramme,
260
+             Like.objects.filter(reset__counter=counter).count()])
261
+    if (len(likeesCounts) == 0):
262
+        noBestLikees = True
263
+        likees_chart = None
264
+    else:
265
+        likeesCounts.sort(key=lambda x: -x[1])
266
+        noBestLikees = False
267
+        likeesCounts.insert(0, ['Trigramme', 'Nombre de likes reçus'])
268
+        likees_data = SimpleDataSource(likeesCounts[:bestSeumeursNumber])
269
+        likees_chart = gchart.ColumnChart(likees_data, options={
270
+            'title': '',
271
+            'legend': 'none',
272
+            'vAxis': {'title': 'Nombre de likes reçus'},
273
+            'hAxis': {'title': 'Trigramme'},
274
+        })
275
+
256
     # At last we render the page
276
     # At last we render the page
257
     return render(request, 'homeTemplate.html', {
277
     return render(request, 'homeTemplate.html', {
258
         'counters': counters,
278
         'counters': counters,
259
-        'col_chart': col_chart,
260
         'line_chart': line_chart,
279
         'line_chart': line_chart,
261
         'best_chart': best_chart,
280
         'best_chart': best_chart,
281
+        'likers_chart': likers_chart,
282
+        'likees_chart': likees_chart,
283
+        'hashtags_chart': hashtags_chart,
262
         'activity_chart': activity_chart,
284
         'activity_chart': activity_chart,
263
         'noTimeline': noTimeline,
285
         'noTimeline': noTimeline,
264
-        'noGraph': noGraph,
265
         'noBestSeum': noBestSeum,
286
         'noBestSeum': noBestSeum,
287
+        'noBestLikers': noBestLikers,
288
+        'noBestLikees': noBestLikees,
289
+        'noBestHashtags': noBestHashtags,
266
         'noSeumActivity': noSeumActivity,
290
         'noSeumActivity': noSeumActivity,
267
         'myCounter': myCounter,
291
         'myCounter': myCounter,
268
     })
292
     })