Bug: Incorrect Calculation for Consecutive Days with Rain Record
First step I have debugged the skin and believe I have identified the source of the issue but confirmation would be more than welcome. The bug appears to be in the SQL query used to calculate consecutive rainy days within the belchertown.py script.
Describe the bug
The "Consecutive Days with Rain" record on the records page displays a highly inflated and incorrect value (e.g., 275 days). This value is not supported by the data in the archive_day_rain database table. The issue seems to be caused by a flawed SQL query that prevents the counter from resetting.
Link to your website (IMPORTANT) https://meteosaintsulpice.fr/records/
Version of the skin you're using 1.3.1
To Reproduce Steps to reproduce the behavior: Go to the records page of the Belchertown skin. Locate the "Rain Records" section. Observe the "Consecutive Days with Rain" value.
Expected behavior
The "Consecutive Days with Rain" value should accurately reflect the longest streak of days with rainfall, as calculated from the archive_day_rain table. The displayed number should be significantly smaller and correct, corresponding to actual data.
Screenshots
Device Information (please complete the following information):
Additional context
The issue lies within the SQL query used in the belchertown.py script for the at_rain_query variable. The WHERE count > 0 clause in the query causes the code to only process days with at least one observation, effectively skipping days with no data or no rain. This prevents the Python logic from resetting the consecutive day counter, leading to the inflated value.
HELP WANTED I believe the fix is to remove the WHERE count > 0 clause from the SQL query in the belchertown.py script. The original query is:
at_rain_query = wx_manager.genSql(
"SELECT dateTime, ROUND( sum, 2 ) FROM archive_day_rain WHERE count > 0;"
)
The corrected query should be:
at_rain_query = wx_manager.genSql(
"SELECT dateTime, ROUND( sum, 2 ) FROM archive_day_rain;"
)
I am unsure if I have 100% understood how belchertown.py works, so I am not proposing a pull request at this time. This correction is my best guess, and it appears to work on my side. Testing on my local webpage decreased the "Consecutive Days Without Rain" record from 275 days to 23 days, which seems more realistic.
Note: My database may have several holes in 2019. I developed my weather station myself and it experienced a few crashes during that time before I was able to perform a hardware reset. This could explain the missing data. Also if I remember correctly, in the past, it did not send a rain measurement (including a 0 value) during periods of no rain to save battery power. This could have created gaps in my database.
Nevertheless, I think it may worth to make belchertown.py handle this (hole in database can happen).
One last thought: my fix might not be completely accurate for consecutive days with rain and consecutive days without rain due to data gaps.
The original script's logic implicitly assumed that any data gap was part of a rainy streak, because the counter was never reset. My proposed correction now assumes the opposite, that a data gap breaks a streak.
While my fix corrects a bug in the logic, the true consecutive count for both scenarios remains unknown for periods where data is missing. My solution provides a more conservative and arguably more correct assumption (my opinion: you may disagree 😄 , but it's still important to note that the data itself is incomplete for those periods)
It might also be added a key in skin.conf, like:
consider_db_gap_as_rainy = 0 or 1
This would let users in different climates (e.g., rainy vs. arid zones) decide how the script should handle data gaps.
But it's maybe overcomplicated something not that critical?
This repo isn't being actively maintained anymore. I'm trying to keep up with bug fixes on my own fork, https://github.com/uajqq/weewx-belchertown-new. If you open the issue over there, I can take a look. You might want to install that version first, to see if the bug hasn't already been fixed somehow.
Done: https://github.com/uajqq/weewx-belchertown-new/issues/23
I think the issue should be same (I still see the WHERE count > 0 )
But as explained in the issue, I think there is no perfect solution but maybe better or less worse proposal 😄 . I'm open for discussion
I've just caught up with this. The solution I would favour is to end the run of wet or dry days whenever there is a gap in the data. By that I mean a complete day when there are no rain readings. This can occur for two reasons: 1 The weather station is off-line and has sent no data 2 The weather station is sending data but the rain gauge is not working. I think this is better than making decisions about whether the empty day should be wet or dry based on some assumptions about the characteristics of the location, previous days etc... I'm working on a PR if you are interested. Michael
If you do put in a PR, I would recommend you put it in on my fork https://github.com/uajqq/weewx-belchertown-new so I can merge it -- this repo is no longer maintained.