From 3fc788b05bba8813b5b5b274ac1676050104d2f0 Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 9 Jun 2010 18:30:28 +0000 Subject: bla git-svn-id: http://10.2.2.13/svn/common/ebus@1678 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- bin/ebus_web | 7 +++- ebus/web/controller.py | 93 ++++++++++---------------------------------------- 2 files changed, 24 insertions(+), 76 deletions(-) diff --git a/bin/ebus_web b/bin/ebus_web index 057d50e..74fe9b9 100755 --- a/bin/ebus_web +++ b/bin/ebus_web @@ -2,4 +2,9 @@ import sys from ebus.web import controller -sys.exit(controller.run()) +from sqlalchemy import create_engine + +#db_engine = create_engine('sqlite:///:memory:', echo=True) +db_engine = create_engine("postgresql://yvesf:iii@10.2.2.13:5432/yvesf", echo=True) + +sys.exit(controller.run(db_engine)) diff --git a/ebus/web/controller.py b/ebus/web/controller.py index edf174d..406db01 100644 --- a/ebus/web/controller.py +++ b/ebus/web/controller.py @@ -4,79 +4,12 @@ import os, time import itty from werkzeug.contrib.cache import SimpleCache from simplejson import dumps as dump_json +from sqlalchemy.orm import sessionmaker from ebus.web import model -def data(name): - return {"name":name} -""" -def data(name): - if name in ( - "solarDaten.tempKollektor", - "solarDaten.tempWarmwasserSolar", - "betriebsdatenRegler1.boilerTemperatur", - "betriebsdatenRegler1.kesselTemperatur", - "betriebsdatenRegler1.aussenTemperatur", - "betriebsdatenFeuerungsautomat.brauchwasserSollwert", - "betriebsdatenFeuerungsautomat.kesselSollwertTemperatur"): - m = Code(''' - function () { - emit(parseInt(this.time/900)*900000, {sum: this.values[field], count:1}); - }''') - r = Code(''' - function (key, values) { - var n = { sum:0, count:0 }; - for (var i = 0; i[^/]+)') -@itty.get('/json/(?P[^/]+)/from_date/(?P.+)') +@itty.get('/json/(?P[^/]+)') +@itty.get('/json/(?P[^/]+)/from_date/(?P[^/]+)') +@itty.get('/json/(?P[^/]+)/from_date/(?P[^/]+)/till_date/(?P[^/]+)') @CacheDecorator(key=lambda args,kwargs: tuple(kwargs.keys()) + tuple(kwargs.values()), timeout=20) -def json(req,name=None,from_date=None): +def json(req,sensor=None,from_date=None,till_date=None): print "name=%s from_date=%s" % (name,from_date) - return itty.Response(dump_json( {"label":name, "data":data(name)} ), + return itty.Response(dump_json(data(sensor)), content_type="application/json") @@ -117,5 +59,6 @@ def static(request,filename): return itty.Response(file, content_type=itty.content_type(file)) -def run(): - return itty.run_itty(host="0.0.0.0",port=5000) +def run(db_engine,host="0.0.0.0",port=5000): + Session.configure(bind=db_engine) + return itty.run_itty(host=host,port=port) -- cgit v1.2.1