-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdashboard.html
859 lines (802 loc) · 23.7 KB
/
dashboard.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<meta name="mobile-web-app-capable" content="yes">
<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="width" />
<title>Tracktime Dashboard</title>
<style>
html, body {
height: 100%;
margin: 0;
}
body {
color: #333;
font-family: 'Unicode Sans','Lucida Sans Unicode',Helvetica,Arial,Verdana,sans-serif;
font-size: 13px;
padding: 1em;
text-align: center;
}
header, section {
background-color: #EEF;
background: linear-gradient(to bottom, #DDF 0%, #EEF 100%);
background: -moz-linear-gradient(top, #EEF 0%, #DDF 100%);
background: -moz-linear-gradient(top, #EEF 0%, #DDF 100%);
background: -ms-linear-gradient(top, #EEF 0%, #DDF 100%);
background: -o-linear-gradient(top, #EEF 0%, #DDF 100%);
background: -webkit-linear-gradient(top, #EEF 0%, #DDF 100%);
color: #000;
border: 2px outset #EEF;
border-radius: 4px;
box-shadow: -2px 3px 4px rgba(153, 153, 102, 0.5);
display: block;
margin: 0;
position: absolute;
}
header {
height: 25px;
left: 1%;
padding: 0;
right: 1%;
top: 10px;
}
header button, header input, header select {
position: absolute;
top: 1px;
}
header #prev {
left: 3px;
}
header #next {
right: 3px;
}
#from {
font-family: 'Unicode Sans','Lucida Sans Unicode',Helvetica,Arial,Verdana,sans-serif;
left: 33px;
width: 15em;
}
/*
#search {
left: 170px;
}
#ratinglimit {
left: 290px;
}
*/
#to {
font-family: 'Unicode Sans','Lucida Sans Unicode',Helvetica,Arial,Verdana,sans-serif;
right: 33px;
width: 15em;
}
h1 {
font-size: 13px;
line-height: 1;
}
h1 a, h1 a:visited {
color: #000;
font-size: smaller;
font-weight: normal;
margin-left: 2em;
}
section {
padding: 4px;
}
#pie {
bottom: 75%;
left: 1%;
right: 72%;
top: 48px;
}
#pie2 {
bottom: 75%;
left: 29%;
right: 44%;
top: 48px;
}
#pie3 {
bottom: 75%;
left: 57%;
right: 16%;
top: 48px;
}
#gauge {
bottom: 75%;
left: 85%;
right: 1%;
top: 48px;
}
#area {
bottom: 160px;
left: 95%;
right: 1%;
top: 26%;
}
#bars {
bottom: 160px;
left: 1%;
right: 6%;
top: 26%;
}
/*
#area, #bars {
transition: all 0 1s;
}
*/
#timeline {
bottom: 4px;
height: 133px;
left: 1%;
right: 1%;
}
</style>
</head>
<body>
<header><button id="prev">◀</button><input id="from" type="datetime-local" step="600" /><!-- <input id="search" type="text" size="14" /><select id="ratinglimit"><option value="">All</option><option value="1">1</option><option value="1 2">1 or 2</option><option value="2 3 4">2 - 4</option><option value="4 5">4 or 5</option><option value="5">5</option></select> --><h1>Tracktime Dashboard</h1><input id="to" type="datetime-local" step="600" /><button id="next">▶</button></header>
<section id="pie">Pie chart loading...</section>
<section id="pie2">Pie chart loading...</section>
<section id="pie3">Pie chart loading...</section>
<section id="gauge">Gauge loading...</section>
<section id="area"></section>
<section id="bars">Bar chart loading...</section>
<section id="timeline">Timeline loading...</section>
<!-- script src="//www.google.com/jsapi"></script -->
<script src="//www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', {packages: ['corechart',
'gauge',
'timeline']});
</script>
<script>
var GET_URI = './get.php';
var MAX_ROWS = 150;
var fts = 11;
var lfs = 12;
var animOpts = {'easing': 'in', 'duration': 500};
var stateStatus;
var globalStart, globalEnd;
var zoomLevel = 3;
var xhr = new XMLHttpRequest();
xhr.onload = update;
const params = new URLSearchParams(document.location.search)
let subject = params.get('subject') || ''
var pb = document.getElementById('prev');
pb.onclick = showprev;
var nb = document.getElementById('next');
nb.onclick = shownext;
var fi = document.getElementById('from');
var ti = document.getElementById('to');
fi.onchange = ti.onchange = function() {
globalStart = toDate(fi.value);
globalEnd = toDate(ti.value);
getInterval();
}
var h1 = document.querySelector('h1');
var a = document.createElement('a');
a.href = '/?subject=' + encodeURIComponent(subject); // index.html
a.className = 'eventslink';
a.textContent = 'All events';
a.onclick = function(e) {
this.href += '&starttime=' + encodeURIComponent(fi.value) +
'&endtime=' + encodeURIComponent(ti.value);
}
h1.appendChild(a);
var labels = {};
labels['01'] = 'Sleep';
labels['02'] = 'Eating';
labels['03'] = 'Other personal care';
labels[11] = 'Main job and second job';
labels[12] = 'Activities related to employment';
labels[21] = 'School and university';
labels[22] = 'Free time study';
labels[30] = 'Unspecified household and family care';
labels[31] = 'Food management';
labels[32] = 'Household upkeep';
labels[33] = 'Care for textiles';
labels[34] = 'Gardening and pet care';
labels[35] = 'Construction and repairs';
labels[36] = 'Shopping and services';
labels[37] = 'Household management';
labels[38] = 'Childcare';
labels[39] = 'Help to an adult household member';
labels[41] = 'Organisational work';
labels[42] = 'Informal help to other households';
labels[27] = 'Participatory and religious activities';
labels[51] = 'Social life';
labels[52] = 'Entertainment and culture';
labels[53] = 'Resting - time out';
labels[61] = 'Physical excercise';
labels[62] = 'Productive excercise';
labels[63] = 'Sports related activities';
labels[71] = 'Arts and hobbies';
labels[72] = 'Computing';
labels[73] = 'Games';
labels[81] = 'Reading';
labels[82] = 'TV, video and DVD';
labels[83] = 'Radio and recordings';
labels[91] = 'Travel to/from work';
labels[92] = 'Travel related to study';
labels[93] = 'Travel r. to shopping, services, childcare &c.';
labels[94] = 'Travel related to voluntary work and meetings';
labels[95] = 'Travel related to social life';
labels[96] = 'Travel related to other leisure';
labels[98] = 'Travel related to changing locality';
labels[90] = 'Other or unspecified travel purpose';
labels[99] = 'Other unspecified time use';
var clabels = [
'Personal care',
'Employment',
'Study',
'Household and family care',
'Voluntary work and meetings',
'Social life and entertainment',
'Sports and outdoor activities',
'Hobbies',
'Mass media',
'Travel by purpose',
'Unspecified'
];
var cats = {};
Object.keys(labels).forEach(function(key) {
var i = parseInt(key);
if (i<=10) {
cats[key] = clabels[0];
}
else if (i<=20) {
cats[key] = clabels[1];
}
else if (i<=30) {
cats[key] = clabels[2];
}
else if (i<=40) {
cats[key] = clabels[3];
}
else if (i<=50) {
cats[key] = clabels[4];
}
else if (i<=60) {
cats[key] = clabels[5];
}
else if (i<=70) {
cats[key] = clabels[6];
}
else if (i<=80) {
cats[key] = clabels[7];
}
else if (i<=90) {
cats[key] = clabels[8];
}
else if (i<=99) {
cats[key] = clabels[9];
}
else {
cats[key] = clabels[10];
}
});
var ad = document.getElementById('area');
var aopts = {'backgroundColor': 'transparent', 'orientation': 'horizontal',
'isStacked': true, 'legend': {'position': 'none'},
'animation': animOpts, 'theme': 'maximized',
'vAxis': {'title': '%', 'viewWindowMode': 'maximized'},
'hAxis': {'showTextEvery': 24}, 'areaOpacity': 1,
'focusTarget': 'category',
'lineWidth': 0,
};
var adata = [];
var arows = {};
var bd = document.getElementById('bars');
var bopts = {'backgroundColor': 'transparent', 'orientation': 'horizontal',
'isStacked': true, 'legend': {'position': 'none'},
'animation': animOpts,
'vAxis': { title: "hours"},
'charArea': {'left': 0, 'top': 0, 'width': '100%', 'height': '100%'},
};
var bdata = [];
var brows = {};
ad.addEventListener('click', toggleBars, true);
bd.addEventListener('dblclick', zoomColumns, true);
var td = document.getElementById('timeline');
var topts = {'backgroundColor': 'transparent',
'timeline': {'colorByRowLabel': true,
'barLabelStyle': {'fontSize': fts}}};
var tdata = [];
var gd = document.getElementById('gauge');
var gopts = {'min': 1, 'max': 5,
'redFrom': 1, 'redTo': 2,
'yellowFrom': '2', 'yellowTo': 4,
'greenFrom': 4, 'greenTo': 5,
'width': gd.clientWidth,
'height': gd.clientHeight,
'animation': animOpts,
'majorTicks': ['1', '2', '3', '4', '5']};
var gdata = [];
var rattime = 0;
var ratvalue = 0;
var wlabels = [];
wlabels[1] = 'Alone';
wlabels[2] = 'Partner';
wlabels[3] = 'Parent';
wlabels[4] = 'Kids';
wlabels[5] = 'Family';
wlabels[6] = 'Others';
var pd = document.getElementById('pie');
setLegendStyle();
/*
var popts = {'pieHole': 0.4,
'backgroundColor': 'transparent',
'pieSliceTextStyle': {'color': '#000', 'fontSize': fts},
'chartArea': {'left': '5%', 'top': '5%',
'width': '90%', 'height': '90%'},
'animation': animOpts,
'legend': legendStyle};
*/
var popts = {'backgroundColor': 'transparent', 'orientation': 'horizontal',
'legend': {'position': 'none'},
'animation': animOpts,
'charArea': {'left': 0, 'top': 0, 'width': '100%', 'height': '100%'},
};
var pdata = [];
var prows = [];
var p2d = document.getElementById('pie2');
var p2opts = {'pieHole': 0.4,
'backgroundColor': 'transparent',
'pieSliceTextStyle': {'color': '#000', 'fontSize': fts},
'chartArea': {'left': '5%', 'top': '5%',
'width': '90%', 'height': '90%'},
'animation': animOpts,
'legend': legendStyle};
var p2data = [];
var llabels = [];
llabels[11] = 'At home';
llabels[12] = 'At other home';
llabels[13] = 'At work';
llabels[14] = 'At other\'s home';
llabels[15] = 'At restaurant';
llabels[16] = 'At shop';
llabels[17] = 'At hotel';
llabels[19] = 'At other';
llabels[21] = 'By foot';
llabels[22] = 'By bicycle';
llabels[23] = 'By motorbike';
llabels[24] = 'By car';
llabels[29] = 'By other';
llabels[31] = 'By public transport';
var p3d = document.getElementById('pie3');
var p3opts = {'pieHole': 0.4,
'backgroundColor': 'transparent',
'pieSliceTextStyle': {'color': '#000', 'fontSize': fts},
'chartArea': {'left': '5%', 'top': '5%',
'width': '90%', 'height': '90%'},
'animation': animOpts,
'legend': legendStyle};
var p3data = [];
var lrows = {};
google.setOnLoadCallback(init);
window.addEventListener('resize', resizeHandler, true);
window.addEventListener('hashchange', restoreState);
var a, b, g, p, p2, p3, t;
function init() {
a = new google.visualization.AreaChart(ad);
b = new google.visualization.ColumnChart(bd);
t = new google.visualization.Timeline(td);
g = new google.visualization.Gauge(gd);
// p = new google.visualization.PieChart(pd);
p = new google.visualization.ColumnChart(pd);
p2 = new google.visualization.PieChart(p2d);
p3 = new google.visualization.PieChart(p3d);
google.visualization.events.addListener(b, 'onmouseover', function(e) {
if (e['column']-1 < p2data.getNumberOfRows()) {
p2.setSelection([{'row': e['column']-1, 'column': null}]);
}
else{
// console.log(e);
}
});
google.visualization.events.addListener(b, 'onmouseout', function(e) {
p2.setSelection([{'row': null, 'column': null}]);
});
// not working yet...
google.visualization.events.addListener(p2, 'onmouseover', function(e) {
b.setSelection([{'row': null, 'column': e['row']+1}]);
});
google.visualization.events.addListener(p2, 'onmouseout', function(e) {
b.setSelection([{'row': null, 'column': null}]);
});
bdata = new google.visualization.DataTable();
bdata.addColumn({'type': 'string', 'id': 'Type'});
for (var i=0; i<clabels.length; i++) {
bdata.addColumn('number', clabels[i]);
}
adata = new google.visualization.DataTable();
adata.addColumn({'type': 'string', 'id': 'Time'});
for (var i=0; i<clabels.length; i++) {
adata.addColumn('number', clabels[i]);
}
adata.addColumn({'type': 'string', 'role': 'Annotation'});
tdata = new google.visualization.DataTable();
tdata.addColumn({'type': 'string', 'id': 'Action type'});
tdata.addColumn({'type': 'string', 'id': 'Description'});
tdata.addColumn({'type': 'date', 'id': 'Start'});
tdata.addColumn({'type': 'date', 'id': 'End'});
gdata = new google.visualization.DataTable();
gdata.addColumn({'type': 'string', 'id': 'Label'});
gdata.addColumn({'type': 'number', 'id': 'Value'});
pdata = new google.visualization.DataTable();
pdata.addColumn({'type': 'string', 'id': 'With'});
pdata.addColumn({'type': 'number', 'id': 'Duration'});
p2data = new google.visualization.DataTable();
p2data.addColumn({'type': 'string', 'id': 'Action'});
p2data.addColumn({'type': 'number', 'id': 'Duration'});
p3data = new google.visualization.DataTable();
p3data.addColumn({'type': 'string', 'id': 'Location'});
p3data.addColumn({'type': 'number', 'id': 'Duration'});
var dateRegex = '(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{0,2})'
var m;
if (m = document.location.hash.match('#'+dateRegex+','+dateRegex)) {
// console.log(m);
globalStart = new Date(m[1]);
globalEnd = new Date(m[2]);
}
else {
var d = new Date();
globalStart = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 4);
if (d.getHours() <= 5) {
globalStart = new Date(globalStart.getTime() - 24 * 60 * 60 * 1000);
}
globalEnd = new Date(globalStart.getTime() + 24 * 60 * 60 * 1000);
}
getInterval();
}
function showprev() {
var diff = globalEnd.getTime() - globalStart.getTime();
globalStart = new Date(globalStart.getTime() - diff);
globalEnd = new Date(globalEnd.getTime() - diff);
getInterval();
}
function shownext() {
var diff = globalEnd.getTime() - globalStart.getTime();
globalStart = new Date(globalStart.getTime() + diff);
globalEnd = new Date(globalEnd.getTime() + diff);
getInterval();
}
function setLegendStyle() {
legendStyle = {'position': 'left', 'textStyle': {'fontSize': lfs}};
if ((pd.offsetWidth < 220) || (pd.offsetHeight < 130)) {
legendStyle['position'] = 'none';
return;
}
if ((pd.offsetWidth < 240) || (pd.offsetHeight < 140)) {
legendStyle['textStyle']['fontSize'] = 8;
return;
}
if ((pd.offsetWidth < 260) || (pd.offsetHeight < 150)) {
legendStyle['textStyle']['fontSize'] = 9;
return;
}
if ((pd.offsetWidth < 280) || (pd.offsetHeight < 160)) {
legendStyle['textStyle']['fontSize'] = 10;
return;
}
if ((pd.offsetWidth < 300) || (pd.offsetHeight < 170)) {
legendStyle['textStyle']['fontSize'] = 11;
return;
}
if ((pd.offsetWidth < 320) || (pd.offsetHeight < 180)) {
legendStyle['textStyle']['fontSize'] = 12;
return;
}
if ((pd.offsetWidth < 340) || (pd.offsetHeight < 190)) {
legendStyle['textStyle']['fontSize'] = 13;
return;
}
if ((pd.offsetWidth < 360) || (pd.offsetHeight < 200)) {
legendStyle['textStyle']['fontSize'] = 14;
return;
}
if ((pd.offsetWidth < 380) || (pd.offsetHeight < 210)) {
legendStyle['textStyle']['fontSize'] = 15;
return;
}
}
function toggleBars() {
if (!ad.style.left || (ad.style.left == '95%')) {
ad.style.left = '6%';
bd.style.right = '95%';
ad.removeEventListener('click', toggleBars, true);
bd.addEventListener('click', toggleBars, true);
b.clearChart();
}
else {
ad.style.left = '95%';
bd.style.right = '6%';
bd.removeEventListener('click', toggleBars, true);
ad.addEventListener('click', toggleBars, true);
a.clearChart();
}
showBars();
}
function zoomColumns() {
zoomLevel += 2;
if (zoomLevel > 16) {
zoomLevel = 3;
}
var maxBarHeight = (globalEnd - globalStart) / 1000 / 60 / 60 / zoomLevel;
bopts['vAxis']['viewWindowMode'] = 'explicit';
bopts['vAxis']['viewWindow'] = {'max': maxBarHeight, 'min': 0};
b.draw(bdata, bopts);
}
function showBars() {
if (!ad.style.left || (ad.style.left == '95%')) {
bopts['width'] = bd.clientWidth;
bopts['height'] = bd.clientHeight;
b.draw(bdata, bopts);
ad.textContent = 'Show area';
}
else {
aopts['width'] = ad.clientWidth;
aopts['height'] = ad.clientHeight;
a.draw(adata, aopts);
bd.textContent = 'Show bars';
// WTF: chart gives an error every second time it is drawn!
// Ugly ugly fix: if chart is empty, toggle twice... :-(
if (ad.getElementsByTagName('svg').length < 1) {
toggleBars();
toggleBars();
}
}
}
function resizeHandler() {
setLegendStyle();
topts['width'] = td.clientWidth;
topts['height'] = td.clientHeight;
t.draw(tdata, topts);
gopts['width'] = gd.clientWidth;
gopts['height'] = gd.clientHeight;
g.draw(gdata, gopts);
popts['width'] = pd.clientWidth;
popts['height'] = pd.clientHeight;
popts['legend'] = legendStyle;
p.draw(pdata, popts);
p2opts['width'] = p2d.clientWidth;
p2opts['height'] = p2d.clientHeight;
p2opts['legend'] = legendStyle;
p2.draw(p2data, p2opts);
p3opts['width'] = p3d.clientWidth;
p3opts['height'] = p3d.clientHeight;
p3opts['legend'] = legendStyle;
p3.draw(p3data, p3opts);
showBars();
}
function restoreState(e) {
var match;
if (e.newURL && (match = new String(e.newURL).match(/([\d\s:-]+),([\d\s:-]+)$/))) {
fi.value = match[1];
ti.value = match[2];
ti.onchange();
stateStatus = 'pop';
}
}
function getInterval() {
fi.value = toString(globalStart);
ti.value = toString(globalEnd);
var state = {'from': fi.value, 'to': ti.value};
var newTitle = fi.value + ' - '+ ti.value;
var url = new String(document.location).replace(/#.+$/, '') +
'#' + fi.value + ',' + ti.value;
if ((stateStatus == 'wait') || !history.replaceState) {
history.pushState(state, newTitle, url);
}
else {
history.replaceState(state, newTitle, url);
}
document.title = newTitle;
stateStatus = 'wait';
xhr.abort();
var href = GET_URI + '?subject=' + encodeURIComponent(subject) +
'&starttime=' + Math.round(globalStart.getTime()/1000) +
'&endtime=' + Math.round(globalEnd.getTime()/1000);
xhr.open('GET', href, true);
xhr.send(null);
var maxBarHeight = (globalEnd - globalStart) / 1000 / 60 / 60 / zoomLevel;
bopts['vAxis']['viewWindowMode'] = 'explicit';
bopts['vAxis']['viewWindow'] = {'max': maxBarHeight, 'min': 0};
}
function update() {
var values = JSON.parse(this.responseText);
if (!values.length) {
var message = 'No data between ' + toString(globalStart) + ' and ' + toString(globalEnd);
ad.textContent = message;
bd.textContent = message;
gd.textContent = message;
td.textContent = message;
pd.textContent = message;
p2d.textContent = message;
p3d.textContent = message;
return false;
}
bdata.removeRows(0, bdata.getNumberOfRows());
adata.removeRows(0, adata.getNumberOfRows());
tdata.removeRows(0, tdata.getNumberOfRows());
gdata.removeRows(0, gdata.getNumberOfRows());
pdata.removeRows(0, pdata.getNumberOfRows());
p2data.removeRows(0, p2data.getNumberOfRows());
p3data.removeRows(0, p3data.getNumberOfRows());
ratvalue = 0;
rattime = 0;
prows = [0, 0, 0, 0, 0, 0, 0];
lrows = {};
brows = {};
arows = {};
var currEnd = '';
for (var i=values.length-1; i>=0; i--) {
if (currEnd && (values[i]['starttime'] > currEnd)) {
var tmp = {'starttime': currEnd,
'endtime': values[i]['starttime'],
'mainaction': 99,
'rating': 0,
'with': 0};
addData(tmp);
}
addData(values[i]);
currEnd = values[i]['endtime'];
}
var total = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
Object.keys(labels).sort().forEach(function(key) {
if (!brows[key]) {
return;
}
var tmp = [labels[key]];
for (var k=0; k<clabels.length; k++) {
if (cats[key] == clabels[k]) {
tmp.push(Math.round(brows[key]/6)/10);
total[k] += brows[key];
}
else {
tmp.push(0);
}
}
bdata.addRow(tmp);
});
for (var i=0; i<total.length; i++) {
p2data.addRow([clabels[i], Math.round(total[i]/6)/10]);
}
p2.draw(p2data, p2opts);
for (var i in lrows) {
p3data.addRow([llabels[i], Math.round(lrows[i]/6)/10]);
}
p3.draw(p3data, p3opts);
for (var i=1; i<wlabels.length; i++) {
if (!wlabels[i] || !prows[i]) {
continue;
}
pdata.addRow([wlabels[i], Math.round(prows[i]/6)/10]);
}
p.draw(pdata, popts);
t.draw(tdata, topts);
gdata.addRow(['Rating', rattime ? Math.round(ratvalue/rattime*100)/100 : 0]);
g.draw(gdata, gopts);
var minutes = 24 * 60;
for (var i=0; i<minutes; i+=10) {
var d = new Date(0, 0, 0, 4, i, 0);
var tkey = pad(d.getHours()) + ':' + pad(d.getMinutes());
if (!arows[tkey]) {
continue;
}
var tmp = [tkey];
for (var j=0; j<clabels.length; j++) {
var cl = clabels[j];
if (arows[tkey] && arows[tkey][cl] && arows[tkey]['total']) {
tmp.push(Math.round(10000*arows[tkey][cl]/arows[tkey]['total'])/100);
}
else {
tmp.push(0);
}
}
tmp.push(tkey);
adata.addRow(tmp);
}
showBars();
}
function addData(values) {
var st = toDate(values['starttime']);
st = (st >= globalStart) ? st : globalStart;
var et = toDate(values['endtime']);
et = (et <= globalEnd) ? et : globalEnd;
var duration = (et - st)/(60 * 1000);
var desc = '';
var ma = values['mainaction'];
if (values['description']) {
desc += ' (' + values['description'] + ')';
}
if (values['with'] == 1) {
desc += ' ' + wlabels[1].toLowerCase();
prows[1] += duration;
}
else {
var company = [];
for (var i=1; i<wlabels.length; i++) {
if (parseInt(values['with']) & Math.pow(2, (i-1))) {
company.push(wlabels[i].toLowerCase());
prows[i] += duration;
}
}
if (company.length > 0) {
desc += ' with ' + company.join(', ');
}
}
if (values['location']) {
if (!lrows[values['location']]) {
lrows[values['location']] = 0;
}
lrows[values['location']] += duration;
if (llabels[values['location']]) {
desc += ' ' + llabels[values['location']].toLowerCase();
}
}
if (values['rating']) {
var rv = parseInt(values['rating']);
desc += ' ' + new Array(rv+1).join('\u2605');
rattime += duration;
ratvalue += (duration * rv);
}
var act = ['Main action', labels[ma] + desc, st, et];
tdata.addRow(act);
if (!brows[ma]) {
brows[ma] = 0;
}
brows[ma] += duration;
if (values['sideaction']) {
act = ['Side action', labels[values['sideaction']] + desc, st, et];
tdata.addRow(act);
// if (!brows[values['sideaction']]) {
// brows[values['sideaction']] = 0;
// }
// brows[values['sideaction']] += duration;
}
var init = st.getTime();
var end = et.getTime();
var interval = 10 * 60 * 1000;
for (var t = init; t < end; t += interval) {
var d = new Date(t);
var tkey = pad(d.getHours()) + ':' + pad(d.getMinutes());
if (!arows[tkey]) {
arows[tkey] = {'total': 0};
}
if (!arows[tkey][cats[ma]]) {
arows[tkey][cats[ma]] = 0;
}
arows[tkey]['total'] += 10;
arows[tkey][cats[ma]] += 10;
}
}
function toDate(str) {
var dt;
if (str.indexOf('T') > 0) {
dt = str.split('T');
}
else {
dt = str.split(' ');
}
var d = dt[0].split('-');
var t = dt[1].split(':');
var date = new Date(d[0], d[1]-1, d[2], t[0], t[1]);
return date;
}
function toString(d) {
var str = d.getFullYear() + '-' +
pad(d.getMonth()+1) + '-' +
pad(d.getDate()) + 'T' +
pad(d.getHours()) + ':' +
pad(10*Math.floor(d.getMinutes()/10)) + ':00';
return str;
}
function pad(val) {
if (val < 10) {
return '0' + '' + val;
}
return val;
}
</script>
</body>
</html>