Mercurial > templog
diff web/log.py @ 125:397ac5c079bf
avoid bad values
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 10 Oct 2012 22:58:35 +0800 |
parents | 7f3fc0980df1 |
children | 6a9419ac8f77 |
line wrap: on
line diff
--- a/web/log.py Wed Oct 10 22:50:02 2012 +0800 +++ b/web/log.py Wed Oct 10 22:58:35 2012 +0800 @@ -76,11 +76,14 @@ graph_args.append('CDEF:%(vname)s=raw%(vname)s,35,GT,UNKN,raw%(vname)s,0.1,*,2,+,IF' % locals()) unit = '<span face="Liberation Serif">ยบ</span>C' - last_value = float(rrdtool.info(rrdfile)['ds[temp].last_ds']) + try: + last_value = float(rrdtool.info(rrdfile)['ds[temp].last_ds']) + format_last_value = ('%f' % last_value).rstrip('0') + unit + except ValueError: + format_last_value = 'Bad' width = config.LINE_WIDTH legend = config.SENSOR_NAMES.get(sensor, sensor) colour = config.SENSOR_COLOURS.get(legend, colour_from_string(sensor)) - format_last_value = ('%f' % last_value).rstrip('0') + unit print_legend = '%s (%s)' % (legend, format_last_value) graph_args.append('LINE%(width)f:%(vname)s#%(colour)s:%(print_legend)s' % locals()) @@ -128,6 +131,13 @@ #return tempf return tempf.read() +def validate_values(measurements): + for m in measurements: + if m == 85: + yield 'U' + else: + yield '%f' % m + def sensor_update(sensor_id, measurements, first_real_time, time_step): try: open(sensor_rrd_path(sensor_id)) @@ -135,9 +145,9 @@ create_rrd(sensor_id) if measurements: - values = ['%d:%f' % p for p in + values = ['%d:%s' % p for p in zip((first_real_time + time_step*t for t in xrange(len(measurements))), - measurements)] + validate_values(measurements))] rrdfile = sensor_rrd_path(sensor_id) # XXX what to do here when it fails...