diff options
author | Ebus-at-dockstar <ebus@dockstar> | 2013-04-30 17:50:25 +0200 |
---|---|---|
committer | Ebus-at-dockstar <ebus@dockstar> | 2013-04-30 17:50:52 +0200 |
commit | a3f3c9d7a9bb5237628eaa30b550c9cc5d3dcdc2 (patch) | |
tree | 61e49ad91c7472a5836bd51224e7d1195eb16a28 /datastore-leveldb/wwwroot_ebus/src/ebus.js | |
parent | 5e002f200691d5fd9c46ff645668b82e17c2261b (diff) | |
download | ebus-alt-a3f3c9d7a9bb5237628eaa30b550c9cc5d3dcdc2.tar.gz ebus-alt-a3f3c9d7a9bb5237628eaa30b550c9cc5d3dcdc2.zip |
wwwroot_ebus
Diffstat (limited to 'datastore-leveldb/wwwroot_ebus/src/ebus.js')
-rw-r--r-- | datastore-leveldb/wwwroot_ebus/src/ebus.js | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/datastore-leveldb/wwwroot_ebus/src/ebus.js b/datastore-leveldb/wwwroot_ebus/src/ebus.js new file mode 100644 index 0000000..5b56d76 --- /dev/null +++ b/datastore-leveldb/wwwroot_ebus/src/ebus.js @@ -0,0 +1,258 @@ +// vim: set filetype=javascript expandtab tabstop=4 shiftwidth=4 autoindent smartindent: +var d = new Object(); +d.ms = 1; +d.sec = 1000*d.ms; +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; +d.now = new Date().getTime(); + +var timeToUTC = function(d) { return d + new Date().getTimezoneOffset() * 60 * 1000; } +var timeToLocal = function(d) { return d - new Date().getTimezoneOffset() * 60 * 1000; } + +$(document).ready(function(){ + var from = d.now - 2*d.day; + var to = d.now; + var fromOverview = d.now - 1.5 * d.month; + var toOverview = d.now; + var numberOfValues = jQuery("#ebusgraph").width(); + + var datasetDetail = []; + var datasetOverview = []; + + var plotOverview = null; + var plotDetail = null; + var indexFound = null; + var sensorConfigList = [ +{ + "sensorname":"heizkreisregler10.betriebsdatenRegler1.kesselTemperatur", + "description":"Kessel Temperatur", + "values":jQuery("#ebusgraph").width()/4, + "lines":{fill: true, fillColor: "rgba(80,40,100, 0.1)"}, + "show":true, + "color":"rgb(80,40,100)" +}, +{ + "sensorname":"heizkreisregler9.solarDaten.tempKollektor", + "description":"Kollektortemperatur", + "lines":{fill: true, fillColor: "rgba(255, 0, 0, 0.4)"}, + "show":true, + "color":"#f30000" +}, +{ + "sensorname":"heizkreisregler9.solarDaten.tempWarmwasserSolar", + "description":"Warmwasser Solar", + "lines":{fill: true, fillColor: "rgba(30,250,20,0.05)"}, + "show":true, + "color":"rgba(30,250,20,0.5)" +}, +{ + "sensorname":"feuerungsautomat1.betriebsdatenRegler1.aussenTemperatur", + "description":"Aussentemperatur (ebus)", + "values":jQuery("#ebusgraph").width()/4, + "show":true, + "lines":{fill: true, fillColor: "rgba(250, 250, 0, 0.2)"}, + "color":"rgb(250,250,0)" +}, +{ + "sensorname":"dockstar.load5", + "description":"System Load (5m, *10)", + "lines":{lineWidth:1}, + "show":false, + "color":"blue", + "mapFunc":function(d){return [d[0],d[1]*10]} +}, +{ + "sensorname":"dockstar.diskfree.rootfs", + "description":"Rootfs free percent", + "show":false, + "color":"red" +}, +{ + "sensorname":"heizkreisregler10.betriebsdatenRegler1.boilerTemperatur", + "description":"Boilertemperatur", + "show":false, + "color":"#48b4ff" +}, +{"sensorname":"de.wettermichel.temperature", + "description":"Aussentemperatur (wettermichel)", + "show":false, + "lines":{fill: true, fillColor: "rgba(132, 181, 0, 0.2)"}, + "color":"#84b500" +}, + ]; + +var pickSensorConfig = function(sensorname) { + var sensorConfigFound; + $.each(sensorConfigList, function(i,sensorConfig) { + if (sensorConfig.sensorname == sensorname) { + sensorConfigFound = sensorConfig; + return false; + } + }); + return sensorConfigFound; +} +var replot = function() { + plotDetail.setData(datasetDetail); + plotDetail.getOptions().xaxes[0].min = timeToLocal(from); + plotDetail.getOptions().xaxes[0].max = timeToLocal(to); + plotDetail.setupGrid(); + plotDetail.draw(); +}; +var replotOverview = function() { + plotOverview.setData(datasetOverview); + plotOverview.setSelection({xaxis: {"from": timeToLocal(from), "to": timeToLocal(to)}}, true); + plotOverview.setupGrid(); + plotOverview.draw(); +}; +var plotSensor = function(sensorConfig) { + plotSensorDetail(sensorConfig); + plotSensorOverview(sensorConfig); +}; +var unplotSensor = function(sensorname) { + unplotSensorDetail(sensorname); + unplotSensorOverview(sensorname); +}; +var plotSensorDetail = function(sensorConfig) { + jQuery("#ebusgraph").animate({opacity:0.2}, 200); + var values = sensorConfig.values || numberOfValues; + $.getJSON("/api/range/"+escape(sensorConfig.sensorname)+"/"+from+"/"+to+"/" + values, + function(response) { + if (!response.error) { + response.data = response.data.map(function(d) { + return [ timeToLocal(d[0]), d[1] ]; + }); + if (sensorConfig.mapFunc) { + response.data = response.data.map( sensorConfig.mapFunc ) + } + datasetDetail.push({"data":response["data"], + "userData":sensorConfig.sensorname, + "lines":sensorConfig.lines || {}, + "label":sensorConfig.description, + "color":sensorConfig.color}); + + jQuery("#ebusgraph").animate({opacity:1.0}, 200); + replot(); + } else { + jQuery("#ebusgraph").animate({backgroundColor: "lightRed"},200); + alert("Fehler: " + response["error"]); + } + }).fail(function(a) { + jQuery("#ebusgraph").animate({backgroundColor: "lightRed"},200); + }); +}; + +var unplotSensorDetail = function(sensorname) { + $.each(datasetDetail, function(i, sensor) { + if (sensor.userData == sensorname) { + datasetDetail.splice(i,1); + replot(); + return false; + } + }); +}; + +var plotSensorOverview = function(sensorConfig) { + $.getJSON("api/range/"+escape(sensorConfig.sensorname)+"/"+fromOverview+"/"+toOverview+ "/" + numberOfValues/2, + function(response) { + if (!response.error) { + response.data = response.data.map(function(d) { + return [ timeToLocal(d[0]), d[1] ]; + }); + if (sensorConfig.mapFunc) { + response.data = response.data.map( sensorConfig.mapFunc) + } + 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); + range_to = Math.round(ranges.xaxis.to); + // max selection range + if (range_to - range_from > d.month) { + // reset selection + plotOverview.setSelection({xaxis: {"from": from, "to": to}}, true); + return; + } else { + from = timeToUTC(range_from); + to = timeToUTC(range_to); + } + sensors = []; + for (elem in datasetOverview) { + sensor = datasetDetail[elem]["userData"]; + sensors.push(sensor); + } + datasetDetail =[]; + for (i in sensors) { + plotSensorDetail(pickSensorConfig(sensors[i])); + } +}); + +plotDetail = $.plot($("#ebusgraph"), + datasetDetail, + { + xaxis: { mode: "time", min: timeToLocal(from), max:timeToLocal(to) }, + yaxis: { min: -16, max: 100 }, + legend: { show : true} + }); + +plotOverview = $.plot($("#overview"), + datasetOverview, + { // options + series: { + lines: { show: true, lineWidth: 1 }, + shadowSize: 0 + }, + xaxis: { mode: "time", min: timeToLocal(fromOverview), max:timeToLocal(toOverview)}, + yaxis: { ticks: [], min: -26, max: 100, autoscaleMargin: 0.1 }, + legend: { show: false }, + selection: { mode: "x" } + }); + +$.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($("<span>").text( sensorConfig.description + " (" + 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")) { + if (typeof console != "undefined") console.log(sensorname); + plotSensor(pickSensorConfig(sensorname)); + } else { + unplotSensor(sensorname); + } +}); + +}); |