diff options
author | Ebus-at-dockstar <ebus@dockstar> | 2014-07-26 19:55:43 +0200 |
---|---|---|
committer | Ebus-at-dockstar <ebus@dockstar> | 2014-07-26 19:55:43 +0200 |
commit | a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb (patch) | |
tree | 524672c3237be2552379f9d752184bd3cbf1d554 /datastore-leveldb/wwwroot_laerm/src/ebus.js | |
parent | 3f5b5ff5e71cf078c2c04906bffa06f3a1050085 (diff) | |
download | ebus-alt-a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb.tar.gz ebus-alt-a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb.zip |
Revert "embed xexpr-path" restore datastore-leveldb and other stuff
This reverts commit f6675ccdd7a5997def3c4656f0e2c5dbbbed1fc8.
Diffstat (limited to 'datastore-leveldb/wwwroot_laerm/src/ebus.js')
-rw-r--r-- | datastore-leveldb/wwwroot_laerm/src/ebus.js | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/datastore-leveldb/wwwroot_laerm/src/ebus.js b/datastore-leveldb/wwwroot_laerm/src/ebus.js new file mode 100644 index 0000000..1b905c3 --- /dev/null +++ b/datastore-leveldb/wwwroot_laerm/src/ebus.js @@ -0,0 +1,196 @@ +// vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=javascript +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 - 4*d.day; + var to = d.now; + var fromOverview = d.now - 3 * d.day; + var toOverview = d.now; + var datasetDetail = [] + var datasetOverview = []; + var plotOverview = null; + var plotDetail = null; + var indexFound = null; + var numberOfValues = 1000; + var sensorConfigList = [ + {"sensorname":"arduino.a0.dba", + "description":"Arduino dB(A)", + "show":true, + "color":"red"}, + {"sensorname":"beagleboard.internet.speed", + "description":"Internet Speed", + "mapFunc":function(d) { + return [d[0], d[1]/10000]; + }, + "show":true, + "color":"blue"} + ]; + + 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 = $.plot($("#ebusgraph"), + datasetDetail, + { + xaxis: { mode: "time", min: timeToLocal(from), max:timeToLocal(to) }, + yaxis: { min: 10, max: 75 }, + legend: { show : true} + }); + }; + var replotOverview = function() { + if (plotOverview == null) { + 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: 10, max: 75, autoscaleMargin: 0.1 }, + legend: { show: false }, + selection: { mode: "x" } + }); + } else { + plotOverview.setData(datasetOverview); + plotOverview.draw(); + } + plotOverview.setSelection({xaxis: {'from': timeToLocal(from), 'to': timeToLocal(to)}}, true); + }; + var plotSensor = function(sensorConfig) { + plotSensorDetail(sensorConfig); + plotSensorOverview(sensorConfig); + }; + var unplotSensor = function(sensorname) { + unplotSensorDetail(sensorname); + unplotSensorOverview(sensorname); + }; + var plotSensorDetail = function(sensorConfig) { + $.getJSON("/api/range/"+escape(sensorConfig.sensorname)+"/"+from+"/"+to+"/" + numberOfValues, + 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, + 'label':sensorConfig.description, + 'color':sensorConfig.color}); + replot(); + } else { + alert("Fehler: " + response["error"]); + } + }); //.fail(function(a) { console.log(a); }); + }; + + 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, + 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])); + } + }); + + $.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")) { + plotSensor(pickSensorConfig(sensorname)); + } else { + unplotSensor(sensorname); + } + }); +}); |