Skip to content

Commit c360121

Browse files
authored
Merge pull request #153 from poblabs/development
Merge 1.0.1 development to master
2 parents 9c84a24 + 0447fd5 commit c360121

File tree

8 files changed

+99
-28
lines changed

8 files changed

+99
-28
lines changed

Diff for: bin/user/belchertown.py

+55-12
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def logerr(msg):
5959
logmsg(syslog.LOG_ERR, msg)
6060

6161
# Print version in syslog for easier troubleshooting
62-
VERSION = "1.0"
62+
VERSION = "1.0.1"
6363
loginf("version %s" % VERSION)
6464

6565
class getData(SearchList):
@@ -85,12 +85,11 @@ def get_extension_list(self, timespan, db_lookup):
8585
binding = self.generator.config_dict['StdReport'].get('data_binding', 'wx_binding')
8686
manager = self.generator.db_binder.get_manager(binding)
8787

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:
9090
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
9493
belchertown_root_url = ""
9594

9695
belchertown_debug = self.generator.skin_dict['Extras'].get('belchertown_debug', 0)
@@ -124,11 +123,30 @@ def get_extension_list(self, timespan, db_lookup):
124123
system_locale, locale_encoding = locale.getlocale()
125124
except Exception as error:
126125
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"]
129126

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+
130145
# 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
132150

133151
# Get the ordinal labels
134152
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):
9921010
maxstamp = self.stop_ts
9931011
else:
9941012
# 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
9961016

9971017
chart_title = plot_options.get("title", "")
9981018
output[chart_group][plotname]["options"]["title"] = chart_title
@@ -1123,6 +1143,9 @@ def run(self):
11231143
else:
11241144
# No custom series data overrides, so just add series_data to the chart series data
11251145
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])
11261149

11271150
# 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
11281151
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
15271550
usageRound = int(self.skin_dict['Units']['StringFormats'].get(obs_vt[2], "2f")[-2])
15281551
obsRound_vt = [self._roundNone(x, usageRound) for x in obs_vt[0]]
15291552

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)
15311555
# 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):
15331557
point_timestamp = time_stop_vt
15341558
else:
15351559
point_timestamp = time_start_vt
@@ -1613,3 +1637,22 @@ def _get_cardinal_direction(self, degree):
16131637
elif (degree >= 348.76 and degree <= 360):
16141638
return "N"
16151639

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+

Diff for: changelog

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
1.0.1 June 9, 2019
2+
3+
# Changes
4+
5+
* Adds more debugging capability. See Wiki "How to get help" section.
6+
* Adds default chart values for areaspline chart type.
7+
* Updates the areaspline and area charts threshold. Default is 0, now it's undefined so its a floating y axis range.
8+
* Fixes a chart bug with Highcharts values being set as an integer resulting in unexpected behavior.
9+
* Fixes a locale bug if a system locale is not defined (or is using C, which Python views as None)
10+
* Fixes an archive_interval bug if one is not defined in weewx.conf (e.g. when the station provides the archive interval, not weewx)
11+
* Fixes a belchertown_root_url bug which affects on certain scenarios. In 1.1 belchertown_root_url may be removed all together.
12+
* Fixes a moon translation label in the celestial information
13+
* Fixes a bug with scaletime and rolling time period charts. Unsure why scaletime was used but it's gone now.
14+
* Fixes a bug with point timestamp and using an odd minute like :59 instead of :00
15+
* Fixes a typo in the skin.conf labels section
16+
* Removes an invalid link from the "powered by" line in the header.
17+
118
1.0 June 1, 2019
219

320
**BREAKING CHANGES**:

