diff options
author | marc <marc@thinkpad.localnet.cc> | 2011-07-12 22:23:14 +0200 |
---|---|---|
committer | marc <marc@thinkpad.localnet.cc> | 2011-07-12 22:23:14 +0200 |
commit | 0362859a8ef5d9a206d7d6910fd7664ec894a2b3 (patch) | |
tree | a80aaaa19b93a4af88e0d80e0bf8aa0815f57190 /ebus | |
parent | 2d3bebf62bee63c39e49d33180013c5d7f225a38 (diff) | |
download | ebus-alt-0362859a8ef5d9a206d7d6910fd7664ec894a2b3.tar.gz ebus-alt-0362859a8ef5d9a206d7d6910fd7664ec894a2b3.zip |
Ausgabe unabhängig vom Datentyp. Akutellesten Wert.
Diffstat (limited to 'ebus')
-rw-r--r-- | ebus/webapp/.__init__.py.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | ebus/webapp/__init__.py | 43 | ||||
-rw-r--r-- | ebus/webapp/static/.index.html.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | ebus/webapp/static/index.html | 6 |
4 files changed, 33 insertions, 16 deletions
diff --git a/ebus/webapp/.__init__.py.swp b/ebus/webapp/.__init__.py.swp Binary files differdeleted file mode 100644 index f68e2d4..0000000 --- a/ebus/webapp/.__init__.py.swp +++ /dev/null diff --git a/ebus/webapp/__init__.py b/ebus/webapp/__init__.py index 486187b..76cec16 100644 --- a/ebus/webapp/__init__.py +++ b/ebus/webapp/__init__.py @@ -19,27 +19,42 @@ Session.configure(bind=engine) @app.route('/') def index_file(): return static_files("index.html") - #return bottle.static_file("index.html", root="./static") @app.route('/static/:filename') def static_files(filename): return bottle.static_file(filename, root=os.path.join(os.path.dirname(__file__),"static")) +@app.route('/sensor/:name') +def sensor_data_single(name): + #s = Session() + #sensorid = s.query(model.Sensor).filter(model.Sensor.name == name).first() + #values = Session().query(model.Value).add_columns("timestamp","value_float","value_string","value_int") + #values = values.filter(model.Value.sensor == sensorid) + #return json.dumps(values.first().value_int) + return sensor_data_fromto(name,None,None) + @app.route('/sensor/:name/:startdate/:enddate') -def sensor_data(name,startdate,enddate): - #data = [-10,50935],[-9,50305],[-8,50403] - now = datetime.datetime.now() - # -24h - first = now.date() - datetime.timedelta(2) - last = now.date() +def sensor_data_fromto(name,startdate,enddate): s = Session() - sensorid = s.query(model.Sensor).filter(model.Sensor.name == name).first() + sensorid = s.query(model.Sensor).filter(model.Sensor.name == name).first() values = Session().query(model.Value).add_columns("timestamp","value_float","value_string","value_int") - values = values.filter(model.Value.sensor == sensorid) - values = values.filter(model.Value.timestamp.between(first,last)) + values = values.filter(model.Value.sensor == sensorid) + + if startdate == None or enddate == None: + queried_values = [] + queried_values.append(values.first()) + else: + now = datetime.datetime.now() + f = datetime.datetime.fromtimestamp(float(startdate)) + t = datetime.datetime.fromtimestamp(float(enddate)) + values = values.filter(model.Value.timestamp.between(f,t)) + queried_values = values.all() v = [] - for value in values.all(): - v.append([int(time.mktime(value.timestamp.timetuple())*1000),value.value_float]) + for value in queried_values: + if value.value_float != None: + v.append([int((time.mktime(value.timestamp.timetuple())+time.altzone*-1)*1000),value.value_float]) # time.altzone ist negativ + elif value.value_int != None: + v.append([int((time.mktime(value.timestamp.timetuple())+time.altzone*-1)*1000),value.value_int]) + elif value.value_string != None: + v.append([int((time.mktime(value.timestamp.timetuple())+time.altzone*-1)*1000),value.value_string]) return json.dumps(v) - #return "<pre> %s </pre>" % dir(values[0]) - #return json.dumps(data) diff --git a/ebus/webapp/static/.index.html.swp b/ebus/webapp/static/.index.html.swp Binary files differdeleted file mode 100644 index 2a39bee..0000000 --- a/ebus/webapp/static/.index.html.swp +++ /dev/null diff --git a/ebus/webapp/static/index.html b/ebus/webapp/static/index.html index 84db15a..754fd62 100644 --- a/ebus/webapp/static/index.html +++ b/ebus/webapp/static/index.html @@ -5,7 +5,9 @@ <script src="/static/jquery.flot.js"></script> <script> $(document).ready(function(){ - $.getJSON("/sensor/heizkreisregler9.solarDaten.tempKollektor/1/1", + var from = Math.round(new Date().getTime()/1000) - 86400; + var to = Math.round(new Date().getTime()/1000); + $.getJSON("/sensor/heizkreisregler9.solarDaten.tempKollektor/"+from+"/"+to, function(data) { $.plot($("#ebusgraph"), [data], { xaxis: { mode: "time"}}); }); @@ -13,7 +15,7 @@ </script> </head> <body> - <h1>ULTIMATE CONTROL PANEL</h1> + <h1>TEST</h1> <div id="ebusgraph"></div> </body> </html> |