Skip to content

Commit 796d20e

Browse files
authored
Merge pull request #14 from mcrossley/master
1.4.1
2 parents 0b3e2d7 + 236b1f9 commit 796d20e

6 files changed

Lines changed: 53 additions & 40 deletions

File tree

CreateMissing.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<AssemblyVersion>1.4.0.4</AssemblyVersion>
6-
<FileVersion>1.4.0.4</FileVersion>
7-
<Version></Version>
5+
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
6+
<FileVersion>$(PackageVersion)</FileVersion>
7+
<Version>1.4.1</Version>
88
<StartupObject>CreateMissing.Program</StartupObject>
99
<TargetFramework>net48</TargetFramework>
1010
<Authors>Mark Crossley</Authors>

Cumulus.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using CumulusMX;
22
using System;
3-
using System.Collections.Generic;
43
using System.Globalization;
5-
using System.Text;
64

75
namespace CreateMissing
86
{

DayFile.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ public void LoadDayFile()
6363
using (var sr = new StreamReader(dayFileName))
6464
{
6565
var lastDate = DateTime.MinValue;
66+
6667
do
6768
{
6869
try
6970
{
7071
// process each record in the file
7172

73+
7274
linenum++;
7375
string Line = sr.ReadLine();
7476
var newRec = ParseDayFileRec(Line);
@@ -79,7 +81,7 @@ public void LoadDayFile()
7981
Program.LogMessage($"LoadDayFile: Error - Date is out of order at line {linenum} of {dayFileName}, '{newRec.Date.ToString("dd" + DateSep + "MM" + DateSep + "yy")}'");
8082
Console.WriteLine();
8183
Program.LogConsole($"Error, date is out of order at line {linenum} of {dayFileName}, '{newRec.Date.ToString("dd" + DateSep + "MM" + DateSep + "yy")}'", ConsoleColor.Red);
82-
Environment.Exit(3);
84+
errorCount++;
8385
}
8486

8587
// sanity check if this date has already been added
@@ -94,7 +96,10 @@ public void LoadDayFile()
9496
Environment.Exit(4);
9597
}
9698

97-
DayfileRecs.Add(newRec);
99+
if (errorCount == 0)
100+
{
101+
DayfileRecs.Add(newRec);
102+
}
98103

99104
lastDate = newRec.Date;
100105

@@ -114,14 +119,20 @@ public void LoadDayFile()
114119
Environment.Exit(5);
115120
}
116121
}
117-
} while (!(sr.EndOfStream || errorCount >= 20));
122+
} while (!sr.EndOfStream);
118123
}
119124
}
120125
catch (Exception e)
121126
{
122127
Program.LogMessage($"LoadDayFile: Error at line {linenum} of {dayFileName} : {e.Message}");
123128
Program.LogMessage("Please edit the file to correct the error");
124129
}
130+
131+
if (errorCount > 0)
132+
{
133+
Environment.Exit(3);
134+
}
135+
125136
Program.LogMessage($"LoadDayFile: Loaded {addedEntries} entries to the daily data list");
126137
Console.WriteLine($"Loaded {addedEntries} entries to the daily data list");
127138
}

Program.cs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
463463
rain = 0;
464464
}
465465

466-
AddLastHoursRainEntry(entrydate, rain, ref rain1hLog, ref rain24hLog);
466+
AddLastHoursRainEntry(entrydate, raincounter, ref rain1hLog, ref rain24hLog);
467467

468468
lastentryrain = rain;
469469

@@ -505,7 +505,6 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
505505
// Special case, the last record of the day is only used for averaging and summation purposes
506506
if (entrydate != endTime)
507507
{
508-
509508
// current gust
510509
idx = 14;
511510
if (st.Count > idx && double.TryParse(st[idx], out valDbl) && valDbl > rec.HighGust)
@@ -716,23 +715,24 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
716715
rec.HighRainRateTime = entrydate;
717716
}
718717
// total rain - just take the last value - the user may have edited the value during the day
719-
rec.TotalRain = raintoday;
718+
rec.TotalRain = raintoday * cumulus.CalibRainMult;
720719

721720
// add last hours rain - the first record of the day has already been added as the last record of the previous day
722721
if (entrydate > startTime)
723722
{
724-
AddLastHoursRainEntry(entrydate, totalRainfall + raintoday, ref rain1hLog, ref rain24hLog);
723+
AddLastHoursRainEntry(entrydate, raincounter, ref rain1hLog, ref rain24hLog);
725724
}
726725

727726
// rainfall in last hour
728-
rainThisHour = Math.Round(rain1hLog.Last().Raincounter - rain1hLog.Peek().Raincounter, cumulus.Units.RainDPlaces);
727+
rainThisHour = Math.Round((rain1hLog.Last().Raincounter - rain1hLog.Peek().Raincounter) * cumulus.CalibRainMult, cumulus.Units.RainDPlaces);
729728
if (rainThisHour > rec.HighHourlyRain)
730729
{
731730
rec.HighHourlyRain = rainThisHour;
732731
rec.HighHourlyRainTime = entrydate;
733732
}
734733

