changeset 159:683cfd134f6a

Fix the updated json web code to work
author Matt Johnston <matt@ucc.asn.au>
date Thu, 03 Jan 2013 22:35:54 +0800
parents 6d799bee3508
children 256505f98c4d 632d436d227b
files web/log.py
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/web/log.py	Thu Jan 03 20:12:07 2013 +0800
+++ b/web/log.py	Thu Jan 03 22:35:54 2013 +0800
@@ -14,12 +14,13 @@
 import datetime
 import struct
 import binascii
+import json
 from colorsys import hls_to_rgb
 
 import config
 
 def sensor_rrd_path(s):
-    return '%s/sensor_%s.rrd' % (config.DATA_PATH, s)
+    return '%s/sensor_%s.rrd' % (config.DATA_PATH, str(s))
 
 # returns (path, sensor_name) tuples
 def all_sensors():
@@ -45,6 +46,8 @@
                 'DS:temp:GAUGE:600:-100:500',
                 'RRA:AVERAGE:0.5:1:1051200']
 
+    print>>sys.stderr, sensor_rrd_path(sensor_id) 
+
     rrdtool.create(sensor_rrd_path(sensor_id), 
                 '--start', 'now-60d',
                 *args)
@@ -148,9 +151,9 @@
 
 def validate_value(m):
     if m == 85:
-        yield 'U'
+        return 'U'
     else:
-        yield '%f' % m
+        return '%f' % m
 
 def sensor_update(sensor_id, measurements):
     try:
@@ -180,11 +183,10 @@
 def record_debug(params):
     f = debug_file('a+')
     f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S'))
-    json.dump(params, f, sort_keys=True, indent=4))
+    json.dump(params, f, sort_keys=True, indent=4)
     f.flush()
     return f
 
-
 def tail_debug_log():
     f = debug_file()
     f.seek(0, 2)
@@ -221,14 +223,15 @@
     for rs, t in readings:
         real_t = t + time_diff
         for s, v in rs.iteritems():
-            measurements.getdefault(s, []).append((real_t, v))
+            measurements.setdefault(s, []).append((real_t, v))
 
     # one-off measurements here
     measurements['fridge_on'] = [ (time.time(), params['fridge_on']) ]
+    measurements['fridge_setpoint'] = [ (time.time(), params['fridge_setpoint']) ]
 
     for s, vs in measurements.iteritems():
         sensor_update(s, vs)
 
     timedelta = time.time() - start_time
-    debugf.write("Updated %d sensors in %.2f secs\n" % (len(sensors), timedelta))
+    debugf.write("Updated sensors in %.2f secs\n" % timedelta)
     debugf.flush()