From 4cff008215af95869f904b94b34fbebc6b9eef18 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:20:27 +0100 Subject: [PATCH 1/3] Fix wild RainRate values on start-up --- CumulusMX/Cumulus.cs | 12 +++++++++++- CumulusMX/DataEditor.cs | 6 +++--- CumulusMX/Properties/AssemblyInfo.cs | 6 +++--- CumulusMX/StationSettings.cs | 1 + CumulusMX/WeatherStation.cs | 17 +++++++++-------- CumulusMX/webtags.cs | 4 ++-- Updates.txt | 7 +++++++ 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/CumulusMX/Cumulus.cs b/CumulusMX/Cumulus.cs index 4c13233f..1bd5fef6 100644 --- a/CumulusMX/Cumulus.cs +++ b/CumulusMX/Cumulus.cs @@ -4151,7 +4151,16 @@ private void ReadIniFile() RecordsBeganDate = ini.GetValue("Station", "StartDate", DateTime.Now.ToLongDateString()); - LogMessage("Cumulus start date: " + RecordsBeganDate); + try + { + RecordsBeganDateTime = DateTime.Parse(RecordsBeganDate); + } + catch (Exception ex) + { + LogErrorMessage($"Error parsing the RecordsBegan date: {ex.Message}"); + } + + LogMessage($"Cumulus start date: {RecordsBeganDate} Parsed: {RecordsBeganDateTime:yyyy-MM-dd}" ); ImetOptions.WaitTime = ini.GetValue("Station", "ImetWaitTime", 500); ImetOptions.ReadDelay = ini.GetValue("Station", "ImetReadDelay", 500); @@ -6778,6 +6787,7 @@ private void ReadStringsFile() //public bool EWduplicatecheck { get; set; } public string RecordsBeganDate { get; set; } + public DateTime RecordsBeganDateTime { get; set; } //public bool EWdisablecheckinit { get; set; } diff --git a/CumulusMX/DataEditor.cs b/CumulusMX/DataEditor.cs index 517d272b..9257f23d 100644 --- a/CumulusMX/DataEditor.cs +++ b/CumulusMX/DataEditor.cs @@ -664,7 +664,7 @@ internal string GetRecordsLogFile(string recordType) switch (recordType) { case "alltime": - datefrom = DateTime.Parse(cumulus.RecordsBeganDate); + datefrom = cumulus.RecordsBeganDateTime; break; case "thisyear": var now = DateTime.Now; @@ -675,7 +675,7 @@ internal string GetRecordsLogFile(string recordType) datefrom = new DateTime(now.Year, now.Month, 1).Date; break; default: - datefrom = DateTime.Parse(cumulus.RecordsBeganDate); + datefrom = cumulus.RecordsBeganDateTime; break; } var dateto = DateTime.Now.Date; @@ -2158,7 +2158,7 @@ internal string GetMonthlyRecLogFile() const string monthFormat = "MMM yyyy"; var json = new StringBuilder("{", 25500); - var datefrom = DateTime.Parse(cumulus.RecordsBeganDate); + var datefrom = cumulus.RecordsBeganDateTime; datefrom = new DateTime(datefrom.Year, datefrom.Month, 1, 0, 0, 0); var dateto = DateTime.Now; dateto = new DateTime(dateto.Year, dateto.Month, 1, 0, 0, 0); diff --git a/CumulusMX/Properties/AssemblyInfo.cs b/CumulusMX/Properties/AssemblyInfo.cs index c72994b7..8588e746 100644 --- a/CumulusMX/Properties/AssemblyInfo.cs +++ b/CumulusMX/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Cumulus MX")] -[assembly: AssemblyDescription("Version 3.22.0 - Build 3211")] +[assembly: AssemblyDescription("Version 3.22.1 - Build 3212")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Cumulus MX")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.22.0.3211")] -[assembly: AssemblyFileVersion("3.22.0.3211")] +[assembly: AssemblyVersion("3.22.1.3212")] +[assembly: AssemblyFileVersion("3.22.1.3212")] diff --git a/CumulusMX/StationSettings.cs b/CumulusMX/StationSettings.cs index 877fac6a..1b30fa56 100644 --- a/CumulusMX/StationSettings.cs +++ b/CumulusMX/StationSettings.cs @@ -1295,6 +1295,7 @@ internal string UpdateConfig(IHttpContext context) try { cumulus.RecordsBeganDate = settings.general.advanced.recsbegandate; + cumulus.RecordsBeganDateTime = DateTime.Parse(cumulus.RecordsBeganDate); } catch (Exception ex) { diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 5a93ba7f..51224deb 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -6275,6 +6275,7 @@ public void DoTrendValues(DateTime ts, bool rollover = false) { double trendval, retVal; List retVals; + List retDbl; var recTs = ts; // if this is the special case of rollover processing, we want the High today record to on the previous day at 23:59 or 08:59 @@ -6405,16 +6406,15 @@ public void DoTrendValues(DateTime ts, bool rollover = false) try { - retVal = RecentDataDb.ExecuteScalar("select raincounter from RecentData where Timestamp >= ? order by Timestamp limit 1", ts.AddMinutes(-5.5)); + retDbl = RecentDataDb.Query("select raincounter from RecentData where Timestamp >= ? order by Timestamp limit 1", ts.AddMinutes(-5.5)); - if (Raincounter < retVal) + if (retDbl.Count != 1 || Raincounter < retDbl[0]) { RainRate = 0; } else { - - var raindiff = Math.Round(Raincounter - retVal, cumulus.RainDPlaces); + var raindiff = Math.Round(Raincounter - retDbl[0], cumulus.RainDPlaces); //cumulus.LogMessage("raindiff = " + raindiff); var timediffhours = 1.0 / 12.0; @@ -6431,6 +6431,7 @@ public void DoTrendValues(DateTime ts, bool rollover = false) { // ignore cumulus.LogSpikeRemoval("Max rainfall rate spike value exceed"); + cumulus.LogSpikeRemoval($"Rate value = {ConvertUserRainToMM(tempRainRate):F2} SpikeMaxRainRate = {cumulus.Spike.MaxRainRate:F2}"); lastSpikeRemoval = DateTime.Now; cumulus.SpikeAlarm.LastError = $"Max rainfall rate greater than spike value - Value={tempRainRate:F1}"; cumulus.SpikeAlarm.Triggered = true; @@ -6479,17 +6480,17 @@ public void DoTrendValues(DateTime ts, bool rollover = false) // calculate and display rainfall in last 24 hour try - { - retVal = RecentDataDb.ExecuteScalar("select raincounter from RecentData where Timestamp >= ? order by Timestamp limit 1", ts.AddDays(-1)); + { + retDbl = RecentDataDb.Query("select raincounter from RecentData where Timestamp >= ? order by Timestamp limit 1", ts.AddDays(-1)); - if (Raincounter < retVal) + if (retDbl.Count != 1 || Raincounter < retDbl[0]) { RainLast24Hour = 0; } else { - trendval = Math.Round(Raincounter - retVal, cumulus.RainDPlaces); + trendval = Math.Round(Raincounter - retDbl[0], cumulus.RainDPlaces); if (trendval < 0) { diff --git a/CumulusMX/webtags.cs b/CumulusMX/webtags.cs index 8cf5a24d..862474aa 100644 --- a/CumulusMX/webtags.cs +++ b/CumulusMX/webtags.cs @@ -2486,13 +2486,13 @@ private string TagThumL(Dictionary tagParams) private string Tagrecordsbegandate(Dictionary tagParams) { - var begandate = DateTime.Parse(cumulus.RecordsBeganDate); + var begandate = cumulus.RecordsBeganDateTime; return GetFormattedDateTime(begandate, "dd MMMM yyyy", tagParams); } private string TagDaysSinceRecordsBegan(Dictionary tagParams) { - var begandate = DateTime.Parse(cumulus.RecordsBeganDate); + var begandate = cumulus.RecordsBeganDateTime; return (DateTime.Now - begandate).Days.ToString(); } diff --git a/Updates.txt b/Updates.txt index 01a2bd6b..3ad8e141 100644 --- a/Updates.txt +++ b/Updates.txt @@ -1,3 +1,10 @@ +3.22.1 - b3212 +—————————————— +Fixed +- NOAA Reports pages not working in all locales +- RainRate sometimes giving wild values on start-up + + 3.22.0 - b3211 —————————————— New From 86299d8e86adbbeabe6e3fd2d77127a9e223ca60 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:57:41 +0100 Subject: [PATCH 2/3] tidy --- CumulusMX/WeatherStation.cs | 1 - Updates.txt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 51224deb..a750b31d 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -6489,7 +6489,6 @@ public void DoTrendValues(DateTime ts, bool rollover = false) } else { - trendval = Math.Round(Raincounter - retDbl[0], cumulus.RainDPlaces); if (trendval < 0) diff --git a/Updates.txt b/Updates.txt index 3ad8e141..776c7511 100644 --- a/Updates.txt +++ b/Updates.txt @@ -2,7 +2,7 @@ —————————————— Fixed - NOAA Reports pages not working in all locales -- RainRate sometimes giving wild values on start-up +- RainRate sometimes giving wild values on start-up when CMX calculates rate 3.22.0 - b3211 @@ -16,7 +16,6 @@ Changed - The web tag <#TimeJavaScript> now provides a value truncated to the current second - 3.21.2 - b3206 —————————————— Fixed From 6b807c0a2c4b70780b6f691fef8a02d0e827b650 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Sat, 15 Oct 2022 11:18:52 +0100 Subject: [PATCH 3/3] updates.txt --- Updates.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Updates.txt b/Updates.txt index 776c7511..38faf694 100644 --- a/Updates.txt +++ b/Updates.txt @@ -3,6 +3,7 @@ Fixed - NOAA Reports pages not working in all locales - RainRate sometimes giving wild values on start-up when CMX calculates rate +- Amusing typo in default web site today/yesterday page 3.22.0 - b3211