From 0cc987e9991630da1505779e87d5c3fcfa237e4d Mon Sep 17 00:00:00 2001 From: David Baetge Date: Thu, 2 Nov 2023 16:57:40 +0100 Subject: [PATCH] Added support for weewx-GTS (software defined obs). --- bin/user/weewx_wdc.py | 17 +++++++++++++++++ skins/weewx-wdc/includes/body-alternative.inc | 4 ++-- skins/weewx-wdc/includes/body-classic.inc | 4 ++-- skins/weewx-wdc/lang/de.conf | 5 +++++ skins/weewx-wdc/lang/en.conf | 5 +++++ skins/weewx-wdc/lang/it.conf | 5 +++++ skins/weewx-wdc/lang/nl.conf | 7 ++++++- skins/weewx-wdc/skin.conf | 2 +- skins/weewx-wdc/src/js/diagrams/d3/line.tsx | 8 ++++++++ 9 files changed, 51 insertions(+), 6 deletions(-) diff --git a/bin/user/weewx_wdc.py b/bin/user/weewx_wdc.py index 87b12ae6..75f21c8a 100644 --- a/bin/user/weewx_wdc.py +++ b/bin/user/weewx_wdc.py @@ -354,6 +354,23 @@ def __init__(self, generator): "wx_binding" ) + # print(self.generator.config_dict["StdWXCalculate"]["Calculations"]) + + def get_software_obs(self): + """ + Get the observations provided by software (weewx calculations), was + added because the has_data check fails for GTS, seasonGDD or yearGDD. + + Returns: + list: The software observations + """ + try: + obs = filter( + lambda x: "software" in x[1], self.generator.config_dict["StdWXCalculate"]["Calculations"].items()) + return list(dict(obs).keys()) + except KeyError: + return [] + def get_locale(self): """ Get the locale. diff --git a/skins/weewx-wdc/includes/body-alternative.inc b/skins/weewx-wdc/includes/body-alternative.inc index 55abce11..5bc87cb1 100644 --- a/skins/weewx-wdc/includes/body-alternative.inc +++ b/skins/weewx-wdc/includes/body-alternative.inc @@ -160,7 +160,7 @@ $render_gauges($DisplayOptions['Gauges'][$context]) ## ValueError: start time (1654034700) is greater than stop time (1640991600) #set $alltime_tag = $alltime($data_binding=$skin_obs_binding) if $context == 'alltime' else None - #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($combined_diagram.obs[$combined_obs].observation)).has_data + #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($combined_diagram.obs[$combined_obs].observation)).has_data or $combined_diagram.obs[$combined_obs].observation in $get_software_obs #set global $comb_obs = $skin_obs #set global $combined_diagram = $combined_diagram #set global $diagram_index = $diagram_index @@ -172,7 +172,7 @@ $render_gauges($DisplayOptions['Gauges'][$context]) #else #set $skin_obs_binding = $get_data_binding($skin_obs, $context) #set $alltime_tag = $alltime($data_binding=$skin_obs_binding) if $context == 'alltime' else None - #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($skin_obs)).has_data or (($skin_obs == 'windDir' or $skin_obs == 'windRose') and $getattr($get_time_span_from_context($context, $day, $week, $month, $year, $alltime, $yesterday), 'windSpeed').has_data) + #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($skin_obs)).has_data or (($skin_obs == 'windDir' or $skin_obs == 'windRose') and $getattr($get_time_span_from_context($context, $day, $week, $month, $year, $alltime, $yesterday), 'windSpeed').has_data or $skin_obs in $get_software_obs) #set global $partial_obs = $skin_obs #set global $diagram_index = $diagram_index #if $skin_obs == 'windRose' diff --git a/skins/weewx-wdc/includes/body-classic.inc b/skins/weewx-wdc/includes/body-classic.inc index 43849107..0931fe16 100644 --- a/skins/weewx-wdc/includes/body-classic.inc +++ b/skins/weewx-wdc/includes/body-classic.inc @@ -109,7 +109,7 @@ ## ValueError: start time (1654034700) is greater than stop time (1640991600) #set $alltime_tag = $alltime($data_binding=$skin_obs_binding) if $context == 'alltime' else None - #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($combined_diagram.obs[$combined_obs].observation)).has_data + #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($combined_diagram.obs[$combined_obs].observation)).has_data or $combined_diagram.obs[$combined_obs].observation in $get_software_obs #set global $comb_obs = $skin_obs #set global $combined_diagram = $combined_diagram #set global $diagram_index = $diagram_index @@ -121,7 +121,7 @@ #else #set $skin_obs_binding = $get_data_binding($skin_obs, $context) #set $alltime_tag = $alltime($data_binding=$skin_obs_binding) if $context == 'alltime' else None - #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($skin_obs)).has_data or (($skin_obs == 'windDir' or $skin_obs == 'windRose') and $getattr($get_time_span_from_context($context, $day, $week, $month, $year, $alltime, $yesterday), 'windSpeed').has_data) + #if $getattr($get_time_span_from_context($context, $day($data_binding=$skin_obs_binding), $week($data_binding=$skin_obs_binding), $month($data_binding=$skin_obs_binding), $year($data_binding=$skin_obs_binding), $alltime_tag, $yesterday($data_binding=$skin_obs_binding)), $get_custom_data_binding_obs_key($skin_obs)).has_data or (($skin_obs == 'windDir' or $skin_obs == 'windRose') and $getattr($get_time_span_from_context($context, $day, $week, $month, $year, $alltime, $yesterday), 'windSpeed').has_data) or $skin_obs in $get_software_obs #set global $partial_obs = $skin_obs #set global $diagram_index = $diagram_index #if $skin_obs == 'windRose' diff --git a/skins/weewx-wdc/lang/de.conf b/skins/weewx-wdc/lang/de.conf index 81c60d60..d4696b79 100644 --- a/skins/weewx-wdc/lang/de.conf +++ b/skins/weewx-wdc/lang/de.conf @@ -163,6 +163,11 @@ rainDur = Regendauer sunshineDur = Sonnenscheindauer + # weewx-GTS + GTS = GTS + seasonGDD = Wachstumsgradtage (Saison) + yearGDD = Wachstumsgradtage (Jahr) + [Texts] "Station Description" = "Aktuelle Wetterlage" "Almanac" = "Almanac" diff --git a/skins/weewx-wdc/lang/en.conf b/skins/weewx-wdc/lang/en.conf index 60837d4c..a812df03 100644 --- a/skins/weewx-wdc/lang/en.conf +++ b/skins/weewx-wdc/lang/en.conf @@ -160,6 +160,11 @@ rainDur = Rain duration sunshineDur = Sunshine duration + # weewx-GTS + GTS = GTS + seasonGDD = Growing degree days (Season) + yearGDD = Growing degree days (Year) + [Texts] "Station Description" = "Current Weather Conditions" diff --git a/skins/weewx-wdc/lang/it.conf b/skins/weewx-wdc/lang/it.conf index 42cf1835..144a105b 100644 --- a/skins/weewx-wdc/lang/it.conf +++ b/skins/weewx-wdc/lang/it.conf @@ -158,6 +158,11 @@ rainDur = Durata della Pioggia sunshineDur = Durata del Sole + # weewx-GTS + GTS = GTS + seasonGDD = Gradi giorno crescenti (Stagione) + yearGDD = Gradi giorno crescenti (Anno) + [Texts] "Station Description" = "Condizione Meteo Attuali" "Almanac" = "Almanacco" diff --git a/skins/weewx-wdc/lang/nl.conf b/skins/weewx-wdc/lang/nl.conf index d00d48e0..f5ecb4b4 100644 --- a/skins/weewx-wdc/lang/nl.conf +++ b/skins/weewx-wdc/lang/nl.conf @@ -38,7 +38,7 @@ heatindex = Hitte Index inDewpoint = Dauwpunt Binnen inHumidity = Luchtvochtigheid Binnen - inTemp = Temperatuur Binnen + inTemp = Temperatuur Binnen interval = Interval leafTemp1 = Blad Temperatuur1 leafTemp2 = Blad Temperatuur2 @@ -160,6 +160,11 @@ rainDur = Duur regen sunshineDur = Zonuren + # weewx-GTS + GTS = GTS + seasonGDD = Groeiende graaddagen (Seizoen) + yearGDD = Groeiende graaddagen (Jaar) + [Texts] "Station Description" = "Huidige Weersomstandigheden" diff --git a/skins/weewx-wdc/skin.conf b/skins/weewx-wdc/skin.conf index c4058459..1ab2ae81 100644 --- a/skins/weewx-wdc/skin.conf +++ b/skins/weewx-wdc/skin.conf @@ -110,7 +110,7 @@ SKIN_VERSION = 3.3.0 # 'alternative' or 'classic'. layout = 'alternative' - # Date/Time localization for charts. Available locales: de-DE, en-US, en-GB, it-IT. + # Date/Time localization for charts. Available locales: de-DE, en-US, en-GB, it-IT, nl-NL. # If not set, the value from weewx.conf (reports section) will be used. If lang = en, then en-US will be used (sorry GB!). #date_time_locale = en-US diff --git a/skins/weewx-wdc/src/js/diagrams/d3/line.tsx b/skins/weewx-wdc/src/js/diagrams/d3/line.tsx index a345be70..647bfdf3 100644 --- a/skins/weewx-wdc/src/js/diagrams/d3/line.tsx +++ b/skins/weewx-wdc/src/js/diagrams/d3/line.tsx @@ -75,6 +75,10 @@ export const D3LineDiagram: FunctionComponent = ( return a.x - b.x; }); + if (combinedData.length === 0) { + return <>; + } + // Group data by unit. const dataGroupedByUnit: { unit: string; data: Datum[] }[] = [ { unit: props.unit[0], data: props.data[0].data }, @@ -610,6 +614,10 @@ export const D3LineDiagram: FunctionComponent = ( const d0 = props.data[index].data[i - 1]; const d1 = props.data[index].data[i]; + if (!d0 || !d1) { + return; + } + const d: Datum = x0 - d0.x * 1000 > d1.x * 1000 - x0 ? d1 : d0; values = [...values, d];