Diff for: install.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def loader():
99
class ExfoliationInstaller(ExtensionInstaller):
1010
def __init__(self):
1111
super(ExfoliationInstaller, self).__init__(
12-
version="1.0",
12+
version="1.0.1",
1313
name='Belchertown',
1414
description='A clean modern skin with real time streaming updates and interactive charts. Modeled after BelchertownWeather.com',
1515
author="Pat OBrien",

Diff for: skins/Belchertown/celestial.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
<td class="data">$almanac.next_full_moon</td>
159159
</tr>
160160
<tr>
161-
<td class="label">$obs.label.new moon</td>
161+
<td class="label">$obs.label.new_moon</td>
162162
<td class="data">$almanac.next_new_moon</td>
163163
</tr>
164164
#else

Diff for: skins/Belchertown/header.html.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
#if $page == "home" and $Extras.has_key("mqtt_websockets_enabled") and $Extras.mqtt_websockets_enabled == '1'
8787
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js"></script>
8888
#end if
89-
<script type='text/javascript' src='//code.highcharts.com/stock/highstock.js'></script>
90-
<script type='text/javascript' src='//code.highcharts.com/highcharts-more.js'></script>
89+
<script type='text/javascript' src='//code.highcharts.com/stock/7.1.2/highstock.js'></script>
90+
<script type='text/javascript' src='//code.highcharts.com/7.1.2/highcharts-more.js'></script>
9191
<script type='text/javascript' src='$belchertown_root_url/js/belchertown.js?#echo int( time.time() )#'></script>
9292
<script>
9393
// Set the session variables for the theme

Diff for: skins/Belchertown/js/belchertown.js.tmpl

+18-9
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ function onConnectionLost(responseObject) {
674674

675675
// New message from mqtt, process it
676676
function onMessageArrived(message) {
677+
belchertown_debug( message.payloadString );
677678
update_current_wx( message.payloadString );
678679
}
679680

@@ -975,6 +976,8 @@ function showChart(json_file, prepend_renderTo=false) {
975976
enabled: false,
976977
radius: 2
977978
},
979+
threshold: null,
980+
softThreshold: true
978981
},
979982
line: {
980983
lineWidth: 2,
@@ -994,21 +997,24 @@ function showChart(json_file, prepend_renderTo=false) {
994997
radius: 2
995998
},
996999
},
1000+
areaspline: {
1001+
lineWidth: 2,
1002+
gapSize: '',
1003+
gapUnit: 'value',
1004+
marker: {
1005+
enabled: false,
1006+
radius: 2
1007+
},
1008+
threshold: null,
1009+
softThreshold: true
1010+
},
9971011
scatter: {
9981012
gapSize: '',
9991013
gapUnit: 'value',
10001014
marker: {
10011015
radius: 2
10021016
},
10031017
},
1004-
series: {
1005-
states: {
1006-
hover: {
1007-
// This disables the overly large hover markers
1008-
enabled: false
1009-
}
1010-
}
1011-
}
10121018
},
10131019

10141020
// Highstock is needed for gapsize. Disable these 3 to make it look like standard Highcharts
@@ -1288,9 +1294,12 @@ function showChart(json_file, prepend_renderTo=false) {
12881294
options.series.push(ns);
12891295
});
12901296
}
1291-
1297+
12921298
// Finally all options are done, now show the chart
12931299
var chart = new Highcharts.chart(options);
1300+
1301+
// If using debug, show a copy paste debug for use with jsfiddle
1302+
belchertown_debug("Highcharts.chart('container', " + JSON.stringify(options) + ");");
12941303

12951304
});
12961305

Diff for: skins/Belchertown/json/weewx_data.json.tmpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"longitude": "$station.longitude[1]' $station.longitude[2]",
3030
"latitude_dd": "$station.stn_info.latitude_f",
3131
"longitude_dd": "$station.stn_info.longitude_f",
32-
"altitude": "$station.altitude"
32+
"altitude": "$station.altitude",
33+
"archive_interval": "#echo $archive_interval_ms / 1000 #",
34+
"archive_interval_ms": "$archive_interval_ms"
3335
},
3436
"station_observations": {
3537
"current": $station_obs_json,

Diff for: skins/Belchertown/skin.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
records_page_header = "Weather Observation Records"
135135
reports_page_header = "Weather Observation Reports"
136136
about_page_header = "About This Weather Station"
137-
powered_by = "Observations are powered by a <a href="/about" target="_blank">Personal Weather Station</a>"
137+
powered_by = "Observations are powered by a Personal Weather Station"
138138

139139
# DarkSky translations
140140
alert_in_effect = in effect until
@@ -204,7 +204,7 @@
204204
sun_always_down = Always down
205205
sun_always_up = Always up
206206
more_than_yesterday = more than yesterday
207-
less_than_yesterday = less_than_yesterday
207+
less_than_yesterday = less than yesterday
208208
start_civil_twilight = Start civil twilight
209209
rise = Rise
210210
transit = Transit

0 commit comments

Comments
 (0)