Skip to content

Commit

Permalink
Fix locale issues reading log files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Crossley committed Jun 20, 2024
1 parent 5614bb3 commit 0a7113d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CreateMissing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<FileVersion>$(PackageVersion)</FileVersion>
<Version>2.0.0.0002</Version>
<Version>2.0.1.0003</Version>
<StartupObject>CreateMissing.Program</StartupObject>
<TargetFramework>net8.0</TargetFramework>
<Authors>Mark Crossley</Authors>
Expand Down
24 changes: 24 additions & 0 deletions DayFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ private static string RecToCsv(Dayfilerec rec)
strb.Append(datestring + sep);

if (rec.HighGust == -9999)
{
Program.LogMessage("Mandatory value High Gust missing, skipping this day");
return null;
//strb.Append("0.0" + listsep + "0" + listsep + "00:00" + listsep)
}
else
{
strb.Append(rec.HighGust.ToString(Program.cumulus.WindFormat, inv) + sep);
Expand All @@ -258,58 +261,79 @@ private static string RecToCsv(Dayfilerec rec)
}

if (rec.LowTemp == 9999)
{
Program.LogMessage("Mandatory value Low Temp missing, skipping this day");
return null;
//strb.Append("0.0" + listsep + "00:00" + listsep)
}
else
{
strb.Append(rec.LowTemp.ToString(Program.cumulus.TempFormat, inv) + sep);
strb.Append(rec.LowTempTime.ToString("HH:mm", inv) + sep);
}

if (rec.HighTemp == -9999)
{
Program.LogMessage("Mandatory value High Temp missing, skipping this day");
return null;
//strb.Append("0.0" + listsep + "00:00" + listsep)
}
else
{
strb.Append(rec.HighTemp.ToString(Program.cumulus.TempFormat, inv) + sep);
strb.Append(rec.HighTempTime.ToString("HH:mm", inv) + sep);
}

if (rec.LowPress == 9999)
{
Program.LogMessage("Mandatory value Low Press missing, skipping this day");
return null;
//strb.Append("0.0" + listsep + "00:00" + listsep)
}
else
{
strb.Append(rec.LowPress.ToString(Program.cumulus.PressFormat, inv) + sep);
strb.Append(rec.LowPressTime.ToString("HH:mm", inv) + sep);
}

if (rec.HighPress == -9999)
{
Program.LogMessage("Mandatory value High Press missing, skipping this day");
return null;
//strb.Append("0.0" + listsep + "00:00" + listsep)
}
else
{
strb.Append(rec.HighPress.ToString(Program.cumulus.PressFormat, inv) + sep);
strb.Append(rec.HighPressTime.ToString("HH:mm", inv) + sep);
}

if (rec.HighRainRate == -9999)
{
Program.LogMessage("Mandatory value High Rain Rate missing, skipping this day");
return null;
//strb.Append("0.0" + listsep + "00:00" + listsep)
}
else
{
strb.Append(rec.HighRainRate.ToString(Program.cumulus.RainFormat, inv) + sep);
strb.Append(rec.HighRainRateTime.ToString("HH:mm", inv) + sep);
}

if (rec.TotalRain == -9999)
{
Program.LogMessage("Mandatory value Total Rain missing, skipping this day");
return null;
//strb.Append("0.0" + listsep)
}
else
strb.Append(rec.TotalRain.ToString(Program.cumulus.RainFormat, inv) + sep);

if (rec.AvgTemp == -9999)
{
Program.LogMessage("Mandatory value Avg Temp missing, skipping this day");
strb.Append(sep);
}
else
strb.Append(rec.AvgTemp.ToString(Program.cumulus.TempFormat, inv) + sep);

Expand Down
46 changes: 25 additions & 21 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -33,7 +34,7 @@ static class Program
static void Main()
{
#if DEBUG
//Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL")
//System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("sl-SL")
#endif
TextWriterTraceListener myTextListener = new TextWriterTraceListener($"MXdiags{Path.DirectorySeparatorChar}CreateMissing-{DateTime.Now:yyyyMMdd-HHmmss}.txt", "CMlog");
Trace.Listeners.Add(myTextListener);
Expand Down Expand Up @@ -83,6 +84,7 @@ static void Main()
Console.WriteLine("Exiting...");
Environment.Exit(1);
}

Console.WriteLine();

// Sanity check #2
Expand Down Expand Up @@ -313,6 +315,8 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
ChillHours = 0
};

var inv = CultureInfo.InvariantCulture;

