Update aggregate data naming and calculation

This commit is contained in:
atef 2024-02-05 15:31:50 +01:00
parent b61ca9264e
commit 08408e61d5
1 changed files with 35 additions and 36 deletions

View File

@ -101,7 +101,7 @@ public static class Aggregator
// Get all CSV files in the specified directory
var csvFiles = Directory.GetFiles(myDirectory, "*.csv");
var batterySoc = new List<Double>();
var pvPowerAverage = new List<Double>();
var pvPowerSum = new List<Double>();
var heatingPower = new List<Double>();
var gridPowerImport = new List<Double>();
var gridPowerExport = new List<Double>();
@ -143,7 +143,7 @@ public static class Aggregator
break;
case "/PvOnDc/DcWh" :
pvPowerAverage.Add(value);
pvPowerSum.Add(value);
break;
case "/Battery/Dc/Power":
@ -163,7 +163,6 @@ public static class Aggregator
// we are using different register to check which value from the grid meter we need to use
gridPowerExport.Add(value);
break;
case "/GridMeter/ActivePowerImportT2":
gridPowerImport.Add(value);
break;
@ -203,35 +202,35 @@ public static class Aggregator
var dischargingEnergy = (batteryDischargePower.Any() ? batteryDischargePower.Average() : 0.0) / 3600;
var chargingEnergy = (batteryChargePower.Any() ? batteryChargePower.Average() : 0.0) / 3600;
var heatingPowerAvg = (heatingPower.Any() ? heatingPower.Average() : 0.0) / 3600;
var heatingPowerAvg = (heatingPower.Any() ? heatingPower.Average() : 0.0) / 3600;
var dMaxSoc = batterySoc.Any() ? batterySoc.Max() : 0.0;
var dMinSoc = batterySoc.Any() ? batterySoc.Min() : 0.0;
var dSumGridExportPower = gridPowerExport.Any() ? (gridPowerExport.Max() - gridPowerExport.Min()) / 1000 : 0.0;
var dSumGridImportPower = gridPowerImport.Any() ? (gridPowerImport.Max() - gridPowerImport.Min()) / 1000 : 0.0;
var dSumPvPower = pvPowerAverage.Any() ? pvPowerAverage.Average() /1000 : 0.0;
var dMaxSoc = batterySoc.Any() ? batterySoc.Max() : 0.0;
var dMinSoc = batterySoc.Any() ? batterySoc.Min() : 0.0;
var dSumGridExportPower = gridPowerExport.Any() ? gridPowerExport.Max() : 0.0;
var dSumGridImportPower = gridPowerImport.Any() ? gridPowerImport.Max() : 0.0;
var dSumPvPower = pvPowerSum.Any() ? pvPowerSum.Max() : 0.0;
AggregatedData aggregatedData = new AggregatedData
{
MaxSoc = dMaxSoc,
MinSoc = dMinSoc,
SumDischargingBatteryPower = dischargingEnergy,
SumChargingBatteryPower = chargingEnergy,
SumGridExportPower = dSumGridExportPower,
SumGridImportPower = dSumGridImportPower,
SumPvPower = dSumPvPower,
HeatingPowerAvg = heatingPowerAvg
MaxSoc = dMaxSoc,
MinSoc = dMinSoc,
DischargingBatteryPower = dischargingEnergy,
ChargingBatteryPower = chargingEnergy,
GridExportPower = dSumGridExportPower,
GridImportPower = dSumGridImportPower,
PvPower = dSumPvPower,
HeatingPower = heatingPowerAvg
};
// Print the stored CSV data for verification
Console.WriteLine($"Max SOC: {aggregatedData.MaxSoc}");
Console.WriteLine($"Min SOC: {aggregatedData.MinSoc}");
Console.WriteLine($"ChargingBatteryPower: {aggregatedData.SumDischargingBatteryPower}");
Console.WriteLine($"DischargingBatteryBattery: {aggregatedData.SumChargingBatteryPower}");
Console.WriteLine($"ChargingBatteryPower: {aggregatedData.DischargingBatteryPower}");
Console.WriteLine($"DischargingBatteryBattery: {aggregatedData.ChargingBatteryPower}");
Console.WriteLine($"SumGridExportPower: {aggregatedData.SumGridExportPower}");
Console.WriteLine($"SumGridImportPower: {aggregatedData.SumGridImportPower}");
Console.WriteLine($"SumGridExportPower: {aggregatedData.GridExportPower}");
Console.WriteLine($"SumGridImportPower: {aggregatedData.GridImportPower}");
Console.WriteLine($"Min SOC: {aggregatedData.MinSoc}");
@ -247,7 +246,7 @@ public static class Aggregator
// Get all CSV files in the specified directory
var csvFiles = Directory.GetFiles(myDirectory, "*.csv");
var batterySoc = new List<Double>();
var pvPowerAverage = new List<Double>();
var pvPower = new List<Double>();
var gridPowerImport = new List<Double>();
var gridPowerExport = new List<Double>();
var batteryDischargePower = new List<Double>();
@ -289,7 +288,7 @@ public static class Aggregator
break;
case "/SumPvPower":
pvPowerAverage.Add(value);
pvPower.Add(value);
break;
case "/SumDischargingBatteryPower" :
@ -336,25 +335,25 @@ public static class Aggregator
AggregatedData aggregatedData = new AggregatedData
{
MaxSoc = batterySoc.Any() ? batterySoc.Max() : 0.0,
MinSoc = batterySoc.Any() ? batterySoc.Min() : 0.0,
SumDischargingBatteryPower = batteryDischargePower.Any() ? batteryDischargePower.Average(): 0.0,
SumChargingBatteryPower = batteryChargePower.Any() ? batteryChargePower.Average() : 0.0,
SumGridExportPower = gridPowerExport.Any() ? gridPowerExport.Average() : 0.0,
SumGridImportPower = gridPowerImport.Any() ? gridPowerImport.Average() : 0.0,
SumPvPower = pvPowerAverage.Any() ? pvPowerAverage.Average() : 0.0,
HeatingPowerAvg = heatingPowerAvg.Any() ? heatingPowerAvg.Average() : 0.0,
MaxSoc = batterySoc.Any() ? batterySoc.Max() : 0.0,
MinSoc = batterySoc.Any() ? batterySoc.Min() : 0.0,
DischargingBatteryPower = batteryDischargePower.Any() ? batteryDischargePower.Average(): 0.0,
ChargingBatteryPower = batteryChargePower.Any() ? batteryChargePower.Average() : 0.0,
GridExportPower = gridPowerExport.Any() ? gridPowerExport.Max() : 0.0,
GridImportPower = gridPowerImport.Any() ? gridPowerImport.Max() : 0.0,
PvPower = pvPower.Any() ? pvPower.Max() : 0.0,
HeatingPower = heatingPowerAvg.Any() ? heatingPowerAvg.Average() : 0.0,
};
// Print the stored CSV data for verification
Console.WriteLine($"Max SOC: {aggregatedData.MaxSoc}");
Console.WriteLine($"Min SOC: {aggregatedData.MinSoc}");
Console.WriteLine($"ChargingBatteryPower: {aggregatedData.SumDischargingBatteryPower}");
Console.WriteLine($"DischargingBatteryBattery: {aggregatedData.SumChargingBatteryPower}");
Console.WriteLine($"ChargingBatteryPower: {aggregatedData.DischargingBatteryPower}");
Console.WriteLine($"DischargingBatteryBattery: {aggregatedData.ChargingBatteryPower}");
Console.WriteLine($"SumGridExportPower: {aggregatedData.SumGridExportPower}");
Console.WriteLine($"SumGridImportPower: {aggregatedData.SumGridImportPower}");
Console.WriteLine($"SumGridExportPower: {aggregatedData.GridExportPower}");
Console.WriteLine($"SumGridImportPower: {aggregatedData.GridImportPower}");
Console.WriteLine($"Min SOC: {aggregatedData.MinSoc}");