Good afternoon, I use Bootstrap theme with Nick gauges (dajda.net). Weewx ver. 4.1 under python 2.7 (Debian Buster) In my syslog every archive interval I see hundreds messages like: GaugeGenerator: Cannot decode reading of 'None' for gauge 'windDir' This is only happens when wind speed is not None. Below is logfile part:
*Jun 24 19:00:15 weewxpi weewxd: GaugeGenerator: outTemp reading = 25.5 degree_CJun 24 19:00:15 weewxpi weewxd: GaugeGenerator: inTemp reading = 24.1111111111 degree_CJun 24 19:00:15 weewxpi weewxd: GaugeGenerator: barometer reading = 1022.58763232 mbarJun 24 19:00:15 weewxpi weewxd: GaugeGenerator: outHumidity reading = 49.0 percentJun 24 19:00:15 weewxpi weewxd: GaugeGenerator: inHumidity reading = 56.0 percentJun 24 19:00:16 weewxpi weewxd: GaugeGenerator: windSpeed reading = 2.68224 meter_per_secondJun 24 19:00:16 weewxpi weewxd: GaugeGenerator: windGust reading = 6.25856 meter_per_secondJun 24 19:00:16 weewxpi weewxd: GaugeGenerator: windDir reading = 0.0 degree_compassJun 24 19:00:16 weewxpi weewxd: GaugeGenerator: Cannot decode reading of 'None' for gauge 'windDir'Jun 24 19:00:16 weewxpi weewxd: GaugeGenerator: Cannot decode reading of 'None' for gauge 'windDir'Jun 24 19:00:16 weewxpi weewxd: GaugeGenerator: Cannot decode reading of 'None' for gauge 'windDir'* This is part of code responsible for this: try: history = int(plot_options.get('history')) except: pass else: history_list = [] windspeed_history_list = [] batch_records = self.db_manager.genBatchRecords(self.lastGoodStamp - history * 60 * 60, self.lastGoodStamp) for rec in batch_records: db_value_tuple = weewx.units.as_value_tuple(rec, columnname) history_value = weewx.units.convert(db_value_tuple, target_unit)[0] try: history_list.append(float(history_value)) except: syslog.syslog(syslog.LOG_DEBUG, "GaugeGenerator: Cannot decode reading of '%s' for gauge '%s'" % (history_value, gaugename)) Why this happens when wind speed has reading? Thanks -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/5e06652d-1b5c-4528-a50d-1f2ae04dd2cdo%40googlegroups.com.
# # Copyright (c) 2013-2014 Nick Dajda <nick.da...@gmail.com> # # Distributed under the terms of the GNU GENERAL PUBLIC LICENSE # """Nick's custom generator for creating visual gauge image files from weewx. Tested on Weewx release 3.0.1. Tested with sqlite, may not work with other databases. WILL NOT WORK WITH Weewx prior to release 3.0. -- Use this version for 2.4 - 2.7: https://github.com/brewster76/fuzzy-archer/releases/tag/v2.0 Directions for use: 1) Put this file in the weewx/bin/user directory. 2) Add user.gaugeengine.GaugeGenerator to the list of Generators in skin.conf. 3) Add a [GaugeGenerator] section to skin.conf. Any gauges contained in this section are created when the report generator runs. 4) Guage names must match the Weewx field name, e.g. outTemp or barometer 5) Here is an example [GaugeGenerator] section: ############################################################################################ # # Settings for Gauge Generator # [GaugeGenerator] image_width = 160 image_height = 160 # Colors... # # Format is 0xBBGGRR, so a pinky-purple color (r=FF, g=00, B=99) which would have # an HTML tag of #FF0099 is expressed as 0x9900FF fill_color = 0x4242b4 background_color = 0xffffff label_color = 0x000000 dial_color = 0x707070 needle_outline_color = 0xb48242 needle_fill_color = 0xb48242 # Leave option out for a transparent needle text_color = 0xb48242 # How far the gauge extends, e.g. 180 is half a full dial, 270 is three quarters # This is ignored when plotting wind direction which always uses 360. # Must be an integer dial_arc = 270 digitfontsize = 13 labelfontsize = 14 [[outTemp]] minvalue = -20 maxvalue = 40 majorstep = 10 minorstep = 2 digitformat = %d history = 24 bins = 90 [[barometer]] minvalue = 970 maxvalue = 1050 majorstep = 20 minorstep = 5 digitformat = %d history = 24 bins = 80 [[outHumidity]] minvalue = 0 maxvalue = 100 majorstep = 20 minorstep = 5 history = 24 bins = 50 [[windSpeed]] minvalue = 0 maxvalue = 40 majorstep = 10 minorstep = 2 history = 24 bins = 40 [[windGust]] minvalue = 0 maxvalue = 40 majorstep = 10 minorstep = 2 history = 24 bins = 40 [[windDir]] majorstep = 90 minorstep = 30 invert = false history = 24 bins = 16 aggregate_type = None [[curImpTemp]] minvalue = 0 maxvalue = 90 majorstep = 10 minorstep = 2 digitformat = %d history = 24 bins = 90 data_binding = calduino_binding input3 = selImpTemp data_binding3 = calduino_binding input2 = retTemp data_binding2 = calduino_binding [[inTemp]] minvalue = 5 maxvalue = 35 majorstep = 5 minorstep = 1 digitformat = %d history = 24 bins = 90 data_binding = wx_binding input2 = selRoomTempHC1 type2 = marker data_binding2 = calduino_binding needle_outline_color2 = 0x5a4121 needle_fill_color2 = 0x5a4121 text_color2 = 0x5a4121 """ import time import syslog import os.path from PIL import Image import weeutil.weeutil import weewx.reportengine import weeplot.utilities import user.gauges class GaugeGenerator(weewx.reportengine.ReportGenerator): """Class for managing the gauge generator.""" def run(self): self.setup() # Generate any images self.gen_gauges() def setup(self): self.db_manager = self.db_binder.get_manager() self.gauge_dict = self.skin_dict['GaugeGenerator'] self.units_dict = self.skin_dict['Units'] # Create a converter to get this into the desired units self.converter = weewx.units.Converter(self.units_dict['Groups']) def gen_gauges(self): """Generate the gauges.""" t1 = time.time() ngen = 0 # Loop over each time span class (day, week, month, etc.): for gauge in self.gauge_dict.sections: plot_options = weeutil.weeutil.accumulateLeaves(self.gauge_dict[gauge]) # Get DB Manager for a diferent data binding binding = plot_options['data_binding'] self.db_manager = self.db_binder.get_manager(binding) # Lookup the last reading in the archive self.lastGoodStamp = self.db_manager.lastGoodStamp() self.record_dict_vtd = None self.record_dict_vtd2 = None self.record_dict_vtd3 = None batch_records = self.db_manager.genBatchRecords(self.lastGoodStamp - 1, self.lastGoodStamp) try: for rec in batch_records: if self.record_dict_vtd is None: self.record_dict_vtd = rec except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: Cannot find the current reading") try: if plot_options['input2'] is not None: # Get a second DB Manager for a diferent data binding binding2 = plot_options['data_binding2'] self.db_manager = self.db_binder.get_manager(binding2) self.lastGoodStamp2 = self.db_manager.lastGoodStamp() batch_records2 = self.db_manager.genBatchRecords(self.lastGoodStamp2 - 1, self.lastGoodStamp2) try: for rec2 in batch_records2: if self.record_dict_vtd2 is None: self.record_dict_vtd2 = rec2 except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: Cannot find the current reading") self.db_manager = self.db_binder.get_manager(binding) except: pass try: if plot_options['input3'] is not None: # Get a second DB Manager for a diferent data binding binding3 = plot_options['data_binding3'] self.db_manager = self.db_binder.get_manager(binding3) self.lastGoodStamp3 = self.db_manager.lastGoodStamp() batch_records3 = self.db_manager.genBatchRecords(self.lastGoodStamp3 - 1, self.lastGoodStamp3) try: for rec3 in batch_records3: if self.record_dict_vtd3 is None: self.record_dict_vtd3 = rec3 except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: Cannot find the current reading") self.db_manager = self.db_binder.get_manager(binding) except: pass # For checking development code deals with 'None' readings correctly if self.gauge_dict.get('test_none_readings', None) is not None: for key, value in self.record_dict_vtd.iteritems(): self.record_dict_vtd[key] = None # For checking development code deals with 'None' readings correctly if self.gauge_dict.get('test_none_readings', None) is not None: for key, value in self.record_dict_vtd2.iteritems(): self.record_dict_vtd2[key] = None image_root = os.path.join(self.config_dict['WEEWX_ROOT'], plot_options['HTML_ROOT']) # Get the path of the file that the image is going to be saved to: img_file = os.path.join(image_root, '%sGauge.png' % gauge) # Create the subdirectory that the image is to be put in. # Wrap in a try block in case it already exists. try: os.makedirs(os.path.dirname(img_file)) except: pass ret = self.gen_gauge(gauge, plot_options, img_file) if ret is not None: ngen += 1 t2 = time.time() syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: Generated %d images for %s in %.2f seconds" % (ngen, self.skin_dict['REPORT_NAME'], t2 - t1)) def gen_gauge(self, gaugename, plot_options, img_file): image_width = int(plot_options.get('image_width', 180)) image_height = int(plot_options.get('image_height', 180)) # Need to remember in case image is blown up for anti-aliasing original_width = image_width original_height = image_height back_color = weeplot.utilities.tobgr(plot_options.get('background_color', '0xffffff')) back_color_tuple = self._int2rgb(back_color) fill_color = weeplot.utilities.tobgr(plot_options.get('fill_color', '0xffffff')) fill_color_tuple = self._int2rgb(fill_color) compass_labels = int(plot_options.get('compass_labels', 0)) label_color = weeplot.utilities.tobgr(plot_options.get('label_color', '0x000000')) dial_color = weeplot.utilities.tobgr(plot_options.get('dial_color', '0x707070')) needle_outline_color = weeplot.utilities.tobgr(plot_options.get('needle_outline_color', '0xb48242')) needle_outline_color2 = weeplot.utilities.tobgr(plot_options.get('needle_outline_color2', '0xadb442')) needle_outline_color3 = weeplot.utilities.tobgr(plot_options.get('needle_outline_color3', '0x5a4121')) needle_fill_color = plot_options.get('needle_fill_color', None) if needle_fill_color is None or needle_fill_color == 'None' or needle_fill_color == 'Opaque': needle_fill_color = None else: needle_fill_color = weeplot.utilities.tobgr(needle_fill_color) needle_fill_color2 = plot_options.get('needle_fill_color2', None) if needle_fill_color2 is None or needle_fill_color2 == 'None' or needle_fill_color2 == 'Opaque': needle_fill_color2 = None else: needle_fill_color2 = weeplot.utilities.tobgr(needle_fill_color2) needle_fill_color3 = plot_options.get('needle_fill_color3', None) if needle_fill_color3 is None or needle_fill_color3 == 'None' or needle_fill_color3 == 'Opaque': needle_fill_color3 = None else: needle_fill_color3 = weeplot.utilities.tobgr(needle_fill_color3) text_color = weeplot.utilities.tobgr(plot_options.get('text_color', '0xb48242')) text_color2 = weeplot.utilities.tobgr(plot_options.get('text_color2', '0xadb442')) text_color3 = weeplot.utilities.tobgr(plot_options.get('text_color3', '0x5a4121')) history_color = weeplot.utilities.tobgr(plot_options.get('history_color', '0x4242b4')) font_path = plot_options.get('font_path', '/usr/share/fonts/truetype/freefont/FreeSans.ttf') label_font_size = int(plot_options.get('labelfontsize', 15)) digit_font_size = int(plot_options.get('digitfontsize', 15)) dial_thickness = float(plot_options.get('line_thickness', 1)) try: anti_alias = int(plot_options.get('anti_alias')) except: anti_alias = None else: # Need to apply this factor to everything that will shrink back down dial_thickness *= anti_alias label_font_size *= anti_alias digit_font_size *= anti_alias image_width *= anti_alias image_height *= anti_alias # Must specify this for every gauge try: major_step = float(plot_options.get('majorstep')) except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: *** Please specify majorstep for gauge %s in skin.conf ***" % gaugename) return try: minor_step = float(plot_options.get('minorstep')) except: minor_step = None image = Image.new("RGB", (image_width, image_height), back_color_tuple) # Create a new gauge instance using the gauges.py library if gaugename == 'windRose': gauge = user.gauges3needles.WindRoseGaugeDraw(image, background_color=fill_color) wind_units = self.converter.getTargetUnit('windSpeed') else: wind_units = None if gaugename == 'windDir': # Need to do some special setup for wind gauges min_value = 0 max_value = 360 dial_arc = 360 offset_angle = 180 else: try: min_value = float(plot_options.get('minvalue')) except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: *** Please specify minvalue for gauge %s in skin.conf ***" % gaugename) return try: max_value = float(plot_options.get('maxvalue')) except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: *** Please specify maxvalue for gauge %s in skin.conf ***" % gaugename) return dial_arc = int(plot_options.get('dial_arc', 270)) offset_angle = int(plot_options.get('offset_angle', 0)) gauge = user.gauges.GaugeDraw(image, min_value, max_value, dial_range=dial_arc, background_color=fill_color, offset_angle=offset_angle) # windRose is a special case of gaugename since windRose is not the name of the archive column that # contains the data. columnname = gaugename if gaugename != 'windRose' else 'windDir' # Find display unit of measure try: target_unit = self.units_dict['Groups'][weewx.units.obs_group_dict[columnname]] except: syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: *** Could not find target unit of measure for gauge '%s'. Obs group is: '%s'. ***" % (gaugename, weewx.units.obs_group_dict[columnname])) return # Deal with None readings / convert to target units if self.record_dict_vtd[columnname] is None: none_value = plot_options.get('none_value', None) if none_value is None: value_now = None else: value_now = float(none_value) syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s has no reading (%s)" % (gaugename, value_now)) return else: # Convert it to units in skin.conf file value_now = weewx.units.convert(weewx.units.as_value_tuple(self.record_dict_vtd, columnname), target_unit)[0] syslog.syslog(syslog.LOG_DEBUG, "GaugeGenerator: %s reading = %s %s" % (gaugename, value_now, target_unit)) # Get the second source of data for the gauge if plot_options.get('input2') is not None: columnname2 = plot_options.get('input2') # Deal with None readings / convert to target units if self.record_dict_vtd2[columnname2] is None: none_value = plot_options.get('none_value', None) if none_value is None: value_now2 = None else: value_now2 = float(none_value) syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s has no reading (%s)" % (columnname2, value_now2)) return else: # Convert it to units in skin.conf file value_now2 = weewx.units.convert(weewx.units.as_value_tuple(self.record_dict_vtd2, columnname2), target_unit)[0] # syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s reading = %s %s" % (columnname2, value_now2, target_unit)) # syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s reading = %s %s" % (gaugename, value_now, target_unit)) else: value_now2 = None # Get the third source of data for the gauge if plot_options.get('input3') is not None: columnname3 = plot_options.get('input3') # Deal with None readings / convert to target units if self.record_dict_vtd3[columnname3] is None: none_value = plot_options.get('none_value', None) if none_value is None: value_now3 = None else: value_now3 = float(none_value) syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s has no reading (%s)" % (columnname3, value_now3)) return else: # Convert it to units in skin.conf file value_now3 = weewx.units.convert(weewx.units.as_value_tuple(self.record_dict_vtd3, columnname3), target_unit)[0] # syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s reading = %s %s" % (columnname2, value_now2, target_unit)) # syslog.syslog(syslog.LOG_INFO, "GaugeGenerator: %s reading = %s %s" % (gaugename, value_now, target_unit)) else: value_now3 = None label_format = self.units_dict['StringFormats'][target_unit] dial_format = plot_options.get('digitformat', label_format) if value_now is None: label_text = '---' else: label_text = label_format % value_now try: label_text += self.units_dict['Labels'][target_unit] except: pass gauge.add_text(label_text, text_font_size=label_font_size, text_font=font_path, text_color=text_color) if plot_options.get('input2') is not None: if value_now2 is None: label_text2 = '---' else: label_text2 = label_format % value_now2 try: label_text2 += self.units_dict['Labels'][target_unit] except: pass gauge.add_text2(label_text2, text_font_size=label_font_size, text_font=font_path, text_color=text_color2) if plot_options.get('input3') is not None: if value_now3 is None: label_text3 = '---' else: label_text3 = label_format % value_now3 try: label_text3 += self.units_dict['Labels'][target_unit] except: pass gauge.add_text3(label_text3, text_font_size=label_font_size, text_font=font_path, text_color=text_color3) if value_now is not None: if plot_options.get('type') == 'marker': gauge.add_marker(float(value_now), needle_outline_color=needle_outline_color, needle_fill_color=needle_fill_color) else: gauge.add_needle(float(value_now), needle_outline_color=needle_outline_color, needle_fill_color=needle_fill_color) if value_now2 is not None: if plot_options.get('type2') == 'marker': gauge.add_marker2(float(value_now2), needle_outline_color=needle_outline_color2, needle_fill_color=needle_fill_color2) else: gauge.add_needle2(float(value_now2), needle_outline_color=needle_outline_color2, needle_fill_color=needle_fill_color2) if value_now3 is not None: if plot_options.get('type3') == 'marker': gauge.add_marker3(float(value_now3), needle_outline_color=needle_outline_color3, needle_fill_color=needle_fill_color3) else: gauge.add_needle3(float(value_now3), needle_outline_color=needle_outline_color3, needle_fill_color=needle_fill_color3) try: history = int(plot_options.get('history')) except: pass else: history_list = [] windspeed_history_list = [] batch_records = self.db_manager.genBatchRecords(self.lastGoodStamp - history * 60 * 60, self.lastGoodStamp) for rec in batch_records: db_value_tuple = weewx.units.as_value_tuple(rec, columnname) history_value = weewx.units.convert(db_value_tuple, target_unit)[0] try: history_list.append(float(history_value)) except: syslog.syslog(syslog.LOG_DEBUG, "GaugeGenerator: Cannot decode reading of '%s' for gauge '%s'" % (history_value, gaugename)) else: if gaugename == 'windRose': speed_value = self.converter.convertDict(rec)['windSpeed'] # Uses up a lot of time try: value_knot = float(weewx.units.convert((speed_value, wind_units[0], None), 'knot')[0]) except: pass else: windspeed_history_list.append(value_knot) num_buckets = int(plot_options.get('bins', 10)) if gaugename == 'windRose': rings = [] for ring in plot_options.get('rings', [1, 3, 10]): rings.append(int(ring)) ring_colors = [] for ring_color in plot_options.get('ring_colors', [0x4242b4, 0xb482420, 0xff0000]): ring_colors.append(weeplot.utilities.tobgr(ring_color)) gauge.add_history(history_list, num_buckets, windspeed_history_list, rings, ring_colors) else: gauge.add_history(history_list, num_buckets, history_color) if compass_labels: # Lookup the labels for the main compass points and add them to the gauge try: labels_dict = self.skin_dict['Labels'] except: hemispheres = ['N', 'S', 'E', 'W'] else: hemispheres = labels_dict.get("hemispheres", ['N', 'S', 'E', 'W']) compass_points = [0, 180, 90, 270] dial_labels = dict(zip(compass_points, hemispheres)) gauge.add_dial_labels(dial_labels=dial_labels, dial_label_font_size=digit_font_size, dial_label_color=label_color, dial_label_font=font_path) # Do not add degree numbers to the dial dial_format = None gauge.add_dial(major_ticks=major_step, minor_ticks=minor_step, dial_format=dial_format, dial_font_size=digit_font_size, dial_font=font_path, dial_color=dial_color, dial_label_color=label_color, dial_thickness=dial_thickness) gauge.render() if anti_alias is not None: image.thumbnail((original_width, original_height), Image.ANTIALIAS) image.save(img_file) return 1 @staticmethod def _int2rgb(x): # # Stolen from genploy.py Weewx file # if x is None: return None else: b = (x >> 16) & 0xff g = (x >> 8) & 0xff r = x & 0xff return r, g, b