From 4dd390cb20404e03b6221c25af26fe3237cc3c8a Mon Sep 17 00:00:00 2001 From: John Kline Date: Tue, 25 Aug 2020 07:26:10 -0700 Subject: [PATCH] v2.4.0.b9: Add support for the following icons in WU forecasts: tstms, hail, dirzzle, sleet, frzngdrzl, frzngrain, flurries. --- bin/user/forecast.py | 53 +++++++++++++++++++++++++++++++++++--------- install.py | 2 +- readme.txt | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/bin/user/forecast.py b/bin/user/forecast.py index 729fa08..a14e0db 100644 --- a/bin/user/forecast.py +++ b/bin/user/forecast.py @@ -555,7 +555,7 @@ from weewx.engine import StdService from weewx.cheetahgenerator import SearchList -VERSION = "3.4.0b8" +VERSION = "3.4.0b9" if weewx.__version__ < "4": raise weewx.UnsupportedFeature( @@ -2561,16 +2561,34 @@ def create_records_from_five_day(fc, issued_ts, now, location=None): precip_type = fc['daypart'][0]['precipType'][daypart_index] precip_chance = fc['daypart'][0]['precipChance'][daypart_index] if precip_chance > 0 and (precip_type == 'rain' or precip_type == 'snow'): - if precip_chance < 30: - r[precip_type] = 'S' - elif precip_chance < 60: - r[precip_type] = 'C' - elif precip_chance < 80: - r[precip_type] = 'L' - elif precip_chance < 100: - r[precip_type] = 'O' - else: - r[precip_type] = 'D' + r[precip_type] = WUForecast.code_from_precip_chance(precip_chance) + # ThunderStorms + #wu_tstms_dict = { + # 0: None, + # 1: 'S', + # 2: 'C', + # 3: 'L', + # 4: 'O', + # 5: 'D'} + #thunder_index = fc['daypart'][0]['thunderIndex'][daypart_index] + #if thunder_index > 0: + # r['tstms'] = wu_tstms_dict[thunder_index] + # Look for other precip in iconCode + icon_code = fc['daypart'][0]['iconCode'][daypart_index] + if icon_code == 4 or icon_code == 37 or icon_code == 38 or icon_code == 47: + r['tstms'] = WUForecast.code_from_precip_chance(precip_chance) + if icon_code == 4 or icon_code == 17 or icon_code == 35: + r['hail'] = WUForecast.code_from_precip_chance(precip_chance) + if icon_code == 9: + r['drizzle'] = WUForecast.code_from_precip_chance(precip_chance) + if icon_code == 6 or icon_code == 7 or icon_code == 18: + r['sleet'] = WUForecast.code_from_precip_chance(precip_chance) + if icon_code == 8: + r['frzngdrzl'] = WUForecast.code_from_precip_chance(precip_chance) + if icon_code == 10: + r['frzngrain'] = WUForecast.code_from_precip_chance(precip_chance) + if icon_code == 13: + r['flurries'] = WUForecast.code_from_precip_chance(precip_chance) if half_day_index == 0: r['tempMax'] = Forecast.str2float( 'temperatureMax', fc['temperatureMax'][half_day_index], WU_KEY) @@ -2717,6 +2735,19 @@ def create_records_from_five_day(fc, issued_ts, now, location=None): '24': 'BS', } + @staticmethod + def code_from_precip_chance(precip_chance): + if precip_chance < 30: + return 'S' + elif precip_chance < 60: + return 'C' + elif precip_chance < 80: + return 'L' + elif precip_chance < 100: + return 'O' + else: + return 'D' + @staticmethod def str2pc(s): """parse a wu wx string for the precipitation type and likeliehood diff --git a/install.py b/install.py index 332d592..a2206be 100644 --- a/install.py +++ b/install.py @@ -10,7 +10,7 @@ def loader(): class ForecastInstaller(ExtensionInstaller): def __init__(self): super(ForecastInstaller, self).__init__( - version="3.4.0b8", + version="3.4.0b9", name='forecast', description='Generate and display weather and tide forecasts.', author="Matthew Wall", diff --git a/readme.txt b/readme.txt index d938280..f94f915 100644 --- a/readme.txt +++ b/readme.txt @@ -78,7 +78,7 @@ Installation instructions: 1) run the installer: -wee_extension --install weewx-forecast-3.4.0b8.zip +wee_extension --install weewx-forecast-3.4.0b9.zip 2) modify weewx.conf for your location: