comparison web/log.py @ 191:8318d50d766d

gets current params
author Matt Johnston <matt@ucc.asn.au>
date Tue, 11 Feb 2014 22:10:32 +0800
parents adbf70d1449f
children 4fa8cbf31065
comparison
equal deleted inserted replaced
189:101c66da848d 191:8318d50d766d
16 import binascii 16 import binascii
17 import json 17 import json
18 from colorsys import hls_to_rgb 18 from colorsys import hls_to_rgb
19 19
20 import config 20 import config
21 import atomicfile
21 22
22 def sensor_rrd_path(s): 23 def sensor_rrd_path(s):
23 return '%s/sensor_%s.rrd' % (config.DATA_PATH, str(s)) 24 return '%s/sensor_%s.rrd' % (config.DATA_PATH, str(s))
24 25
25 # returns (path, sensor_name) tuples 26 # returns (path, sensor_name) tuples
159 args += ['--right-axis', '%(volts_div)f:-%(volts_shift_div)f' % locals(), 160 args += ['--right-axis', '%(volts_div)f:-%(volts_shift_div)f' % locals(),
160 # '--right-axis-format', '%.0lf', 161 # '--right-axis-format', '%.0lf',
161 # '--right-axis-label', 'Temperature' 162 # '--right-axis-label', 'Temperature'
162 ] 163 ]
163 164
164 print>>sys.stderr, ' '.join("'%s'" % s for s in args) 165 #print>>sys.stderr, ' '.join("'%s'" % s for s in args)
165 rrdtool.graph(*args) 166 rrdtool.graph(*args)
166 #return tempf 167 #return tempf
167 return tempf.read() 168 return tempf.read()
168 169
169 def validate_value(m): 170 def validate_value(m):
220 val_rem = int(entries['%s_rem' % name]) 221 val_rem = int(entries['%s_rem' % name])
221 tick_wake = int(entries['tick_wake']) + 1 222 tick_wake = int(entries['tick_wake']) + 1
222 tick_secs = int(entries['tick_secs']) 223 tick_secs = int(entries['tick_secs'])
223 return val_ticks + float(val_rem) * tick_secs / tick_wake 224 return val_ticks + float(val_rem) * tick_secs / tick_wake
224 225
226 def write_current_params(current_params):
227 out = {}
228 out['params'] = current_params
229 out['time'] = time.time()
230 atomicfile.AtomicFile("%s/current_params.txt" % config.DATA_PATH).write(
231 json.dumps(out, sort_keys=True, indent=4)+'\n')
232
233 def read_current_params():
234 p = atomicfile.AtomicFile("%s/current_params.txt" % config.DATA_PATH).read()
235 dat = json.loads(p)
236 return dat['params']
237
225 def parse(params): 238 def parse(params):
226 239
227 start_time = time.time() 240 start_time = time.time()
228 241
229 debugf = record_debug(params) 242 debugf = record_debug(params)
241 real_t = t + time_diff 254 real_t = t + time_diff
242 for s, v in rs.iteritems(): 255 for s, v in rs.iteritems():
243 measurements.setdefault(s, []).append((real_t, v)) 256 measurements.setdefault(s, []).append((real_t, v))
244 257
245 # one-off measurements here 258 # one-off measurements here
259 current_params = params['current_params']
246 measurements['fridge_on'] = [ (time.time(), params['fridge_on']) ] 260 measurements['fridge_on'] = [ (time.time(), params['fridge_on']) ]
247 measurements['fridge_setpoint'] = [ (time.time(), params['fridge_setpoint']) ] 261 measurements['fridge_setpoint'] = [ (time.time(), current_params['fridge_setpoint']) ]
262
263 write_current_params(current_params)
248 264
249 for s, vs in measurements.iteritems(): 265 for s, vs in measurements.iteritems():
250 sensor_update(s, vs) 266 sensor_update(s, vs)
251 267
252 timedelta = time.time() - start_time 268 timedelta = time.time() - start_time
264 'fridge_range_lower': 3, 280 'fridge_range_lower': 3,
265 'fridge_range_upper': 3, 281 'fridge_range_upper': 3,
266 } 282 }
267 283
268 r = [] 284 r = []
285
286 vals = read_current_params()
287
269 for k, v in _FIELD_DEFAULTS.iteritems(): 288 for k, v in _FIELD_DEFAULTS.iteritems():
270 n = {'name': k, 'value': v} 289 n = {'name': k, 'value': vals[k]}
271 if type(v) is bool: 290 if type(v) is bool:
272 kind = 'yesno' 291 kind = 'yesno'
273 else: 292 else:
274 kind = 'number' 293 kind = 'number'
275 if k == 'overshoot_delay': 294 if k == 'overshoot_delay':