summaryrefslogtreecommitdiff
path: root/ebus/webhdf/static/src/ebus.js
diff options
context:
space:
mode:
authorRandom Hacker <random_hacker@xapek.org>2013-02-24 16:44:17 +0100
committerRandom Hacker <random_hacker@xapek.org>2013-02-24 16:44:17 +0100
commit37e334d24a099e5367597ee18ac0c6d5ae2fba32 (patch)
tree057a2ad096b44e8bda448d35ebd2a7f835673f05 /ebus/webhdf/static/src/ebus.js
parent946eb7d95fc04d465802c8fc00e5d4130a52c8f2 (diff)
downloadebus-alt-37e334d24a099e5367597ee18ac0c6d5ae2fba32.tar.gz
ebus-alt-37e334d24a099e5367597ee18ac0c6d5ae2fba32.zip
hdf support
Diffstat (limited to 'ebus/webhdf/static/src/ebus.js')
-rw-r--r--ebus/webhdf/static/src/ebus.js179
1 files changed, 179 insertions, 0 deletions
diff --git a/ebus/webhdf/static/src/ebus.js b/ebus/webhdf/static/src/ebus.js
new file mode 100644
index 0000000..7667b71
--- /dev/null
+++ b/ebus/webhdf/static/src/ebus.js
@@ -0,0 +1,179 @@
+var d = new Object();
+d.sec = 1;
+d.min = 60 * d.sec;
+d.hour = 60 * d.min;
+d.day = 24 * d.hour;
+d.week = 7 * d.day;
+d.month = 30.5 * d.day;
+
+$(document).ready(function(){
+ var from = Math.round(new Date().getTime()/1000) - 2*d.day;
+ var fromOverview = Math.round(new Date().getTime()/1000) - 15*d.day;
+ var to = Math.round(new Date().getTime()/1000);
+ var datasetDetail = []
+ var datasetOverview = [];
+ var plotOverview = null;
+ var plotDetail = null;
+ var indexFound = null;
+ var sensorConfigList = [{"sensorname":"heizkreisregler9.solarDaten.tempKollektor","show":true, "color":"#f30000"},
+ {"sensorname":"heizkreisregler10.betriebsdatenRegler1.kesselTemperatur","show":true, "color":"#283074"},
+ {"sensorname":"heizkreisregler9.solarDaten.tempWarmwasserSolar","show":false, "color":"#f0ff4c"},
+ {"sensorname":"feuerungsautomat1.betriebsdatenRegler1.aussenTemperatur","show":false, "color":"#84b500"},
+ {"sensorname":"de.wettermichel.temperature","show":true, "color":"#24f590"},
+ {"sensorname":"heizkreisregler10.betriebsdatenRegler1.boilerTemperatur","show":true, "color":"#48b4ff"}];
+
+ var pickSensorConfig = function(sensorname) {
+ var SensorConfigFound;
+ $.each(sensorConfigList, function(i,sensorConfig) {
+ if (sensorConfig.sensorname == sensorname) {
+ sensorConfigFound = sensorConfig;
+ return false;
+ }
+ });
+ return sensorConfigFound;
+ }
+ var replot = function() {
+ if (plotDetail == null) {
+ plotDetail = $.plot($("#ebusgraph"),
+ datasetDetail,
+ {
+ xaxis: { mode: "time"},
+ yaxis: { min: -16, max: 100 },
+ legend: { show : true}
+ });
+ } else {
+ plotDetail.setData(datasetDetail);
+ plotDetail.draw();
+ plotDetail.setupGrid(); // redraw legend
+ }
+ };
+ var replotOverview = function() {
+ if (plotOverview == null) {
+ plotOverview = $.plot($("#overview"),
+ datasetOverview,
+ { // options
+ series: {
+ lines: { show: true, lineWidth: 1 },
+ shadowSize: 0
+ },
+ xaxis: { mode: "time" },
+ yaxis: { ticks: [], min: -26, max: 100, autoscaleMargin: 0.1 },
+ legend: { show: false },
+ selection: { mode: "x" }
+ });
+ } else {
+ plotOverview.setData(datasetOverview);
+ plotOverview.draw();
+ }
+ plotOverview.setSelection({xaxis: {'from': from*1000, 'to': to*1000}}, true);
+ };
+ var plotSensor = function(sensorConfig) {
+ plotSensorDetail(sensorConfig);
+ plotSensorOverview(sensorConfig);
+ };
+ var unplotSensor = function(sensorname) {
+ unplotSensorDetail(sensorname);
+ unplotSensorOverview(sensorname);
+ };
+ var tzFix = function(d) {
+ return d - new Date().getTimezoneOffset() * 60 * 1000;
+ }
+
+ var plotSensorDetail = function(sensorConfig) {
+ $.getJSON("sensor/"+escape(sensorConfig.sensorname)+"/"+from+"/"+to,
+ function(response) {
+ if (response['data']) {
+ response.data = response.data.map(function(d) { return [ tzFix(d[0]), d[1] ]; });
+ datasetDetail.push({'data':response['data'],
+ 'label':sensorConfig.sensorname,
+ 'color':sensorConfig.color});
+ replot();
+ } else {
+ alert("Fehler: " + response["error"]);
+ }
+ });
+ };
+
+ var unplotSensorDetail = function(sensorname) {
+ $.each(datasetDetail, function(i, sensor) {
+ if (sensor.label == sensorname) {
+ datasetDetail.splice(i,1);
+ replot();
+ return false;
+ }
+ });
+ };
+
+ var plotSensorOverview = function(sensorConfig) {
+ $.getJSON("avg/"+escape(sensorConfig.sensorname)+"/"+fromOverview,
+ function(response) {
+ if (response['data']) {
+ response.data = response.data.map(function(d) { return [ tzFix(d[0]), d[1] ]; });
+ datasetOverview.push({'data':response['data'],
+ 'label':sensorConfig.sensorname,
+ 'color':sensorConfig.color});
+ replotOverview();
+ } else {
+ alert("Overview Fehler: " + response["error"]);
+ }
+ });
+
+ };
+ var unplotSensorOverview = function(sensorname) {
+ $.each(datasetOverview, function(i, sensor) {
+ if (sensor.label == sensorname) {
+ datasetOverview.splice(i,1);
+ replotOverview();
+ return false;
+ }
+ });
+ }
+
+ $("#overview").bind("plotselected", function (event, ranges) {
+ range_from = Math.round(ranges.xaxis.from / 1000);
+ range_to = Math.round(ranges.xaxis.to / 1000);
+ // max selection range
+ if (range_to - range_from > d.month/2) {
+ plotOverview.setSelection({xaxis: {'from': from*1000, 'to': to*1000}}, true);
+ return;
+ } else {
+ from = range_from;
+ to = range_to;
+ }
+ sensors = [];
+ for (elem in datasetOverview) {
+ sensor = datasetDetail[elem]["label"];
+ sensors.push(sensor);
+ }
+ datasetDetail =[];
+ for (i in sensors) {
+ plotSensorDetail(pickSensorConfig(sensors[i]));
+ }
+ });
+
+ $.each(sensorConfigList, function(i,sensorConfig) {
+ var pickerDiv = $("<div>").attr("id","pick_"+sensorConfig.sensorname.replace(/\./g,"_"))
+ .addClass("picker")
+ .appendTo("#sensorpicker");
+
+ var pickerCheckbox = $("<input>").attr("type","checkbox")
+ .appendTo(pickerDiv);
+ $(pickerDiv).append(sensorConfig.sensorname);
+ if (sensorConfig.show) {
+ //Plot
+ plotSensor(sensorConfig);
+ $(pickerCheckbox).attr("checked","checked");
+ }
+ });
+ // TODO http://people.iola.dk/olau/flot/examples/annotating.html
+
+
+ $('.picker input').click( function() {
+ var sensorname = $(this).parent().attr("id").replace("pick_","").replace(/_/g,".");
+ if ($(this).is(":checked")) {
+ plotSensor(pickSensorConfig(sensorname));
+ } else {
+ unplotSensor(sensorname);
+ }
+ });
+});