comparison 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
comparison
equal deleted inserted replaced
124:24e343a3ef93 125:397ac5c079bf
74 graph_args.append('DEF:raw%(vname)s=%(rrdfile)s:temp:AVERAGE' % locals()) 74 graph_args.append('DEF:raw%(vname)s=%(rrdfile)s:temp:AVERAGE' % locals())
75 # limit max temp to 50 75 # limit max temp to 50
76 graph_args.append('CDEF:%(vname)s=raw%(vname)s,35,GT,UNKN,raw%(vname)s,0.1,*,2,+,IF' % locals()) 76 graph_args.append('CDEF:%(vname)s=raw%(vname)s,35,GT,UNKN,raw%(vname)s,0.1,*,2,+,IF' % locals())
77 unit = '<span face="Liberation Serif">º</span>C' 77 unit = '<span face="Liberation Serif">º</span>C'
78 78
79 last_value = float(rrdtool.info(rrdfile)['ds[temp].last_ds']) 79 try:
80 last_value = float(rrdtool.info(rrdfile)['ds[temp].last_ds'])
81 format_last_value = ('%f' % last_value).rstrip('0') + unit
82 except ValueError:
83 format_last_value = 'Bad'
80 width = config.LINE_WIDTH 84 width = config.LINE_WIDTH
81 legend = config.SENSOR_NAMES.get(sensor, sensor) 85 legend = config.SENSOR_NAMES.get(sensor, sensor)
82 colour = config.SENSOR_COLOURS.get(legend, colour_from_string(sensor)) 86 colour = config.SENSOR_COLOURS.get(legend, colour_from_string(sensor))
83 format_last_value = ('%f' % last_value).rstrip('0') + unit
84 print_legend = '%s (%s)' % (legend, format_last_value) 87 print_legend = '%s (%s)' % (legend, format_last_value)
85 graph_args.append('LINE%(width)f:%(vname)s#%(colour)s:%(print_legend)s' % locals()) 88 graph_args.append('LINE%(width)f:%(vname)s#%(colour)s:%(print_legend)s' % locals())
86 89
87 end = int(start+length) 90 end = int(start+length)
88 start = int(start) 91 start = int(start)
126 print>>sys.stderr, ' '.join("'%s'" % s for s in args) 129 print>>sys.stderr, ' '.join("'%s'" % s for s in args)
127 rrdtool.graph(*args) 130 rrdtool.graph(*args)
128 #return tempf 131 #return tempf
129 return tempf.read() 132 return tempf.read()
130 133
134 def validate_values(measurements):
135 for m in measurements:
136 if m == 85:
137 yield 'U'
138 else:
139 yield '%f' % m
140
131 def sensor_update(sensor_id, measurements, first_real_time, time_step): 141 def sensor_update(sensor_id, measurements, first_real_time, time_step):
132 try: 142 try:
133 open(sensor_rrd_path(sensor_id)) 143 open(sensor_rrd_path(sensor_id))
134 except IOError, e: 144 except IOError, e:
135 create_rrd(sensor_id) 145 create_rrd(sensor_id)
136 146
137 if measurements: 147 if measurements:
138 values = ['%d:%f' % p for p in 148 values = ['%d:%s' % p for p in
139 zip((first_real_time + time_step*t for t in xrange(len(measurements))), 149 zip((first_real_time + time_step*t for t in xrange(len(measurements))),
140 measurements)] 150 validate_values(measurements))]
141 151
142 rrdfile = sensor_rrd_path(sensor_id) 152 rrdfile = sensor_rrd_path(sensor_id)
143 # XXX what to do here when it fails... 153 # XXX what to do here when it fails...
144 for v in values: 154 for v in values:
145 try: 155 try: