-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstatistics.html
More file actions
215 lines (176 loc) · 5.25 KB
/
statistics.html
File metadata and controls
215 lines (176 loc) · 5.25 KB
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
<!DOCTYPE html>
<html>
<head>
<title>User Statitics</title>
<script src="./moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
async function csvToJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length-1;i++){
var obj = {};
var currentline=lines[i].split(",");
for(var j=0;j<headers.length;j++){
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
//return result; //JavaScript object
return result;
}
var csvdata=[];var data=[];
var labels=[];
var myChart=null;
function renderChart(time_limit) {
var local_data=[];
var local_labels=[];
var index=-1;
var nowObj=new Date();
var now = new Date(nowObj.getTime() - (3600000* time_limit));
//console.log((3600000* time_limit));
//console.log("now:"+now);
console.log(moment("final record:"+labels[data.length-1]).toDate());
for(var i=data.length-1;i>=0;i--){//console.log("i,"+i);
if(moment(labels[i]).toDate().getTime()-now<=0)
{index=i+1;
console.log("break:"+i);
break;}}
if(i==-1) index=0;
local_labels=labels.slice(index, data.length);
local_data=data.slice(index, data.length);
if(myChart!=null)
{
myChart.data.labels=local_labels;
myChart.data.datasets[0].data=local_data;
myChart.options.title.text='Eye Blinks in the last '+time_limit+" Hour(s)";
myChart.update();
return;
}
var ctx = document.getElementById("myChart").getContext('2d');
myChart = new Chart(ctx, {
type: 'line',
data: {
labels: local_labels,
datasets: [{
label: 'Number of Eye Blinks',
data: local_data,
'ticks':{"source":"2019-02-02 17:43:27.828029"},
borderColor: "#80b6f4",
pointBorderColor: "#80b6f4",
pointBackgroundColor: "#80b6f4",
pointHoverBackgroundColor: "#80b6f4",
pointHoverBorderColor: "#80b6f4",
}]
},
options: {
responsive: true,
title:{
display:true,
text: 'Eye Blinks in the last '+time_limit+" Hour(s)",
},
scales: {
xAxes: [{
type: 'time',
time: {
displayFormats: {
quarter: 'MMM YYYY'
}
}
}]
}
}
});
}
window.onload=async function(){
const fs = require('fs');
await fs.readFile('engine/stats.csv', 'utf8', async function(err, contents) {
csvdata=await csvToJSON(contents);
console.log(csvdata);
for (var i = 0; i < csvdata.length; i++) {
data.push(csvdata[i].count);
labels.push(csvdata[i].time);
}
});
renderChart(0.5);
};
</script>
<style type="text/css">
.myButton {
-moz-box-shadow: 0px 0px 0px 0px #b5b5b5;
-webkit-box-shadow: 0px 0px 0px 0px #b5b5b5;
box-shadow: 0px 0px 0px 0px #b5b5b5;
background-color:#7ce699;
-moz-border-radius:8px;
-webkit-border-radius:8px;
border-radius:8px;
border:1px solid #ffffff;
display:inline-block;
cursor:pointer;
color:#000000;
font-family:Courier New;
font-size:15px;
padding:13px 40px;
text-decoration:none;
}
.myButton:hover {
background-color:#3ccefa;
}
.myButton:active {
position:relative;
top:1px;
}
body{
background: #93cede; /* Old browsers */
background: -moz-linear-gradient(-45deg, #93cede 0%, #75bdd1 41%, #84edb0 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(-45deg, #93cede 0%,#75bdd1 41%,#84edb0 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(135deg, #93cede 0%,#75bdd1 41%,#84edb0 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#93cede', endColorstr='#84edb0',GradientType=1 );
}
.content {
padding: 30px;
background: white;
width: 70%;
max-width: 900px;
min-width: 500px;
min-height: 500px;
text-align: center;
font-family: Helvetica, Arial, Sans-Serif;
overflow: auto;
}
.center{
position: fixed; /* or absolute */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.shadow{
-webkit-box-shadow: 0 8px 6px -6px black;
-moz-box-shadow: 0 8px 6px -6px black;
box-shadow: 0 8px 6px -6px black;
}
</style>
<script>
</script>
<style type="text/css">
.container {
width: 90%;
height: 90%;
}
</style>
</head>
<body>
<div class="content shadow center">
<a onclick="renderChart(0.5)" class="myButton">Last 30 Min</a>
<a onclick="renderChart(1)" class="myButton">Last 1 Hour</a>
<a onclick="renderChart(2)" class="myButton">Last 2 Hours</a>
<a onclick="renderChart(6)" class="myButton">Last 6 Hours</a>
<div class="container" style="margin: auto;margin: 10px">
<canvas id="myChart"></canvas>
</div>
<a href='./settings.html' class="myButton">Go Back</a>
</div>
</body>
</html>