summaryrefslogtreecommitdiff
path: root/ebus/webapp/__init__.py
diff options
context:
space:
mode:
authormarc <marc@thinkpad.localnet.cc>2011-07-10 11:43:14 +0200
committermarc <marc@thinkpad.localnet.cc>2011-07-10 11:43:14 +0200
commit4e7f2748ccd6feba3e24b5ae5a285eeac7decc4b (patch)
tree443fb6b177212e2b124c4a95e76a5501068e5a81 /ebus/webapp/__init__.py
parent053dac10a85feea51cf6cb3435b3d3f08e4e0ddb (diff)
downloadebus-alt-4e7f2748ccd6feba3e24b5ae5a285eeac7decc4b.tar.gz
ebus-alt-4e7f2748ccd6feba3e24b5ae5a285eeac7decc4b.zip
Test mit Ajax und Flot bei der Auswertung
Diffstat (limited to 'ebus/webapp/__init__.py')
-rw-r--r--ebus/webapp/__init__.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/ebus/webapp/__init__.py b/ebus/webapp/__init__.py
new file mode 100644
index 0000000..486187b
--- /dev/null
+++ b/ebus/webapp/__init__.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+
+import bottle
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+
+from ebus.sql import model
+import os
+import json
+import datetime
+import time
+app = bottle.Bottle("ebus")
+bottle.debug()
+
+engine = create_engine("postgresql://ebus:ebus@10.2.2.26/ebus", echo=True)
+Session = sessionmaker()
+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/: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()
+ 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)
+ values = values.filter(model.Value.timestamp.between(first,last))
+ v = []
+ for value in values.all():
+ v.append([int(time.mktime(value.timestamp.timetuple())*1000),value.value_float])
+ return json.dumps(v)
+ #return "<pre> %s </pre>" % dir(values[0])
+ #return json.dumps(data)