2019-08-15 15:33:37 +02:00
|
|
|
window.onload = function () {
|
2021-03-08 06:18:42 +01:00
|
|
|
resize_canvas();
|
|
|
|
var chart = new SmoothieChart({ millisPerPixel: 200, maxValueScale: 1.1, minValueScale: 1.1, scaleSmoothing: 0.1, grid: { fillStyle: '#ffffff', millisPerLine: 5000, verticalSections: 8 }, labels: { fillStyle: '#0000ff', fontSize: 18, precision: 1 }, timestampFormatter: SmoothieChart.timeFormatter }),
|
2019-08-15 15:33:37 +02:00
|
|
|
canvas = document.getElementById('smoothie-chart'),
|
|
|
|
series = new TimeSeries();
|
2021-03-08 06:18:42 +01:00
|
|
|
average_array = []
|
2019-08-15 15:33:37 +02:00
|
|
|
|
|
|
|
chart.addTimeSeries(series, { lineWidth: 3.5, strokeStyle: '#ff0000' });
|
|
|
|
chart.streamTo(canvas, 500);
|
|
|
|
|
2021-03-08 06:18:42 +01:00
|
|
|
function run_proc(series, average_array) {
|
|
|
|
cockpit.spawn(['sh', '-c', 'sensors|grep °C']).then(function (data) {
|
|
|
|
pt = parseFloat(("" + data).trim().split(/[\r\n]+/)[0].split(/:\s*/)[1].trim());
|
2019-08-15 15:33:37 +02:00
|
|
|
series.append(new Date().getTime(), pt);
|
|
|
|
document.getElementById("cur_temp").innerHTML = pt;
|
|
|
|
average_array.push(pt);
|
2021-03-08 06:18:42 +01:00
|
|
|
if (average_array.length > 5 * 60) {
|
2019-08-15 15:33:37 +02:00
|
|
|
average_array.shift();
|
|
|
|
}
|
|
|
|
document.getElementById("avg_temp").innerHTML = average(average_array);
|
|
|
|
});
|
|
|
|
};
|
2021-03-08 06:18:42 +01:00
|
|
|
setInterval(function () { run_proc(series, average_array) }, 2000);
|
2019-08-15 15:33:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resize_canvas() {
|
|
|
|
document.getElementById("smoothie-chart").width = window.innerWidth - 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
function average(array) {
|
|
|
|
var sum = 0;
|
|
|
|
var count = array.length;
|
|
|
|
for (var i = 0; i < count; i++) {
|
2021-03-08 06:18:42 +01:00
|
|
|
sum = sum + array[i];
|
2019-08-15 15:33:37 +02:00
|
|
|
}
|
2021-03-08 06:18:42 +01:00
|
|
|
return Math.round(sum * 10 / count) / 10;
|
|
|
|
}
|