update the Create Avreage function
This commit is contained in:
parent
91da191874
commit
5245df237f
|
@ -99,9 +99,14 @@ public static class Aggregator
|
||||||
{
|
{
|
||||||
// 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 batterySoc = new List<Double>();
|
||||||
|
var batteryAvgSoc = new List<Double>(); // this is only used for the daily data.
|
||||||
var pvPowerAverage = new List<Double>();
|
var pvPowerAverage = new List<Double>();
|
||||||
var batteryPowerAverage = new List<Double>();
|
var gridPowerImport = new List<Double>();
|
||||||
|
var gridPowerExport = new List<Double>();
|
||||||
|
var batteryDischargePower = new List<Double>();
|
||||||
|
var batteryChargePower = new List<Double>();
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("-----------------------------------------------------------------------------------------------------------------");
|
Console.WriteLine("-----------------------------------------------------------------------------------------------------------------");
|
||||||
Console.WriteLine("File timestamp should start after "+ afterTimestamp);
|
Console.WriteLine("File timestamp should start after "+ afterTimestamp);
|
||||||
|
@ -132,18 +137,41 @@ public static class Aggregator
|
||||||
{
|
{
|
||||||
switch (variableName)
|
switch (variableName)
|
||||||
{
|
{
|
||||||
case "/Battery/Soc" or "/AvgSoc":
|
case "/Battery/Soc" or "/MinSoc" or "/MaxSoc":
|
||||||
socAverage.Add(value);
|
batterySoc.Add(value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "/PvOnDc/Dc/Power" or "/AvgPvPower":
|
case "/AvgSoc":
|
||||||
|
batteryAvgSoc.Add(value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "/PvOnDc/Dc/Power" or "/SumPvPower":
|
||||||
pvPowerAverage.Add(value);
|
pvPowerAverage.Add(value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "/Battery/Dc/Power" or "/BatteryPowerAverage":
|
case "/Battery/Dc/Power" or "/SumDischargingBatteryPower" or "/SumChargingBatteryPower":
|
||||||
batteryPowerAverage.Add(value);
|
if (value < 0)
|
||||||
|
{
|
||||||
|
batteryDischargePower.Add(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
batteryChargePower.Add(value);
|
||||||
|
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "/GridMeter/Ac/Power/Active" or "/SumGridExportPower" or "/SumGridImportPower":
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
gridPowerExport.Add(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gridPowerImport.Add(value);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
// Add more cases as needed
|
// Add more cases as needed
|
||||||
default:
|
default:
|
||||||
// Code to execute when variableName doesn't match any condition
|
// Code to execute when variableName doesn't match any condition
|
||||||
|
@ -169,15 +197,29 @@ public static class Aggregator
|
||||||
|
|
||||||
AggregatedData aggregatedData = new AggregatedData
|
AggregatedData aggregatedData = new AggregatedData
|
||||||
{
|
{
|
||||||
AvgSoc = socAverage.Any() ? socAverage.Average() : 0.0,
|
MaxSoc = batterySoc.Any() ? batterySoc.Max() : 0.0,
|
||||||
AvgPvPower = pvPowerAverage.Any() ? pvPowerAverage.Average() : 0.0,
|
MinSoc = batterySoc.Any() ? batterySoc.Min() : 0.0,
|
||||||
BatteryPowerAverage = batteryPowerAverage.Any() ? batteryPowerAverage.Average() : 0.0
|
AvgSoc = batteryAvgSoc.Any() ? batteryAvgSoc.Average() : 0.0,
|
||||||
|
SumDischargingBatteryPower = batteryDischargePower.Any() ? batteryDischargePower.Sum() : 0.0,
|
||||||
|
SumChargingBatteryPower = batteryChargePower.Any() ? batteryChargePower.Sum() : 0.0,
|
||||||
|
SumGridExportPower = gridPowerExport.Any() ? gridPowerExport.Sum() : 0.0,
|
||||||
|
SumGridImportPower = gridPowerImport.Any() ? gridPowerImport.Sum() : 0.0,
|
||||||
|
SumPvPower = pvPowerAverage.Any() ? pvPowerAverage.Sum() : 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Print the stored CSV data for verification
|
// Print the stored CSV data for verification
|
||||||
Console.WriteLine($"SOC: {aggregatedData.AvgSoc}");
|
Console.WriteLine($"Max SOC: {aggregatedData.MaxSoc}");
|
||||||
Console.WriteLine($"PvPower: {aggregatedData.AvgPvPower}");
|
Console.WriteLine($"Min SOC: {aggregatedData.MinSoc}");
|
||||||
Console.WriteLine($"Battery: {aggregatedData.BatteryPowerAverage}");
|
|
||||||
|
Console.WriteLine($"ChargingBatteryPower: {aggregatedData.SumDischargingBatteryPower}");
|
||||||
|
Console.WriteLine($"DischargingBatteryBattery: {aggregatedData.SumChargingBatteryPower}");
|
||||||
|
|
||||||
|
Console.WriteLine($"SumGridExportPower: {aggregatedData.SumGridExportPower}");
|
||||||
|
Console.WriteLine($"SumGridImportPower: {aggregatedData.SumGridImportPower}");
|
||||||
|
|
||||||
|
Console.WriteLine($"Min SOC: {aggregatedData.MinSoc}");
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("CSV data reading and storage completed.");
|
Console.WriteLine("CSV data reading and storage completed.");
|
||||||
Console.WriteLine("-----------------------------------------------------------------------------------------------------------------");
|
Console.WriteLine("-----------------------------------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue