Skip to content

Commit

Permalink
Merge pull request #153 from poblabs/development
Browse files Browse the repository at this point in the history
Merge 1.0.1 development to master
  • Loading branch information
poblabs authored Jun 9, 2019
2 parents 9c84a24 + 0447fd5 commit c360121
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 28 deletions.
67 changes: 55 additions & 12 deletions bin/user/belchertown.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def logerr(msg):
logmsg(syslog.LOG_ERR, msg)

# Print version in syslog for easier troubleshooting
VERSION = "1.0"
VERSION = "1.0.1"
loginf("version %s" % VERSION)

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

# Check if the pre-requisites have been completed. Either station_url or belchertown_root_url need to be set.
if self.generator.skin_dict['Extras']['belchertown_root_url'] != "":
# Setup belchertown_root_url for the absolute links
try:
belchertown_root_url = self.generator.skin_dict['Extras']['belchertown_root_url']
elif self.generator.config_dict["Station"].has_key("station_url"):
belchertown_root_url = self.generator.config_dict["Station"]["station_url"]
else:
except:
# Force a blank root url if the default "" is removed from skin.conf
belchertown_root_url = ""

belchertown_debug = self.generator.skin_dict['Extras'].get('belchertown_debug', 0)
Expand Down Expand Up @@ -124,11 +123,30 @@ def get_extension_list(self, timespan, db_lookup):
system_locale, locale_encoding = locale.getlocale()
except Exception as error:
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 ) )
system_locale_js = system_locale.replace("_", "-") # Python's locale is underscore. JS uses dashes.
highcharts_decimal = locale.localeconv()["decimal_point"]

if system_locale is None:
# Unable to determine locale. Fallback to en_US
system_locale = "en_US"

if locale_encoding is None:
# Unable to determine locale_encoding. Fallback to UTF-8
locale_encoding = "UTF-8"

try:
system_locale_js = system_locale.replace("_", "-") # Python's locale is underscore. JS uses dashes.
except:
system_locale_js = "en-US" # Error finding locale, set to en-US

try:
highcharts_decimal = locale.localeconv()["decimal_point"]
except:
highcharts_decimal = "." # Default to a period

# Get the archive interval for the highcharts gapsize
archive_interval_ms = int(self.generator.config_dict["StdArchive"]["archive_interval"]) * 1000
try:
archive_interval_ms = int(self.generator.config_dict["StdArchive"]["archive_interval"]) * 1000
except KeyError:
archive_interval_ms = 300000 # 300*1000 for archive_interval emulated to millis

# Get the ordinal labels
default_ordinate_names = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N/A']
Expand Down Expand Up @@ -992,7 +1010,9 @@ def run(self):
maxstamp = self.stop_ts
else:
# Rolling timespans using seconds
(minstamp, maxstamp, timeinc) = weeplot.utilities.scaletime(plotgen_ts - int(time_length), plotgen_ts)
time_length = int(time_length) # Convert to int() for minstamp math and for point_timestamp conditional later
minstamp = plotgen_ts - time_length # Take the generation time and subtract the time_length to get our start time
maxstamp = plotgen_ts

chart_title = plot_options.get("title", "")
output[chart_group][plotname]["options"]["title"] = chart_title
Expand Down Expand Up @@ -1123,6 +1143,9 @@ def run(self):
else:
# No custom series data overrides, so just add series_data to the chart series data
output[chart_group][plotname]["series"][line_name]["data"] = series_data

# Final pass through self._highchartsSeriesOptionsToInt() to convert any integer back to int which ConfigObj made a string. Highcharts typically wants integers
output[chart_group][plotname]["series"][line_name] = self._highchartsSeriesOptionsToInt(output[chart_group][plotname]["series"][line_name])

