From 08408e61d56dc05f781f7600fb7bda8aacef672b Mon Sep 17 00:00:00 2001 From: atef Date: Mon, 5 Feb 2024 15:31:50 +0100 Subject: [PATCH] Update aggregate data naming and calculation --- .../src/AggregationService/Aggregator.cs | 71 +++++++++---------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/csharp/App/SaliMax/src/AggregationService/Aggregator.cs b/csharp/App/SaliMax/src/AggregationService/Aggregator.cs index 58589f380..59b7cadc8 100644 --- a/csharp/App/SaliMax/src/AggregationService/Aggregator.cs +++ b/csharp/App/SaliMax/src/AggregationService/Aggregator.cs @@ -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(); - var pvPowerAverage = new List(); + var pvPowerSum = new List(); var heatingPower = new List(); var gridPowerImport = new List(); var gridPowerExport = new List(); @@ -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 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 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() : 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(); - var pvPowerAverage = new List(); + var pvPower = new List(); var gridPowerImport = new List(); var gridPowerExport = new List(); var batteryDischargePower = new List(); @@ -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}");