space fixing and switch loop changed a little

This commit is contained in:
atef 2023-12-18 08:14:35 +01:00
parent b13ff6efbe
commit 56d75a3e6c
1 changed files with 9 additions and 10 deletions

View File

@ -29,7 +29,7 @@ public static class Aggregator
{ {
try try
{ {
AggregatedData hourlyAggregatedData=CreateAverage("LogDirectory",DateTime.Now.AddHours(-1).ToUnixTime(),DateTime.Now.ToUnixTime()); AggregatedData hourlyAggregatedData = CreateAverage("LogDirectory",DateTime.Now.AddHours(-1).ToUnixTime(),DateTime.Now.ToUnixTime());
hourlyAggregatedData.Save("HourlyData"); hourlyAggregatedData.Save("HourlyData");
} }
catch (Exception e) catch (Exception e)
@ -63,7 +63,7 @@ public static class Aggregator
{ {
try try
{ {
AggregatedData dailyAggregatedData=CreateAverage("HourlyData",DateTime.Now.AddDays(-1).ToUnixTime(),DateTime.Now.ToUnixTime()); AggregatedData dailyAggregatedData = CreateAverage("HourlyData",DateTime.Now.AddDays(-1).ToUnixTime(),DateTime.Now.ToUnixTime());
dailyAggregatedData.Save("DailyData"); dailyAggregatedData.Save("DailyData");
} }
catch (Exception e) catch (Exception e)
@ -74,10 +74,10 @@ public static class Aggregator
} }
} }
private static AggregatedData CreateAverage(string myDirectory,long afterTimestamp,long beforeTimestamp) private static AggregatedData CreateAverage(String myDirectory, Int64 afterTimestamp, Int64 beforeTimestamp)
{ {
// Get all CSV files in the specified directory // Get all CSV files in the specified directory
var csvFiles = Directory.GetFiles(myDirectory, "*.csv"); var csvFiles = Directory.GetFiles(myDirectory, "*.csv");
var socAverage = new List<Double>(); var socAverage = new List<Double>();
var pvPowerAverage = new List<Double>(); var pvPowerAverage = new List<Double>();
var batteryPowerAverage = new List<Double>(); var batteryPowerAverage = new List<Double>();
@ -102,7 +102,6 @@ public static class Aggregator
var line = reader.ReadLine(); var line = reader.ReadLine();
var lines = line?.Split(';'); var lines = line?.Split(';');
// Assuming there are always three columns (variable name and its value) // Assuming there are always three columns (variable name and its value)
if (lines is { Length: 3 }) if (lines is { Length: 3 })
{ {
@ -112,15 +111,15 @@ public static class Aggregator
{ {
switch (variableName) switch (variableName)
{ {
case var _ when variableName is "/Battery/Soc" or "/AvgSoc" : case "/Battery/Soc" or "/AvgSoc":
socAverage.Add(value); socAverage.Add(value);
break; break;
case var _ when variableName is "/PvOnDc/Dc/Power" or "/AvgPvPower": case "/PvOnDc/Dc/Power" or "/AvgPvPower":
pvPowerAverage.Add(value); pvPowerAverage.Add(value);
break; break;
case var _ when variableName is "/Battery/Dc/Power" or "/BatteryPowerAverage": case "/Battery/Dc/Power" or "/BatteryPowerAverage":
batteryPowerAverage.Add(value); batteryPowerAverage.Add(value);
break; break;
@ -149,8 +148,8 @@ public static class Aggregator
AggregatedData aggregatedData = new AggregatedData AggregatedData aggregatedData = new AggregatedData
{ {
AvgSoc = socAverage.Any() ? socAverage.Average() : 0.0, AvgSoc = socAverage.Any() ? socAverage.Average() : 0.0,
AvgPvPower = pvPowerAverage.Any() ? pvPowerAverage.Average() : 0.0, AvgPvPower = pvPowerAverage.Any() ? pvPowerAverage.Average() : 0.0,
BatteryPowerAverage = batteryPowerAverage.Any() ? batteryPowerAverage.Average() : 0.0 BatteryPowerAverage = batteryPowerAverage.Any() ? batteryPowerAverage.Average() : 0.0
}; };