|
|
@@ -20,8 +20,6 @@ import functools
|
|
20
|
20
|
from django.utils import timezone
|
|
21
|
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
|
23
|
# Number of counters displayed on the home page's best seumeurs graph
|
|
26
|
24
|
bestSeumeursNumber = 15
|
|
27
|
25
|
|
|
|
@@ -29,7 +27,6 @@ bestSeumeursNumber = 15
|
|
29
|
27
|
@login_required
|
|
30
|
28
|
def home(request):
|
|
31
|
29
|
# Used later to keep track of the maximum JSS
|
|
32
|
|
- maxJSS = 0
|
|
33
|
30
|
lastResets = []
|
|
34
|
31
|
no_seum_delta = timedelta.max
|
|
35
|
32
|
|
|
|
@@ -89,21 +86,6 @@ def home(request):
|
|
89
|
86
|
counter.lastReset.noSeum = False
|
|
90
|
87
|
counter.lastReset.delta = datetime.now(
|
|
91
|
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
|
89
|
# Defining CSS attributes for the counter
|
|
108
|
90
|
if counter.id == myCounter.id:
|
|
109
|
91
|
counter.CSSclass = 'primary'
|
|
|
@@ -126,10 +108,8 @@ def home(request):
|
|
126
|
108
|
|
|
127
|
109
|
if myCounter.sort_by_score:
|
|
128
|
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
|
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
|
113
|
# The counters with no seum have a like count of -1 by convention
|
|
134
|
114
|
counters = sorted(counters, key=lambda t: - (
|
|
135
|
115
|
math.log(t.likeCount + 2) /
|
|
|
@@ -139,29 +119,6 @@ def home(request):
|
|
139
|
119
|
counters = sorted(counters, key=lambda t: +
|
|
140
|
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
|
122
|
# Timeline graph
|
|
166
|
123
|
resets = Reset.objects.filter(
|
|
167
|
124
|
timestamp__gte=timezone.now() - timedelta(days=1))
|
|
|
@@ -253,16 +210,83 @@ def home(request):
|
|
253
|
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
|
276
|
# At last we render the page
|
|
257
|
277
|
return render(request, 'homeTemplate.html', {
|
|
258
|
278
|
'counters': counters,
|
|
259
|
|
- 'col_chart': col_chart,
|
|
260
|
279
|
'line_chart': line_chart,
|
|
261
|
280
|
'best_chart': best_chart,
|
|
|
281
|
+ 'likers_chart': likers_chart,
|
|
|
282
|
+ 'likees_chart': likees_chart,
|
|
|
283
|
+ 'hashtags_chart': hashtags_chart,
|
|
262
|
284
|
'activity_chart': activity_chart,
|
|
263
|
285
|
'noTimeline': noTimeline,
|
|
264
|
|
- 'noGraph': noGraph,
|
|
265
|
286
|
'noBestSeum': noBestSeum,
|
|
|
287
|
+ 'noBestLikers': noBestLikers,
|
|
|
288
|
+ 'noBestLikees': noBestLikees,
|
|
|
289
|
+ 'noBestHashtags': noBestHashtags,
|
|
266
|
290
|
'noSeumActivity': noSeumActivity,
|
|
267
|
291
|
'myCounter': myCounter,
|
|
268
|
292
|
})
|