# 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
html_dest_dir = os.path.join(self.config_dict['WEEWX_ROOT'],
Expand Down Expand Up @@ -1527,9 +1550,10 @@ def _getObservationData(self, observation, start_ts, end_ts, aggregate_type, agg
usageRound = int(self.skin_dict['Units']['StringFormats'].get(obs_vt[2], "2f")[-2])
obsRound_vt = [self._roundNone(x, usageRound) for x in obs_vt[0]]

# "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)
# "Today" charts and floating timespan 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)
# 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)
if time_length == "today":
if time_length == "today" or isinstance(time_length, int):
point_timestamp = time_stop_vt
else:
point_timestamp = time_start_vt
Expand Down Expand Up @@ -1613,3 +1637,22 @@ def _get_cardinal_direction(self, degree):
elif (degree >= 348.76 and degree <= 360):
return "N"

def _highchartsSeriesOptionsToInt(self, d):
# Recurse through all the series options and set any strings that should be integers back to integers.
# https://stackoverflow.com/a/54565277/1177153
try:
for k, v in d.items():
if isinstance(v, dict):
# Check nested dicts
self._highchartsSeriesOptionsToInt(v)
else:
try:
v = to_int(v)
d.update({k: v})
except:
pass
return d
except:
# This item isn't a dict, so return it back
return d

17 changes: 17 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
1.0.1 June 9, 2019

# Changes

* Adds more debugging capability. See Wiki "How to get help" section.
* Adds default chart values for areaspline chart type.
* Updates the areaspline and area charts threshold. Default is 0, now it's undefined so its a floating y axis range.
* Fixes a chart bug with Highcharts values being set as an integer resulting in unexpected behavior.
* Fixes a locale bug if a system locale is not defined (or is using C, which Python views as None)
* Fixes an archive_interval bug if one is not defined in weewx.conf (e.g. when the station provides the archive interval, not weewx)
* Fixes a belchertown_root_url bug which affects on certain scenarios. In 1.1 belchertown_root_url may be removed all together.
* Fixes a moon translation label in the celestial information
* Fixes a bug with scaletime and rolling time period charts. Unsure why scaletime was used but it's gone now.
* Fixes a bug with point timestamp and using an odd minute like :59 instead of :00
* Fixes a typo in the skin.conf labels section
* Removes an invalid link from the "powered by" line in the header.

1.0 June 1, 2019

**BREAKING CHANGES**:
Expand Down
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def loader():
class ExfoliationInstaller(ExtensionInstaller):
def __init__(self):
super(ExfoliationInstaller, self).__init__(
version="1.0",
version="1.0.1",
name='Belchertown',
description='A clean modern skin with real time streaming updates and interactive charts. Modeled after BelchertownWeather.com',
author="Pat OBrien",
Expand Down
2 changes: 1 addition & 1 deletion skins/Belchertown/celestial.inc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<td class="data">$almanac.next_full_moon</td>
</tr>
<tr>
<td class="label">$obs.label.new moon</td>
<td class="label">$obs.label.new_moon</td>
<td class="data">$almanac.next_new_moon</td>
</tr>
#else
Expand Down
4 changes: 2 additions & 2 deletions skins/Belchertown/header.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
#if $page == "home" and $Extras.has_key("mqtt_websockets_enabled") and $Extras.mqtt_websockets_enabled == '1'
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js"></script>
#end if
<script type='text/javascript' src='//code.highcharts.com/stock/highstock.js'></script>
<script type='text/javascript' src='//code.highcharts.com/highcharts-more.js'></script>
<script type='text/javascript' src='//code.highcharts.com/stock/7.1.2/highstock.js'></script>
<script type='text/javascript' src='//code.highcharts.com/7.1.2/highcharts-more.js'></script>
<script type='text/javascript' src='$belchertown_root_url/js/belchertown.js?#echo int( time.time() )#'></script>
<script>
// Set the session variables for the theme
Expand Down
27 changes: 18 additions & 9 deletions skins/Belchertown/js/belchertown.js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ function onConnectionLost(responseObject) {

// New message from mqtt, process it
function onMessageArrived(message) {
belchertown_debug( message.payloadString );
update_current_wx( message.payloadString );
}

Expand Down Expand Up @@ -975,6 +976,8 @@ function showChart(json_file, prepend_renderTo=false) {
enabled: false,
radius: 2
},
threshold: null,
softThreshold: true
},
line: {
lineWidth: 2,
Expand All @@ -994,21 +997,24 @@ function showChart(json_file, prepend_renderTo=false) {
radius: 2
},
},
areaspline: {
lineWidth: 2,
gapSize: '',
gapUnit: 'value',
marker: {
enabled: false,
radius: 2
},
threshold: null,
softThreshold: true
},
scatter: {
gapSize: '',
gapUnit: 'value',
marker: {
radius: 2
},
},
series: {
states: {
hover: {
// This disables the overly large hover markers
enabled: false
}
}
}
},

// Highstock is needed for gapsize. Disable these 3 to make it look like standard Highcharts
Expand Down Expand Up @@ -1288,9 +1294,12 @@ function showChart(json_file, prepend_renderTo=false) {
options.series.push(ns);
});
}

// Finally all options are done, now show the chart
var chart = new Highcharts.chart(options);

// If using debug, show a copy paste debug for use with jsfiddle
belchertown_debug("Highcharts.chart('container', " + JSON.stringify(options) + ");");

});

Expand Down
4 changes: 3 additions & 1 deletion skins/Belchertown/json/weewx_data.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"longitude": "$station.longitude[1]' $station.longitude[2]",
"latitude_dd": "$station.stn_info.latitude_f",
"longitude_dd": "$station.stn_info.longitude_f",
"altitude": "$station.altitude"
"altitude": "$station.altitude",
"archive_interval": "#echo $archive_interval_ms / 1000 #",
"archive_interval_ms": "$archive_interval_ms"
},
"station_observations": {
"current": $station_obs_json,
Expand Down
4 changes: 2 additions & 2 deletions skins/Belchertown/skin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
records_page_header = "Weather Observation Records"
reports_page_header = "Weather Observation Reports"
about_page_header = "About This Weather Station"
powered_by = "Observations are powered by a <a href="/about" target="_blank">Personal Weather Station</a>"
powered_by = "Observations are powered by a Personal Weather Station"

# DarkSky translations
alert_in_effect = in effect until
Expand Down Expand Up @@ -204,7 +204,7 @@
sun_always_down = Always down
sun_always_up = Always up
more_than_yesterday = more than yesterday
less_than_yesterday = less_than_yesterday
less_than_yesterday = less than yesterday
start_civil_twilight = Start civil twilight
rise = Rise
transit = Transit
Expand Down

0 comments on commit c360121

Please sign in to comment.