735-
rainLast24Hr = Math.Round(rain24hLog.Last().Raincounter - rain24hLog.Peek().Raincounter, cumulus.Units.RainDPlaces);
734+
// rainfall in last 24 hours
735+
rainLast24Hr = Math.Round((rain24hLog.Last().Raincounter - rain24hLog.Peek().Raincounter) * cumulus.CalibRainMult, cumulus.Units.RainDPlaces);
736736
if (rainLast24Hr > rec.HighRain24h)
737737
{
738738
rec.HighRain24h = rainLast24Hr;
@@ -825,43 +825,45 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
825825

826826
// logging format changed on with C1 v1.9.3 b1055 in Dec 2012
827827
// before that date the 00:00 log entry contained the rain total for the day before and the next log entry was reset to zero
828-
// after that build the total was reset to zero in the entry
828+
// after that build the total was reset to zero in the 00:00 entry
829829
// messy!
830830
// no final rainfall entry after this date (approx). The best we can do is add in the increase in rain counter during this preiod
831-
var rolloverRain = double.Parse(st[9]); // 9
832-
var rolloverRaincounter = double.Parse(st[11]); // 11
831+
var rolloverRain = double.Parse(st[9]); // 9 - rain so far today
832+
var rolloverRaincounter = double.Parse(st[11]); // 11 - rain counter
833+
834+
rec.TotalRain += (rolloverRaincounter - lastentrycounter) * cumulus.CalibRainMult;
833835

834-
if (rolloverRain > 0)
835-
{
836-
raintoday = rolloverRain;
837-
}
838-
if (rolloverRain == 0 && (raincounter - lastentrycounter > 0) && (raincounter - lastentrycounter < counterJumpTooBig))
839-
{
840-
raintoday += (raincounter - lastentrycounter) * cumulus.CalibRainMult;
841-
}
836+
837+
//if (rolloverRain > 0)
838+
//{
839+
// raintoday = lastentryrain + rolloverRain;
840+
//}
841+
//if (rolloverRain == 0 && (raincounter - lastentrycounter > 0) && (raincounter - lastentrycounter < counterJumpTooBig))
842+
//{
843+
// raintoday += (raincounter - lastentrycounter) * cumulus.CalibRainMult;
844+
//}
842845

843846
// add last hours rain for this last record.
844-
AddLastHoursRainEntry(entrydate, totalRainfall + raintoday, ref rain1hLog, ref rain24hLog);
847+
AddLastHoursRainEntry(entrydate, rolloverRaincounter, ref rain1hLog, ref rain24hLog);
845848

846849
// rainfall in last hour
847-
rainThisHour = rain1hLog.Last().Raincounter - rain1hLog.Peek().Raincounter;
850+
rainThisHour = Math.Round((rain1hLog.Last().Raincounter - rain1hLog.Peek().Raincounter) * cumulus.CalibRainMult, cumulus.Units.RainDPlaces);
848851
if (rainThisHour > rec.HighHourlyRain)
849852
{
850853
rec.HighHourlyRain = rainThisHour;
851854
rec.HighHourlyRainTime = entrydate;
852855
}
853856

854-
rainLast24Hr = rain24hLog.Last().Raincounter - rain24hLog.Peek().Raincounter;
857+
rainLast24Hr = Math.Round((rain24hLog.Last().Raincounter - rain24hLog.Peek().Raincounter) * cumulus.CalibRainMult, cumulus.Units.RainDPlaces);
855858
if (rainLast24Hr > rec.HighRain24h)
856859
{
857860
rec.HighRain24h = rainLast24Hr;
858-
rec.HighRain24hTime = entrydate;
861+
rec.HighRain24hTime = entrydate.AddMinutes(-1); // we want the high rate for the day to be at the end of the day we are closing
859862
}
860863

861-
// total rain - just take the last value - the user may have edited the value during the day
862-
rec.TotalRain = raintoday;
863-
864-
totalRainfall += raintoday;
864+
// total rain
865+
totalRainfall += rec.TotalRain;
866+
lastentrycounter = raincounter;
865867

866868
// flag we are done with this record
867869
finished = true;
@@ -920,7 +922,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
920922
return rec;
921923
}
922924

923-
return null;
925+
//return null;
924926
}
925927
if (fileDate > date)
926928
{
@@ -1024,10 +1026,10 @@ private static Dayfilerec GetSolarDayRecFromMonthly(DateTime date, Dayfilerec re
10241026
{
10251027
// process each record in the file
10261028
// first a sanity check for an empty line!
1027-
if (string.IsNullOrWhiteSpace(CurrentLogLines[CurrentLogLineNum]))
1029+
if (string.IsNullOrWhiteSpace(CurrentLogLines[CurrentSolarLogLineNum]))
10281030
{
1029-
CurrentLogLineNum++;
1030-
LogMessage($"Solar: Error at line {CurrentLogLineNum}, an empty line was detected!");
1031+
CurrentSolarLogLineNum++;
1032+
LogMessage($"Solar: Error at line {CurrentSolarLogLineNum}, an empty line was detected!");
10311033
continue;
10321034
}
10331035

@@ -1367,7 +1369,7 @@ private static void AddLastHoursRainEntry(DateTime ts, double rain, ref Queue<La
13671369
h24Queue.Dequeue();
13681370
}
13691371
}
1370-
}
1372+
}
13711373

13721374

13731375
class LastHourRainLog

Updates.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.4.1
2+
—————
3+
- Fix daily rainfall bug in 1.4.0
4+
15
1.4.0
26
—————
37
- Change to AnyCPU - will now run as 64 bit process on 64 bit OS

Utils.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using CumulusMX;
22
using System;
3-
using System.Collections.Generic;
43
using System.IO;
5-
using System.Text;
64
using System.Text.RegularExpressions;
75

86
namespace CreateMissing

0 commit comments

Comments
 (0)