var started = false;
var finished = false;
var recCount = 0;
Expand Down Expand Up @@ -435,8 +439,8 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
// after that build the total was reset to zero in the entry
// messy!
// no final rainfall entry after this date (approx). The best we can do is add in the increase in rain counter during this preiod
var rain = double.Parse(st[9]); // 9
var raincounter = double.Parse(st[11]); // 11
var rain = double.Parse(st[9], inv); // 9
var raincounter = double.Parse(st[11], inv); // 11

// we need to initalise the rain counter on the first record
if (rain1hLog.Count == 0)
Expand Down Expand Up @@ -482,16 +486,16 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
if (entrydate >= startTime && entrydate <= endTime)
{
recCount++;
var outsidetemp = double.Parse(st[++idx]); // 2
var hum = int.Parse(st[++idx]); // 3
var dewpoint = double.Parse(st[++idx]); // 4
var speed = double.Parse(st[++idx]); // 5
var gust = double.Parse(st[++idx]); // 6
var avgbearing = int.Parse(st[++idx]); // 7
var rainrate = double.Parse(st[++idx]); // 8
var raintoday = double.Parse(st[++idx]); // 9
var pressure = double.Parse(st[++idx]); // 10
var raincounter = double.Parse(st[++idx]); // 11
var outsidetemp = double.Parse(st[++idx], inv); // 2
var hum = int.Parse(st[++idx]); // 3
var dewpoint = double.Parse(st[++idx], inv); // 4
var speed = double.Parse(st[++idx], inv); // 5
var gust = double.Parse(st[++idx], inv); // 6
var avgbearing = int.Parse(st[++idx], inv); // 7
var rainrate = double.Parse(st[++idx], inv); // 8
var raintoday = double.Parse(st[++idx], inv); // 9
var pressure = double.Parse(st[++idx], inv); // 10
var raincounter = double.Parse(st[++idx], inv); // 11

if (!started)
{
Expand All @@ -506,12 +510,12 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
{
// current gust
idx = 14;
if (st.Count > idx && double.TryParse(st[idx], out valDbl) && valDbl > rec.HighGust)
if (st.Count > idx && double.TryParse(st[idx], inv, out valDbl) && valDbl > rec.HighGust)
{
rec.HighGust = valDbl;
rec.HighGustTime = entrydate;
idx = 24;
if (st.Count > idx && int.TryParse(st[idx], out valInt))
if (st.Count > idx && int.TryParse(st[idx], inv, out valInt))
{
rec.HighGustBearing = valInt;
}
Expand All @@ -522,7 +526,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
}
// low chill
idx = 15;
if (st.Count > idx && double.TryParse(st[idx], out valDbl) && valDbl < rec.LowWindChill)
if (st.Count > idx && double.TryParse(st[idx], inv, out valDbl) && valDbl < rec.LowWindChill)
{
rec.LowWindChill = valDbl;
rec.LowWindChillTime = entrydate;
Expand All @@ -539,7 +543,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
}
// hi heat
idx = 16;
if (st.Count > idx && double.TryParse(st[idx], out valDbl) && valDbl > rec.HighHeatIndex)
if (st.Count > idx && double.TryParse(st[idx], inv, out valDbl) && valDbl > rec.HighHeatIndex)
{
rec.HighHeatIndex = valDbl;
rec.HighHeatIndexTime = entrydate;
Expand All @@ -556,7 +560,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
}
// hi/low appt
idx = 21;
if (st.Count > idx && double.TryParse(st[idx], out valDbl))
if (st.Count > idx && double.TryParse(st[idx], inv, out valDbl))
{
if (valDbl > rec.HighAppTemp)
{
Expand Down Expand Up @@ -588,7 +592,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)

// hi/low feels like
idx = 27;
if (st.Count > idx && double.TryParse(st[idx], out valDbl))
if (st.Count > idx && double.TryParse(st[idx], inv, out valDbl))
{
if (valDbl > rec.HighFeelsLike)
{
Expand Down Expand Up @@ -619,7 +623,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)

// hi humidex
idx = 28;
if (st.Count > idx && double.TryParse(st[idx], out valDbl))
if (st.Count > idx && double.TryParse(st[idx], inv, out valDbl))
{
if (valDbl > rec.HighHumidex)
{
Expand Down Expand Up @@ -828,7 +832,7 @@ private static Dayfilerec GetDayRecFromMonthly(DateTime date)
// messy!
// no final rainfall entry after this date (approx). The best we can do is add in the increase in rain counter during this preiod
//var rolloverRain = double.Parse(st[9]); // 9 - rain so far today
var rolloverRaincounter = double.Parse(st[11]); // 11 - rain counter
var rolloverRaincounter = double.Parse(st[11], inv); // 11 - rain counter

rec.TotalRain += (rolloverRaincounter - lastentrycounter) * cumulus.CalibRainMult;

Expand Down

0 comments on commit 0a7113d

Please sign in to comment.