-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph.html
366 lines (366 loc) · 26 KB
/
graph.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
<!DOCTYPE html>
<html>
<head>
<title>Grapher</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Content-Language" content="en">
<meta http-equiv="refresh" content="">
<meta name="csrf-param" content="authenticity_token"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.1/css/tempusdominus-bootstrap-4.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.css" integrity="sha384-degZUV6f5Qw/AGD0Kq6kEC7j8V6h+IWPfm+AJ+2q3gaTFa9U4fu/9u3Egh7xOYE4" crossorigin="anonymous">
<style>
#back_to_top_floater {
position: fixed;
right: 10px;
bottom: 10px;
cursor: pointer;
width: 50px;
height: 50px;
background-color: #3498db;
text-indent: -9999px;
display: none;
-webkit-border-radius: 60px;
-moz-border-radius: 60px;
border-radius: 60px;
z-index: 999;
}
#back_to_top_floater span {
position: absolute;
top: 50%;
left: 50%;
margin-left: -8px;
margin-top: -12px;
height: 0;
width: 0;
border: 8px solid transparent;
border-bottom-color: #ffffff;
}
#back_to_top_floater:hover {
background-color: #e74c3c;
opacity: 1;filter:"alpha(opacity=100)";
-ms-filter:"alpha(opacity=100)";
}
html {
font-size: 16px;
}
.hr-green {
border-color: green !important;
}
time,
#last_updated {
font-size: small;
font-style: italic;
}
</style>
</head>
<body>
<div id='top' class='container-fluid'>
<a href="#" id="back_to_top_floater" style="display: none;">
<span></span>
</a>
<h1>Charts</h1>
<div class='row'>
<form class="form-inline">
<div class='col'>
<select id='device' name='uuid' class='form-control form-control-lg'>
<optgroup label='rooms'>
<option value='638a9d78-09f6-4d92-b70a-2b14edb8d84a'>Laser Lab</option>
<option value='04001f9a-122b-4045-84f4-69b7c7318250'>Unit 2</option>
<option value='ae1dd9a7-b55c-4255-8f16-7e5c69fd678b'>Electronics Lab</option>
<option value='b3efa04b-dac8-4ddc-bc34-94f1daec3c0a'>Craft Lab</option>
<option value='067746e8-7a2f-4f6e-bb59-e1b2043b37f3'>Slytherin</option>
</optgroup>
<option value='7db061e9-d73a-47a0-a4ab-f3d097da5504'>Network</option>
<option value='03bf9198-1fe5-480f-b3c7-efdf628d2b8a'>Doors</option>
<option value='4cf5765b-6a1a-4f05-879f-1285e092beb3'>Vendo</option>
<option value='4f265e2c-3c08-4635-8e50-8400d5294c29'>Printers</option>
<optgroup label='3d printers'>
<option value='7bfff065-f2e8-406d-b8d1-734a84c4c222'>Dremel</option>
<option value='6ab73b55-006b-4a95-adaa-1b9e34c85d46'>Prusa-1</option>
<option value='34a8cf9b-1c94-4554-8fad-ddb616b0f07f'>Prusa-2</option>
<option value='37853276-5ac4-406c-bb66-e012cd360781'>Zoya Ender 3 (orange)</option>
<option value='ca01bc7f-21ed-4e86-bcc8-efcdb3dcd696'>Olga Ender 3 (translucent)</option>
<option value=''>Prusa-1</option>
</optgroup>
<option value='691faad6-bad4-4c87-838b-091ce650e4d4'>Current weather</option>
<option value='ea52198c-6162-4ea8-9e19-2f99bcfb4462'>Weather Station (outdoors)</option>
<option value='1955b27e-17fd-429a-b1ce-293879149e42'>Weather Station (indoors)</option>
<optgroup label='servers'>
<option value='8cb9e03e-1bfe-4ad7-b96e-e9186956b746'>ctrlh.homebus.io</option>
<option value='59905e56-b683-4b22-bc66-345705a3f27e'>Zuul</option>
<option value='9fb914b1-1c5a-40b0-8c6d-eac29bb1ea3d'>Zoya</option>
<option value='7f9ee46e-355e-4b7c-a2c1-fe24e733796a'>Olga</option>
<option value='0d1fd497-8cf7-47b2-b0fc-baab52c52301'>cnc-octopi</option>
</optgroup>
</select>
</div>
<div class='col'>
<select id='interval' name='interval' class='form-control form-control-lg'>
<option value='60'>Last hour</option>
<option value='120'>Last 2 hours</option>
<option value='360'>Last 6 hours</option>
<option value='720'>Last 12 hours</option>
<option value='1440'>Last day</option>
<option value='2880'>Last 2 days</option>
<option value='4320'>Last 3 days</option>
<option value='7200'>Last 5 days</option>
<option value='10080'>Last week</option>
<option value='20160'>Last 2 weeks</option>
</select>
</div>
<div class='col' style='display: none;'>
<div class="input-group date" id="datetimepicker1" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1"/>
<div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
<div class="input-group-text">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
</div>
</form>
</div>
<nav id='key_nav_bar' class='navbar navbar-expand-lg navbar-light'></nav>
<div id='spinner' style='display: none;'><img src="data:image/gif;base64,R0lGODlhIwAjAPUAAP///wD/ANz+3ND+0O7+7sD+wPD+8Pr++sj+yNT+1OL+4sT+xPb+9s7+zuj+6Nj+2Lj+uOb+5n7+fqD+oAz+DF7+Xob+hnr+em7+bgD/AGL+Yj7+Pqj+qJb+lkr+Siz+LKz+rK7+rpD+kE7+Tlb+VpT+lBz+HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAIwAjAAAG/0CAcEgsGo/IpFExcCifSgGkUDBAr8QDlZrAegnbAsJrNDwUByJ4OyYqIBCr0lCYIhhD+nZALEguFyJpSQlhBYMACFQQEUMIgBKRD0oKhl1ChVR4AAQXkZ8ETwuGcg5UbQATnpEXEFAMhg1CWgUCQg+rgBNYDA1bEKGJBU4HFqwSh2QKowULmAVCBZAgTmSzD3WNB40GfxMKWAcGBJtDvZdCAhOTQ9sNCwPBQwJbCwgCBIhJEQgdGB4bAnpIBoCeISoLElQzAkEDwA0fAkrcUELIgIO/IIArcgADxIkgMQhZY2hBgwfyOD7g8A/kBxLQhBgYgMDkAwf6cgIbEiGEBZcNIzSISKnEwTs3FChw0AeAqRIGFzU2RZCmQoYMG5xZY4ANoZA3ThJcvYphIRRTYaoNgGALwIWxGShofeJgyhZZTU/JhHuVXR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MNZ0MGIRIY4gohAAKEH0/WBgTVQg4dmUMQGxPHAAfyBvqxK0BwAQIBBI4JHPJPQYMFBAssIDBEQMSLEhP0OeJgAEaMAkp9jAgBwqsiHgtAGFngCgACIxc0eEARCQMFAyBiRFATgIGeAQhkPnDQT+Ahhg4ePJy5EImDh0QOFOA5rggDjyb9ITDzYGWCo2cYPIi4wBeEPlIjCmjqFOPGARBCAlCwsiBYJQ7qEhTnjyACORjZMvzoyEHEwnqnQrFIUi6ABBE3AkCA8a4RxnuJUCbYTEjaiJaXbE4lxMDFv0MYNCDoWJUBei8vli1iIDQY0xFRV9VEMO5uKDCnCv7ta0BP4siLBAEAIfkECQoAAAAsAAAAACMAIwAABv9AgHBILBqPyKQRwkkon8rQRSJRQK9Eg2V64WC/DypV9DUaHooDMSwWqYcJkcjxNBQgBQRjqBBfJkQTGxsfJHtJCQWKim8HIlwLQxwfg4ORSQqLik5CHFMSEUIKlZWhSguaBQZCDRcXbkIYpB8lUAypDUIErhBCCJSDHxhvTwwNixAEAI4XTgcjpBPEVwqoeUIgF2oTwBICZUMHD3ehBLkRgxgDWAcGBIdDxpysGAXEBwIQIQV0RAKLCxAIIDANST5ZFDIopBDizb9UihYk6GekwwaFGDNmwCBkAERkEKwUOXBRo0YPuj4uaPBA2ZEDBSSU1GgCxBADAxCsfOBgWsGXVULwdajwgcKHCqagOGhwKWgeoOEOFEzCwGPIZQjUPMCTAN4XBuMiioJAB+aib18cpOo3AAJaBXgiQlXiIK6iXMsUIRhibdHUkRAPqVUk2O41JQ8VuYWziCKCVHONJC6A19eieWYXRR75uMCDLJr2xjtWAK2Sdl4BENDU9ObmL3YWiQb3xNpi2k9W5/mLu4iCAS57C0cSBAA7AAAAAAAAAAAA" alt=""/></div>
<div id='no_data_error' style='display: none;'>
<p>Sorry, no data was available for that interval. Please select another source or time period.</p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.2/d3.min.js" integrity="sha384-uG12/gHPdPnhdy0iCylipzJX1dy76nM6OUY+Xn6+LA15uZdd3KxD31dOnlBGuYgc" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.js" integrity="sha384-jRARDwpwU37U6ZSXCpTZ76cMZzkj09vrzygIvQqEmjT7vLaySCbOS097ca1m759r" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js" integrity="sha384-sIzeKWIAHvT0Vm8QbfLCqZwBG0WMCkWVAOYd/330YSNeeQ1Y57N3T9lQz5Ry/EHH" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.1/js/tempusdominus-bootstrap-4.min.js" integrity="sha384-hzexvprs0k2Q/IHSJOfegsjdg6kTcTTVxQdgHiB4+I/915hcvse9v42LLVVM5K4e" crossorigin="anonymous"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.6.7/jquery.timeago.min.js' integrity='sha384-bIExnxLHdrb4/5cUciUyC490hqkTPFw6V1eUbG0gpKQ67B3dsT6KOdXvl5RycCM6' crossorigin='anonymous'></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js" integrity="sha256-7/yoZS3548fXSRXqc/xYzjsmuW3sFKzuvOCHd06Pmps=" crossorigin="anonymous"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.min.js' integrity='sha384-bqIl0+8hxcMpOFf8O3ffwAy5qTUbFPyuNFytX/omkD4RDPMOBtt/uV6Lqlw7sljM' crossorigin='anonymous'></script>
<script>
$(document).ready(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('#back_to_top_floater').fadeIn();
} else {
$('#back_to_top_floater').fadeOut();
}
});
$('#back_to_top_floater').click(function () {
$("html, body").animate({
scrollTop: 0
}, 600);
return false;
});
$('#datetimepicker1').datetimepicker();
$('#interval,#device').change(function () {
this.form.submit();
});
console.log('href', window.location.href);
var url = new URL(window.location.href);
var uuid = url.searchParams.get('uuid');
$('#device option[value=' + uuid + ']').prop('selected', true);
$('#hidden-uuid').val(uuid);
var interval = url.searchParams.get('interval') || 30;
$('#interval option[value=' + interval + ']').prop('selected', true);
// interval wants to be in seconds
interval *= 60;
if (uuid) {
var target = 'https://ctrlh.homebus.io:5679/recorder/samples.json?uuid=' + uuid + '&interval=' + interval;
// var target = 'http://hipster.homebus.io/recorder/samples.json?uuid=' + uuid + '&interval=' + interval;
// var target = 'http://hipster.homebus.io/recorder/samples.json?uuid=' + uuid
console.log(target);
$('#spinner').show();
$
.getJSON(target)
// $.getJSON('https://ctrlh.homebus.io:5679/recorder/samples.json?uuid=067746e8-7a2f-4f6e-bb59-e1b2043b37f3')
// $.getJSON('https://ctrlh.homebus.io:5679/recorder/samples.json?uuid=067746e8-7a2f-4f6e-bb59-e1b2043b37f3')
// $.getJSON('http://hipster.homebus.io/recorder/samples.json?uuid=a7bda86e-e18e-4e7f-9300-d3c11ec85208')
// $.getJSON('http://hipster.homebus.io/recorder/samples.json?uuid=3f45ac0f-16a1-4f2f-bca7-fdaebd27fc86')
// $.getJSON('http://hipster.homebus.io/recorder/samples.json?topic=%2Fdirtball')
.done(function (data) {
console.log("SUCCESS!");
if (data.length > 0) {
make_chart(data);
} else {
$('#no_data_error').show();
}
$('#spinner').hide();
})
.fail(function (jqxhr, status, error) {
console.log("ERROR");
console.log(status);
console.log(error);
console.log(jqxhr);
$('#spinner').hide();
});
}
});
function make_navbar(keys) {
keys.forEach(function (key, index) {
$('#key_nav_bar').append('<a href="#section_' + key + '" class="nav-item nav-link">' + key + '</a>');
});
};
function make_section(key) {
var Capitalized = key.charAt(0).toUpperCase() + key.slice(1);
$('#top').append("<h2>" + Capitalized + "</h2>\n<div id='section_" + key + "'></div>");
};
function make_data(json, key, subkey) {
var data = [{
key: subkey,
values: []
}];
json.forEach(function (item, index) {
if (item["data"][key] && item["data"][key][subkey]) {
data[0]['values'].push({
x: Date.parse(item["created_at"]),
y: item["data"][key][subkey]
});
}
});
return data;
};
function make_graph(data, key, subkey) {
var chart = nv
.models
.lineChart() // Initialise the lineChart object.
.height(400)
.useInteractiveGuideline(true); // Turn on interactive guideline (tooltips)
chart
.xAxis
.axisLabel('Time') // Set the label of the xAxis (Vertical)
.tickFormat(function (unix_timestamp) {
var date = new Date(unix_timestamp);
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
return formattedTime;
});
chart
.yAxis
.axisLabel(subkey) // Set the label of the xAxis (Horizontal)
.tickFormat(d3.format('.02f')); // Rounded Numbers Format.
d3
.select('#chart_' + key + '_' + subkey + ' svg') // Select the ID of the html element we defined earlier.
.datum(data) // Pass in the JSON
.transition()
.duration(500) // Set transition speed
.style({height: "400px"})
.call(chart);
nv.utils.windowResize(chart.update); // Intitiate listener for window resize so the chart responds and changes width.
};
function getTimeagostamp(timestamp) {
var d = new Date(Number(timestamp));
return "<time class='timeago' datetime='" + d.toISOString() + "' title='" + d.toLocaleString() + "'></time>";
}
function activateTimeago() {
$('.timeago').timeago();
}
function make_list(data, key, subkey) {
var id = '#table_' + key + '_' + subkey;
console.log(data);
data[0].values.forEach(function (item, index) {
console.log('list item ', item.y);
$(id).append('<li>' + item.y + '<br/>' + getTimeagostamp(item.x) + '</li>');
});
activateTimeago();
};
function make_graph_subsection(key, subkey) {
$('#section_' + key).append("<div class='card'><h3 class='card-title'>" + subkey + "</h3><div id='chart_" + key + "_" + subkey + "' class='with-3d-shadow with-transitions'> <svg></svg></div></div>");
}
function make_table_subsection(key, headings) {
if (headings[0] == "") {
processed_headings = headings.slice(1);
} else {
processed_headings = headings;
}
$('#section_' + key).append("<div class='card'><h3 class='card-title'>" + processed_headings.join(', ') + "</h3><div><table id='table_" + key + "' class='table table-striped'><thead><tr></tr></thead><tbody></tbody></table></div></div>");
headings.forEach(function (item, index) {
$('#table_' + key + " thead tr").append("<th>" + item + "</th>");
});
}
function fill_image_subsection(data, key, subkey) {
Object.keys(data).forEach(function (sub, index) { // do something
});
}
function make_chart(json, status, jqXHR) {
var data = json[0].data;
var has_system = Object.keys(data).indexOf('system') != -1;
var keys = Object
.keys(data)
.filter(function (value, index, arr) {
return value != 'system' && value != 'id' && value != 'timestamp';
})
.sort();
if (has_system) {
keys.push('system');
}
make_navbar(keys);
console.log('keys', keys);
keys.forEach(function (key, index) {
make_section(key);
if (typeof(data[key]) == 'object' || typeof(data[key]) == 'string') {
var strings = [];
Object.keys(data[key]).forEach(function (subkey, index) {
if (typeof(data[key][subkey]) == 'object' || subkey == 'id') {
return;
}
console.log(key, subkey, typeof(data[key][subkey]));
var data2 = make_data(json, key, subkey);
if (typeof(data[key][subkey]) == 'number') {
make_graph_subsection(key, subkey);
make_graph(data2, key, subkey);
}
if (typeof(data[key][subkey]) == 'string') {
strings.push(subkey);
}
});
if (strings.length > 0) {
strings = strings.sort();
if (data["timestamp"]) {
strings.push("when");
}
strings.unshift("");
make_table_subsection(key, strings);
var last_obj = {};
var current_obj = {};
var repeat_count = 0;
json.forEach(function (item, index) {
strings.forEach(function (item2, index) {
current_obj[item2] = item["data"][key][item2];
});
if (_.isEqual(last_obj, current_obj)) {
repeat_count = repeat_count + 1;
current_obj = {};
$("#table_" + key + " tbody tr:last td:first").text(repeat_count + " repeats");
return;
}
repeat_count = 0;
last_obj = current_obj;
current_obj = {};
$("#table_" + key + " tbody").append("<tr></tr>");
strings.forEach(function (item2, index) {
if (item2 == "") {
$("#table_" + key + " tbody tr:last").append("<td></td>");
return;
}
console.log(item2, item["data"][key][item2]);
$("#table_" + key + " tbody tr:last").append("<td>" + (
item2 == 'when'
? getTimeagostamp(Number(item["data"]["timestamp"]) * 1000)
: item["data"][key][item2]
) + "</td>");
});
});
strings.unshift("");
activateTimeago();
}
}
});
};
</script>
</body>
</html>