|
|
@@ -18,13 +18,16 @@ import math
|
|
18
|
18
|
import copy
|
|
19
|
19
|
from django.utils import timezone
|
|
20
|
20
|
|
|
|
21
|
+# JSS above this limit will not be displayed on the home page col graph
|
|
|
22
|
+JSS_limit = 7
|
|
|
23
|
+# Number of counters displayed on the home page's best seumeurs graph
|
|
|
24
|
+bestSeumeursNumber = 15
|
|
|
25
|
+
|
|
21
|
26
|
|
|
22
|
27
|
@login_required
|
|
23
|
28
|
def home(request):
|
|
24
|
|
- # JSS above this limit will not be displayed on the col graph
|
|
25
|
|
- JSS_limit = 7
|
|
|
29
|
+ # Used later to keep track of the maximum JSS
|
|
26
|
30
|
maxJSS = 0
|
|
27
|
|
- bestSeumeursNumber = 15
|
|
28
|
31
|
lastResets = []
|
|
29
|
32
|
no_seum_delta = timedelta.max
|
|
30
|
33
|
|
|
|
@@ -58,21 +61,23 @@ def home(request):
|
|
58
|
61
|
# Building data for counters display
|
|
59
|
62
|
counters = Counter.objects.all()
|
|
60
|
63
|
for counter in counters:
|
|
|
64
|
+ #Only the last reset is displayed
|
|
61
|
65
|
lastReset = Reset.objects.filter(
|
|
62
|
66
|
counter=counter).order_by('-timestamp')
|
|
63
|
|
- if (lastReset.count() == 0):
|
|
64
|
|
- # This person never had the seum
|
|
|
67
|
+ if (lastReset.count() == 0): # This person never had the seum
|
|
65
|
68
|
counter.lastReset = Reset()
|
|
66
|
69
|
counter.lastReset.delta = no_seum_delta
|
|
67
|
70
|
counter.lastReset.noSeum = True
|
|
68
|
71
|
counter.CSSclass = "warning"
|
|
69
|
|
- else:
|
|
|
72
|
+ else: # This person already had the seum
|
|
70
|
73
|
counter.lastReset = lastReset[0]
|
|
|
74
|
+ # To display the last seum we have to know if it is self-inflicted
|
|
71
|
75
|
if (counter.lastReset.who is None or
|
|
72
|
76
|
counter.lastReset.who.id == counter.id):
|
|
73
|
77
|
counter.lastReset.selfSeum = True
|
|
74
|
78
|
else:
|
|
75
|
79
|
counter.lastReset.selfSeum = False
|
|
|
80
|
+ # Now we compute the duration since the reset
|
|
76
|
81
|
counter.lastReset.noSeum = False
|
|
77
|
82
|
counter.lastReset.delta = datetime.now(
|
|
78
|
83
|
) - counter.lastReset.timestamp.replace(tzinfo=None)
|
|
|
@@ -102,7 +107,10 @@ def home(request):
|
|
102
|
107
|
counter.lastReset.formatted_delta = format_timedelta(
|
|
103
|
108
|
counter.lastReset.delta, locale='fr', threshold=1)
|
|
104
|
109
|
counter.isHidden = "hidden"
|
|
|
110
|
+
|
|
|
111
|
+ # Eventually we sort the counters to display the most recent resets top
|
|
105
|
112
|
counters = sorted(counters, key=lambda t: t.lastReset.delta)
|
|
|
113
|
+
|
|
106
|
114
|
# Column graph
|
|
107
|
115
|
if (len(lastResets) == 0):
|
|
108
|
116
|
noGraph = True
|
|
|
@@ -127,7 +135,6 @@ def home(request):
|
|
127
|
135
|
})
|
|
128
|
136
|
|
|
129
|
137
|
# Timeline graph
|
|
130
|
|
- # Data pre-processing
|
|
131
|
138
|
resets = Reset.objects.filter(
|
|
132
|
139
|
timestamp__gte=timezone.now() - timedelta(days=1))
|
|
133
|
140
|
if (resets.count() == 0):
|
|
|
@@ -153,7 +160,6 @@ def home(request):
|
|
153
|
160
|
'f': reset.who.trigramme + ' à ' +
|
|
154
|
161
|
reset.counter.trigramme +
|
|
155
|
162
|
" : " + reset.reason}
|
|
156
|
|
- # Drawing the graph
|
|
157
|
163
|
line_data = ModelDataSource(resets, fields=['timestamp', 'Seum'])
|
|
158
|
164
|
line_chart = gchart.LineChart(line_data, options={
|
|
159
|
165
|
'lineWidth': 0,
|
|
|
@@ -219,6 +225,7 @@ def home(request):
|
|
219
|
225
|
'hAxis': {'title': 'Mois'},
|
|
220
|
226
|
})
|
|
221
|
227
|
|
|
|
228
|
+ # At last we render the page
|
|
222
|
229
|
return render(request, 'homeTemplate.html', {
|
|
223
|
230
|
'counters': counters,
|
|
224
|
231
|
'col_chart': col_chart,
|