hal/resource/web/pc_overview.tmpl

103 lines
3 KiB
Cheetah
Raw Normal View History

<h1 class="page-header">Overview</h1>
<div class="row placeholders">
<H1>Last 24 hours (kWh/5min)</H1>
<div id="minute-power-chart" style="height:450px;"></div>
</div>
<div class="row placeholders">
<H1>Last Week (kWh/h)</H1>
<div id="hour-power-chart" style="height:450px;"></div>
</div>
<div class="row placeholders">
<H1>All History (kWh/day)</H1>
<div id="day-power-chart" style="height:450px;"></div>
</div>
<div class="row placeholders">
<H1>All History (kWh/week)</H1>
<div id="week-power-chart" style="height:450px;"></div>
</div>
<script>
$(function(){
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-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-10 17:03:31 +01:00
y: {
label: 'Power (kWh)',
min: 0,
},
2016-11-10 17:03:31 +01:00
y2: {
show: true,
label: 'Temperature (C)',
min: 0,
}
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-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,
};
}
</script>