#!/usr/bin/env python # -*- coding: utf-8 -*- import os, time import itty from werkzeug.contrib.cache import SimpleCache from simplejson import dumps as dump_json 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.+)') @CacheDecorator(key=lambda args,kwargs: tuple(kwargs.keys()) + tuple(kwargs.values()), timeout=20) def json(req,name=None,from_date=None): print "name=%s from_date=%s" % (name,from_date) return itty.Response(dump_json( {"label":name, "data":data(name)} ), content_type="application/json") @itty.get("/static/(?P.+)") def static(request,filename): file = itty.static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static')) return itty.Response(file, content_type=itty.content_type(file)) def run(): return itty.run_itty(host="0.0.0.0",port=5000)