diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2011-12-06 19:31:51 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2011-12-06 19:31:51 +0100 |
commit | 4f67e6e30f3300c948afbc498ac7fb71ea8e431f (patch) | |
tree | fc1534c15ca1ee6b1b56efff693ec2110b2b24a9 /ebus/webapp/__init__.py | |
parent | a6f7d26fd72222970226018d423c7138f34c7c0e (diff) | |
download | ebus-alt-4f67e6e30f3300c948afbc498ac7fb71ea8e431f.tar.gz ebus-alt-4f67e6e30f3300c948afbc498ac7fb71ea8e431f.zip |
svg demo
Diffstat (limited to 'ebus/webapp/__init__.py')
-rw-r--r-- | ebus/webapp/__init__.py | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/ebus/webapp/__init__.py b/ebus/webapp/__init__.py index 1435912..d0e0ff6 100644 --- a/ebus/webapp/__init__.py +++ b/ebus/webapp/__init__.py @@ -119,8 +119,6 @@ def stream(soup, startdate=None): cursor = conn.cursor() cursor.execute("LISTEN evt_ebus_value_insert;") - print "Waiting for notifications on channel 'evt_ebus_value_insert'" - values = [] if select.select([conn],[],[],10) == ([],[],[]): time_stop = datetime.datetime.now() @@ -132,17 +130,49 @@ def stream(soup, startdate=None): if notify: sql = text("""SELECT sensor.name, value.timestamp, - COALESCE(value.value_int,value.value_float) "value_real" + COALESCE(value.value_int,value.value_float) "value_real", + value_string FROM value, sensor WHERE value.sensor_id = sensor.id AND timestamp >= :time_start AND timestamp < :time_stop""") - values = connection.execute(sql, time_start=time_start, time_stop=time_stop) - values = map(lambda row: (row.name, maketime(row.timestamp), row.value_real != None and row.value_real.__float__() or None), - values) + values = map(lambda row: { + "name":row.name, + "timestamp":maketime(row.timestamp), + "value_real":row.value_real != None and row.value_real.__float__() or None, + "value_string":row.value_string + }, + connection.execute(sql, time_start=time_start, time_stop=time_stop)) cursor.close() return {'time_start' : maketime(time_start), 'time_stop':maketime(time_stop), 'data':values} +@app.route("/all_values") +def all_values(soup): + conn = soup.connection() + + sql = text(""" + SELECT sensor.name, + value.timestamp, + COALESCE(value.value_int,value.value_float) "value_real", + value_string + FROM value, sensor, (SELECT MAX(timestamp) as timestamp, + sensor_id + FROM value + WHERE timestamp > CURRENT_TIMESTAMP - '15 minutes'::interval + GROUP BY sensor_id) last_value + WHERE value.timestamp = last_value.timestamp + AND value.sensor_id = last_value.sensor_id + AND value.sensor_id = sensor.id""") + + values = map(lambda row: { + "name":row.name, + "timestamp":maketime(row.timestamp), + "value_real":row.value_real != None and row.value_real.__float__() or None, + "value_string":row.value_string}, + conn.execute(sql)) + + return {'data':values} + # vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python |