-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.html
More file actions
151 lines (127 loc) · 4.24 KB
/
monitor.html
File metadata and controls
151 lines (127 loc) · 4.24 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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<style type="text/css">
.container{
height:100%;
min-height:100%;
}
.tempChart{
width:100%;
height:80%;
float:left;
}
.field{
width:33%;
height:40px;
float:left;
}
</style>
<script>
var chart = {
chart: {type: 'column'},
title: {text: 'Time Series Analysis'},
xAxis: {categories: ['-60m','-55m','-50m', '-45m', '-40m', '-35m', '-30m', '-25m', '-20m', '-15m', '-10m', '-5m', 'now', '5m', '10m', '15m', '20m', '25m', '30m', '35m','40m', '45m','50m','55m', '60m']},
yAxis: {title: {text: '°C'}, min:16, max:25, tickInterval: 1},
series: [{type: 'line',
color:'#D379C4',
lineWidth: 1,
marker:{enabled:false},
name: 'Set Point',
data: []},
{type: 'column',
color: '#A4D379',
name: 'Mesured Temperature',
data: []},
{type: 'line',
color:'#E79307',
lineWidth: 3,
marker:{enabled:false},
name: 'Projection',
data: []}
]
};
// Excuted when the page is loaded.
$(function () { renderPage();});
//Retrieves data and renders them.
function renderPage(){
$.ajax({
url: "http://bpoller.hd.free.fr/timeSeries/get",
dataType: 'jsonp',
cache:true,
jsonpCallback: 'cb',
success : function (data) {renderChart(data);}
});
}
function renderChart(rawData){
chart.series[0].data = generateSetPointSeries(rawData);
chart.series[1].data = getMesuredTemperature(rawData);
chart.series[2].data = getProjection(rawData);
$('div.tempChart').highcharts(chart);
$('#setpoint').text(rawData.setPoint);
$('#temp').text(rawData.tempNow);
$('#projection').text(forecastSetPointReached(rawData));
}
function forecastSetPointReached(rawData)
{
var proj = (rawData.setPoint - rawData.n) / rawData.m * rawData.period / 60000;
var result = "";
if(proj > -Infinity && proj < 0){
result = "Projected intersection happened " + (-proj.toFixed(4)) + " minutes ago.";
}
else if(proj < Infinity && proj > 0){
result = "Projected intersection happens in " + proj.toFixed(4) + " mins.";
}
else {
result = "Projected intersection never happens.";
}
return result;
}
function generateSetPointSeries(rawData){
var setPointSeries = new Array();
for (i = 0; i < rawData.capacity * 2 +1; i++){
setPointSeries[i] = rawData.setPoint;
}
return setPointSeries;
}
function getMesuredTemperature(rawData){
var temps = rawData.tempHisto;
temps.push(rawData.tempNow);
return temps;
}
function getProjection(rawData){
var projection = new Array();
for (i = 0; i < rawData.capacity * 2 +1; i++){
var x = i - rawData.capacity;
projection[i] = rawData.m * x + rawData.n;
}
return projection;
}
function calibrate(){
var temp = parseFloat($('input#calTemp').val());
if(!isNaN(temp)){
console.log("Calibrate to " + temp);
$.ajax({
url: "http://bpoller.hd.free.fr/setPoint/calibrate/"+temp,
dataType: 'jsonp',
cache:true,
jsonpCallback: 'cb',
success : function (data) {renderPage();}
});
}
}
</script>
</head>
<div class="container">
<div class="tempChart"></div>
<div class="field" style="background-color: rgb(164,211,121);">Temp: <span id="temp"></span>°C</div>
<div class="field" style="background-color: rgb(211,121,196);">Set Point: <span id="setpoint"></span>°C</div>
<div class="field" id="projection" style="background-color:rgb(231,147,7);"></div>
<div class="field" style="background-color:rgb(231,147,7);">
<input type="text" id="calTemp">
<button id="calibButton" onClick="calibrate();">Calibrate!</button>
</div>
</div>
</html>