@@ -59,7 +59,7 @@ def logerr(msg):
59
59
logmsg (syslog .LOG_ERR , msg )
60
60
61
61
# Print version in syslog for easier troubleshooting
62
- VERSION = "1.0"
62
+ VERSION = "1.0.1 "
63
63
loginf ("version %s" % VERSION )
64
64
65
65
class getData (SearchList ):
@@ -85,12 +85,11 @@ def get_extension_list(self, timespan, db_lookup):
85
85
binding = self .generator .config_dict ['StdReport' ].get ('data_binding' , 'wx_binding' )
86
86
manager = self .generator .db_binder .get_manager (binding )
87
87
88
- # Check if the pre-requisites have been completed. Either station_url or belchertown_root_url need to be set.
89
- if self . generator . skin_dict [ 'Extras' ][ 'belchertown_root_url' ] != "" :
88
+ # Setup belchertown_root_url for the absolute links
89
+ try :
90
90
belchertown_root_url = self .generator .skin_dict ['Extras' ]['belchertown_root_url' ]
91
- elif self .generator .config_dict ["Station" ].has_key ("station_url" ):
92
- belchertown_root_url = self .generator .config_dict ["Station" ]["station_url" ]
93
- else :
91
+ except :
92
+ # Force a blank root url if the default "" is removed from skin.conf
94
93
belchertown_root_url = ""
95
94
96
95
belchertown_debug = self .generator .skin_dict ['Extras' ].get ('belchertown_debug' , 0 )
@@ -124,11 +123,30 @@ def get_extension_list(self, timespan, db_lookup):
124
123
system_locale , locale_encoding = locale .getlocale ()
125
124
except Exception as error :
126
125
raise Warning ( "Error changing locale to %s. This locale may not exist on your system, or you have a typo. For example the correct way to define this skin setting is 'en_US.UTF-8'. The locale also needs to be installed onto your system first before Belchertown Skin can use it. Please check Google on how to install locales onto your system. Or use the default 'auto' locale skin setting. Full error: %s" % ( self .generator .skin_dict ['Extras' ]['belchertown_locale' ], error ) )
127
- system_locale_js = system_locale .replace ("_" , "-" ) # Python's locale is underscore. JS uses dashes.
128
- highcharts_decimal = locale .localeconv ()["decimal_point" ]
129
126
127
+ if system_locale is None :
128
+ # Unable to determine locale. Fallback to en_US
129
+ system_locale = "en_US"
130
+
131
+ if locale_encoding is None :
132
+ # Unable to determine locale_encoding. Fallback to UTF-8
133
+ locale_encoding = "UTF-8"
134
+
135
+ try :
136
+ system_locale_js = system_locale .replace ("_" , "-" ) # Python's locale is underscore. JS uses dashes.
137
+ except :
138
+ system_locale_js = "en-US" # Error finding locale, set to en-US
139
+
140
+ try :
141
+ highcharts_decimal = locale .localeconv ()["decimal_point" ]
142
+ except :
143
+ highcharts_decimal = "." # Default to a period
144
+
130
145
# Get the archive interval for the highcharts gapsize
131
- archive_interval_ms = int (self .generator .config_dict ["StdArchive" ]["archive_interval" ]) * 1000
146
+ try :
147
+ archive_interval_ms = int (self .generator .config_dict ["StdArchive" ]["archive_interval" ]) * 1000
148
+ except KeyError :
149
+ archive_interval_ms = 300000 # 300*1000 for archive_interval emulated to millis
132
150
133
151
# Get the ordinal labels
134
152
default_ordinate_names = ['N' , 'NNE' , 'NE' , 'ENE' , 'E' , 'ESE' , 'SE' , 'SSE' , 'S' , 'SSW' , 'SW' , 'WSW' , 'W' , 'WNW' , 'NW' , 'NNW' , 'N/A' ]
@@ -992,7 +1010,9 @@ def run(self):
992
1010
maxstamp = self .stop_ts
993
1011
else :
994
1012
# Rolling timespans using seconds
995
- (minstamp , maxstamp , timeinc ) = weeplot .utilities .scaletime (plotgen_ts - int (time_length ), plotgen_ts )
1013
+ time_length = int (time_length ) # Convert to int() for minstamp math and for point_timestamp conditional later
1014
+ minstamp = plotgen_ts - time_length # Take the generation time and subtract the time_length to get our start time
1015
+ maxstamp = plotgen_ts
996
1016
997
1017
chart_title = plot_options .get ("title" , "" )
998
1018
output [chart_group ][plotname ]["options" ]["title" ] = chart_title
@@ -1123,6 +1143,9 @@ def run(self):
1123
1143
else :
1124
1144
# No custom series data overrides, so just add series_data to the chart series data
1125
1145
output [chart_group ][plotname ]["series" ][line_name ]["data" ] = series_data
1146
+
1147
+ # Final pass through self._highchartsSeriesOptionsToInt() to convert any integer back to int which ConfigObj made a string. Highcharts typically wants integers
1148
+ output [chart_group ][plotname ]["series" ][line_name ] = self ._highchartsSeriesOptionsToInt (output [chart_group ][plotname ]["series" ][line_name ])
1126
1149
1127
1150
# This consolidates all chart_groups into the chart_group JSON (day.json, week.json, month.json, year.json) and saves them to HTML_ROOT/json
1128
1151
html_dest_dir = os .path .join (self .config_dict ['WEEWX_ROOT' ],
@@ -1527,9 +1550,10 @@ def _getObservationData(self, observation, start_ts, end_ts, aggregate_type, agg
1527
1550
usageRound = int (self .skin_dict ['Units' ]['StringFormats' ].get (obs_vt [2 ], "2f" )[- 2 ])
1528
1551
obsRound_vt = [self ._roundNone (x , usageRound ) for x in obs_vt [0 ]]
1529
1552
1530
- # "Today" charts have the point timestamp on the stop time so we don't see the previous minute in the tooltip. (e.g. 4:59 instead of 5:00)
1553
+ # "Today" charts and floating timespan charts have the point timestamp on the stop time so we don't see the
1554
+ # previous minute in the tooltip. (e.g. 4:59 instead of 5:00)
1531
1555
# Everything else has it on the start time so we don't see the next day in the tooltip (e.g. Jan 2 instead of Jan 1)
1532
- if time_length == "today" :
1556
+ if time_length == "today" or isinstance ( time_length , int ) :
1533
1557
point_timestamp = time_stop_vt
1534
1558
else :
1535
1559
point_timestamp = time_start_vt
@@ -1613,3 +1637,22 @@ def _get_cardinal_direction(self, degree):
1613
1637
elif (degree >= 348.76 and degree <= 360 ):
1614
1638
return "N"
1615
1639
1640
+ def _highchartsSeriesOptionsToInt (self , d ):
1641
+ # Recurse through all the series options and set any strings that should be integers back to integers.
1642
+ # https://stackoverflow.com/a/54565277/1177153
1643
+ try :
1644
+ for k , v in d .items ():
1645
+ if isinstance (v , dict ):
1646
+ # Check nested dicts
1647
+ self ._highchartsSeriesOptionsToInt (v )
1648
+ else :
1649
+ try :
1650
+ v = to_int (v )
1651
+ d .update ({k : v })
1652
+ except :
1653
+ pass
1654
+ return d
1655
+ except :
1656
+ # This item isn't a dict, so return it back
1657
+ return d
1658
+
0 commit comments