|
|
@@ -16,8 +16,9 @@ class resetCounterForm(forms.ModelForm):
|
|
16
|
16
|
model = Reset
|
|
17
|
17
|
fields = ['reason','counter']
|
|
18
|
18
|
|
|
19
|
|
-# Create your views here.
|
|
20
|
19
|
def home(request):
|
|
|
20
|
+ #JSS above this limit will not be displayed on the col graph
|
|
|
21
|
+ JSS_limit = 7
|
|
21
|
22
|
#Display counters
|
|
22
|
23
|
counters = Counter.objects.all()
|
|
23
|
24
|
lastResets = []
|
|
|
@@ -30,41 +31,83 @@ def home(request):
|
|
30
|
31
|
counter.lastReset = Reset()
|
|
31
|
32
|
counter.lastReset.delta = timezero
|
|
32
|
33
|
counter.lastReset.noSeum = True
|
|
|
34
|
+ counter.CSSclass = "warning"
|
|
33
|
35
|
else:
|
|
34
|
36
|
counter.lastReset = lastReset[0]
|
|
35
|
37
|
counter.lastReset.noSeum = False
|
|
36
|
38
|
counter.lastReset.delta = datetime.now()-counter.lastReset.timestamp.replace(tzinfo=None)
|
|
37
|
|
- lastResets.append([counter.trigramme,{'v' : (counter.lastReset.delta.total_seconds())/(24*3600), 'f' : str(round((counter.lastReset.delta.total_seconds())/(24*3600),1))} ])
|
|
38
|
|
- if (counter.lastReset.delta.total_seconds())/(24*3600) > maxJSS:
|
|
39
|
|
- maxJSS = (counter.lastReset.delta.total_seconds())/(24*3600)
|
|
40
|
|
- counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr',threshold=1)
|
|
|
39
|
+ if ((counter.lastReset.delta.total_seconds())/(24*3600)<JSS_limit):
|
|
|
40
|
+ #If more thant 7 JSS do not display on graph
|
|
|
41
|
+ lastResets.append([counter.trigramme,{'v' : (counter.lastReset.delta.total_seconds())/(24*3600), 'f' : str(round((counter.lastReset.delta.total_seconds())/(24*3600),1))} ])
|
|
|
42
|
+ counter.CSSclass = "primary"
|
|
|
43
|
+ if (counter.lastReset.delta.total_seconds())/(24*3600) > maxJSS:
|
|
|
44
|
+ maxJSS = (counter.lastReset.delta.total_seconds())/(24*3600)
|
|
|
45
|
+ counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr',threshold=1)
|
|
|
46
|
+ else:
|
|
|
47
|
+ counter.CSSclass = "danger"
|
|
41
|
48
|
counter.isHidden = "hidden"
|
|
42
|
|
- counters = sorted(counters,key=lambda t: -t.lastReset.delta)
|
|
|
49
|
+ counters = sorted(counters,key=lambda t: t.lastReset.delta)
|
|
43
|
50
|
#Column graph
|
|
44
|
|
- lastResets.sort(key=lambda x: x[1]['v'])
|
|
45
|
|
- lastResets.insert(0,['Trigramme','Jours sans seum'])
|
|
46
|
|
- col_data = SimpleDataSource(lastResets)
|
|
47
|
|
- col_chart = gchart.ColumnChart(col_data,options={'title' : '', 'legend' : 'none','vAxis' : { 'viewWindow' : { 'max' : max(maxJSS,1) , 'min' : 0} , 'ticks' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],'title' : 'Jours sans seum' }, 'hAxis' : {'title' : 'Trigramme' }})
|
|
|
51
|
+ if (len(lastResets) ==0):
|
|
|
52
|
+ noGraph = True
|
|
|
53
|
+ col_chart = None
|
|
|
54
|
+ else:
|
|
|
55
|
+ noGraph = False
|
|
|
56
|
+ lastResets.sort(key=lambda x: x[1]['v'])
|
|
|
57
|
+ lastResets.insert(0,['Trigramme','Jours sans seum'])
|
|
|
58
|
+ col_data = SimpleDataSource(lastResets)
|
|
|
59
|
+ col_chart = gchart.ColumnChart(col_data,options={
|
|
|
60
|
+ 'title' : '',
|
|
|
61
|
+ 'legend' : 'none',
|
|
|
62
|
+ 'vAxis' : {
|
|
|
63
|
+ 'viewWindow' : {
|
|
|
64
|
+ 'max' : max(maxJSS,1) ,
|
|
|
65
|
+ 'min' : 0
|
|
|
66
|
+ },
|
|
|
67
|
+ 'ticks' : [1,2,3,4,5,6,7],
|
|
|
68
|
+ 'title' : 'Jours sans seum'
|
|
|
69
|
+ },
|
|
|
70
|
+ 'hAxis' : {'title' : 'Trigramme' },
|
|
|
71
|
+ })
|
|
48
|
72
|
|
|
49
|
73
|
###Timeline graph
|
|
50
|
74
|
#Data pre-processing
|
|
51
|
75
|
resets = Reset.objects.filter(timestamp__gte=timezone.now() - timedelta(days=1))
|
|
52
|
|
- for reset in resets:
|
|
53
|
|
- reset.timestamp={'v' : reset.timestamp.timestamp(), 'f' : "Il y a "+format_timedelta(datetime.now()-reset.timestamp.replace(tzinfo=None),locale='fr',threshold=1) }
|
|
54
|
|
- reset.Seum={'v' : 0, 'f' : reset.counter.trigramme+" : "+reset.reason}
|
|
55
|
|
- #Drawing the graph
|
|
56
|
|
- line_data = ModelDataSource(resets,fields=['timestamp','Seum'])
|
|
57
|
|
- line_chart = gchart.LineChart(line_data, options={
|
|
58
|
|
- 'lineWidth' : 0,
|
|
59
|
|
- 'pointSize' : 10,
|
|
60
|
|
- 'title' : '',
|
|
61
|
|
- 'vAxis' : { 'ticks' : []},
|
|
62
|
|
- 'hAxis' : {'ticks' : [{'v' : (datetime.now() - timedelta(days=1)).timestamp(), 'f' : 'Il y a 24 h' }, { 'v' :datetime.now().timestamp(), 'f' : 'Présent'}]},
|
|
63
|
|
- 'legend' : 'none',
|
|
64
|
|
- 'height' : 90
|
|
65
|
|
- })
|
|
|
76
|
+ if (resets.count() == 0):
|
|
|
77
|
+ noTimeline = True
|
|
|
78
|
+ line_chart = None
|
|
|
79
|
+ else:
|
|
|
80
|
+ noTimeline = False
|
|
|
81
|
+ for reset in resets:
|
|
|
82
|
+ reset.timestamp={
|
|
|
83
|
+ 'v' : reset.timestamp.timestamp(),
|
|
|
84
|
+ 'f' : "Il y a "+format_timedelta(datetime.now()-reset.timestamp.replace(tzinfo=None),locale='fr',threshold=1)
|
|
|
85
|
+ }
|
|
|
86
|
+ reset.Seum={'v' : 0, 'f' : reset.counter.trigramme+" : "+reset.reason}
|
|
|
87
|
+ #Drawing the graph
|
|
|
88
|
+ line_data = ModelDataSource(resets,fields=['timestamp','Seum'])
|
|
|
89
|
+ line_chart = gchart.LineChart(line_data, options={
|
|
|
90
|
+ 'lineWidth' : 0,
|
|
|
91
|
+ 'pointSize' : 10,
|
|
|
92
|
+ 'title' : '',
|
|
|
93
|
+ 'vAxis' : { 'ticks' : []},
|
|
|
94
|
+ 'hAxis' : {
|
|
|
95
|
+ 'ticks' : [
|
|
|
96
|
+ {'v' : (datetime.now() - timedelta(days=1)).timestamp(), 'f' : 'Il y a 24 h' },
|
|
|
97
|
+ { 'v' :datetime.now().timestamp(), 'f' : 'Présent'}
|
|
|
98
|
+ ]
|
|
|
99
|
+ },
|
|
|
100
|
+ 'legend' : 'none',
|
|
|
101
|
+ 'height' : 90
|
|
|
102
|
+ })
|
|
66
|
103
|
|
|
67
|
|
- return render(request,'homeTemplate.html', {'counters' : counters, 'col_chart' : col_chart, 'line_chart' : line_chart})
|
|
|
104
|
+ return render(request,'homeTemplate.html', {
|
|
|
105
|
+ 'counters' : counters,
|
|
|
106
|
+ 'col_chart' : col_chart,
|
|
|
107
|
+ 'line_chart' : line_chart,
|
|
|
108
|
+ 'noTimeline' : noTimeline,
|
|
|
109
|
+ 'noGraph' : noGraph
|
|
|
110
|
+ })
|
|
68
|
111
|
|
|
69
|
112
|
def resetCounter(request):
|
|
70
|
113
|
#Update Form counter
|