2015-12-10 21:30:37 +01:00
|
|
|
<h1 class="page-header">Overview</h1>
|
|
|
|
|
|
|
|
|
|
<div class="row placeholders">
|
|
|
|
|
<H1>Last 24 hours (kWh/5min)</H1>
|
2016-06-02 17:50:25 +02:00
|
|
|
<div id="minute-power-chart" style="height:450px;"></div>
|
2015-12-10 21:30:37 +01:00
|
|
|
</div>
|
|
|
|
|
<div class="row placeholders">
|
2015-12-11 23:19:17 +01:00
|
|
|
<H1>Last Week (kWh/h)</H1>
|
2016-06-02 17:50:25 +02:00
|
|
|
<div id="hour-power-chart" style="height:450px;"></div>
|
2015-12-10 21:30:37 +01:00
|
|
|
</div>
|
|
|
|
|
<div class="row placeholders">
|
2015-12-11 23:19:17 +01:00
|
|
|
<H1>All History (kWh/day)</H1>
|
2016-06-02 17:50:25 +02:00
|
|
|
<div id="day-power-chart" style="height:450px;"></div>
|
2015-12-10 21:30:37 +01:00
|
|
|
</div>
|
2016-02-09 12:43:28 +01:00
|
|
|
<div class="row placeholders">
|
|
|
|
|
<H1>All History (kWh/week)</H1>
|
2016-06-02 17:50:25 +02:00
|
|
|
<div id="week-power-chart" style="height:450px;"></div>
|
2016-02-09 12:43:28 +01:00
|
|
|
</div>
|
2015-12-10 21:30:37 +01:00
|
|
|
|
|
|
|
|
<script>
|
2016-06-02 17:50:25 +02:00
|
|
|
|
2015-12-10 21:30:37 +01:00
|
|
|
$(function(){
|
2016-11-07 17:07:11 +01:00
|
|
|
initChart("#minute-power-chart", "?json&data=minute", 5*60*1000);
|
|
|
|
|
initChart("#hour-power-chart", "?json&data=hour", 60*60*1000);
|
2016-11-10 17:03:31 +01:00
|
|
|
initChart("#day-power-chart", "?json&data=day", 24*60*60*1000);
|
|
|
|
|
initChart("#week-power-chart", "?json&data=week", 7*24*60*60*1000);
|
2016-06-02 17:50:25 +02:00
|
|
|
|
2015-12-11 17:31:13 +01:00
|
|
|
});
|
2016-06-01 11:14:58 +02:00
|
|
|
|
2016-11-10 17:03:31 +01:00
|
|
|
function initChart(elementId, url, updateTime){
|
|
|
|
|
var tickConf = {count: 20};
|
|
|
|
|
if (updateTime < 60*60*1000)
|
|
|
|
|
tickConf['format'] = '%H:%M';
|
|
|
|
|
else if (updateTime < 24*60*60*1000)
|
|
|
|
|
tickConf['format'] = '%Y-%m-%d %H:%M';
|
|
|
|
|
else
|
|
|
|
|
tickConf['format'] = '%Y-%m-%d';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var chart = c3.generate({
|
|
|
|
|
bindto: elementId,
|
|
|
|
|
data: {json: []}, // set empty data, data will be loaded later
|
|
|
|
|
axis : {
|
|
|
|
|
x : {
|
|
|
|
|
type : 'timeseries',
|
|
|
|
|
label: 'Timestamp',
|
|
|
|
|
tick: tickConf,
|
2016-11-07 17:07:11 +01:00
|
|
|
},
|
2016-11-10 17:03:31 +01:00
|
|
|
y: {
|
|
|
|
|
label: 'Power (kWh)',
|
|
|
|
|
min: 0,
|
2016-11-07 17:07:11 +01:00
|
|
|
},
|
2016-11-10 17:03:31 +01:00
|
|
|
y2: {
|
|
|
|
|
show: true,
|
|
|
|
|
label: 'Temperature (C)',
|
|
|
|
|
min: 0,
|
2016-11-07 17:07:11 +01:00
|
|
|
}
|
2016-11-10 17:03:31 +01:00
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
y: {show: true}
|
|
|
|
|
},
|
|
|
|
|
point: {
|
|
|
|
|
show: false
|
|
|
|
|
}
|
2016-11-09 16:57:58 +01:00
|
|
|
});
|
2016-11-10 17:03:31 +01:00
|
|
|
|
|
|
|
|
updateChart(chart, url, updateTime);;
|
2016-11-09 16:57:58 +01:00
|
|
|
}
|
2016-11-10 17:03:31 +01:00
|
|
|
function updateChart(chart, url, updateTime){
|
2016-11-09 16:57:58 +01:00
|
|
|
$.getJSON(url, function(json){
|
2016-11-10 17:03:31 +01:00
|
|
|
chart.load(getChartData(json));
|
2016-06-02 17:50:25 +02:00
|
|
|
});
|
2016-11-10 17:03:31 +01:00
|
|
|
setTimeout(function(){ updateChart(chart, url, updateTime); }, updateTime);
|
2016-11-09 16:57:58 +01:00
|
|
|
}
|
|
|
|
|
function getChartData(json){
|
|
|
|
|
var dataXaxis = {};
|
|
|
|
|
var dataYaxis = {};
|
|
|
|
|
var data = [];
|
|
|
|
|
var labels = [];
|
|
|
|
|
json.forEach(function(sensor, i) {
|
|
|
|
|
var index = 'data'+i;
|
|
|
|
|
labels[index] = sensor.user +": "+ sensor.name;
|
|
|
|
|
dataXaxis[index] = 'data'+i+'x';
|
|
|
|
|
data.push([index+'x'].concat(sensor.timestamps));
|
|
|
|
|
data.push([index].concat(sensor.data));
|
2016-11-10 17:03:31 +01:00
|
|
|
|
2016-11-09 16:57:58 +01:00
|
|
|
if (sensor.type == "PowerConsumptionSensorData")
|
|
|
|
|
dataYaxis[index] = 'y';
|
|
|
|
|
else //if (sensor.type == "TemperatureSensorData")
|
|
|
|
|
dataYaxis[index] = 'y2';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
xs: dataXaxis,
|
|
|
|
|
columns: data,
|
|
|
|
|
names: labels,
|
|
|
|
|
type: 'spline',
|
|
|
|
|
axes: dataYaxis,
|
|
|
|
|
};
|
2015-12-10 21:30:37 +01:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|