summaryrefslogtreecommitdiff
path: root/ebus/web/controller.py
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2010-06-17 23:07:01 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2010-06-17 23:07:01 +0000
commit41760cb473535ee479682da6e4a9a049f1056b7c (patch)
tree94ba992600d0d4713b1f274926f2203180b9c9ad /ebus/web/controller.py
parent6c580608f942d2f4b931faa6fe81171fd9e8a878 (diff)
downloadebus-alt-41760cb473535ee479682da6e4a9a049f1056b7c.tar.gz
ebus-alt-41760cb473535ee479682da6e4a9a049f1056b7c.zip
update controller
git-svn-id: http://10.2.2.13/svn/common/ebus@1680 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
Diffstat (limited to 'ebus/web/controller.py')
-rw-r--r--ebus/web/controller.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/ebus/web/controller.py b/ebus/web/controller.py
index f581e13..c5b50d2 100644
--- a/ebus/web/controller.py
+++ b/ebus/web/controller.py
@@ -8,7 +8,6 @@ from sqlalchemy.orm import sessionmaker
from ebus.web import model
-
Session = sessionmaker()
class CacheDecorator(object):
@@ -29,14 +28,8 @@ class CacheDecorator(object):
self.func = func
return self.cachedFunc
-def data(sensor, from_date=None, till_date=None):
- session = Session()
- values = session.query(model.Value)\
- .join(model.Sensor)\
- .filter(model.Sensor.name == sensor)\
- .all()
- return {"sensor":sensor, "from_date":from_date, "till_date":till_date, "values":values}
+## Web Requests
@itty.get("/")
def index(req):
filename=os.path.join(os.path.dirname(__file__), "static", "index.html")
@@ -49,7 +42,19 @@ def index(req):
timeout=20)
def json(req,sensor=None,from_date=None,till_date=None):
print "sensor=%s from_date=%s till_date=%s" % (sensor,from_date,till_date)
- return itty.Response(dump_json(data(sensor)),
+ values = Session().query(model.Value).join(model.Sensor)
+
+ if sensor:
+ values = values.filter(model.Sensor.name == sensor)\
+
+ if from_date:
+ values = values.filter(model.Value.timestamp >= from_date)
+
+ if till_date:
+ values = values.filter(model.Value.timestamp <= till_date)
+
+ response = {"sensor":sensor, "from_date":from_date, "till_date":till_date, "values":values.all()}
+ return itty.Response(dump_json(response),
content_type="application/json")
@itty.get("/static/(?P<filename>.+)")
@@ -58,6 +63,8 @@ def static(request,filename):
return itty.Response(file, content_type=itty.content_type(file))
+
+## Start method
def run(db_engine,host="0.0.0.0",port=5000):
Session.configure(bind=db_engine)
return itty.run_itty(host=host,port=port)