From 05c0f74b09838c51e52fe5721c168de35cf4a369 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 6 Oct 2024 15:57:29 +0200 Subject: [PATCH] min_soc (was killed by someone else, pls dont force push!) --- flask_server.py | 4 ++++ modules/class_optimize.py | 1 + single_test_optimization.py | 6 ++++-- tests/test_class_ems.py | 30 +++++++++++++++++------------- tests/test_class_optimize.py | 1 + 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/flask_server.py b/flask_server.py index 368f69e..a7f34d5 100755 --- a/flask_server.py +++ b/flask_server.py @@ -228,6 +228,10 @@ def flask_optimize(): parameter=parameter, start_hour=datetime.now().hour ) + # Optional min SoC PV Battery + if "min_soc_prozent" not in parameter: + parameter["min_soc_prozent"] = None + return jsonify(result) # Return optimization results as JSON diff --git a/modules/class_optimize.py b/modules/class_optimize.py index 49b8033..34b7515 100644 --- a/modules/class_optimize.py +++ b/modules/class_optimize.py @@ -270,6 +270,7 @@ class optimization_problem: kapazitaet_wh=parameter["pv_akku_cap"], hours=self.prediction_hours, start_soc_prozent=parameter["pv_soc"], + min_soc_prozent=parameter["min_soc_prozent"], max_ladeleistung_w=5000, ) akku.set_charge_per_hour(np.full(self.prediction_hours, 1)) diff --git a/single_test_optimization.py b/single_test_optimization.py index d2ea9dc..f442d1d 100644 --- a/single_test_optimization.py +++ b/single_test_optimization.py @@ -341,7 +341,7 @@ parameter = { # Electricity price forecast (48 hours) "strompreis_euro_pro_wh": strompreis_euro_pro_wh, # Minimum SOC for electric car - "eauto_min_soc": 70, + "eauto_min_soc": 1000, # Electric car battery capacity (Wh) "eauto_cap": 60000, # Charging efficiency of the electric car @@ -349,7 +349,7 @@ parameter = { # Charging power of the electric car (W) "eauto_charge_power": 11040, # Current SOC of the electric car (%) - "eauto_soc": 54, + "eauto_soc": 5, # Current PV power generation (W) "pvpowernow": 211.137503624, # Initial solution for the optimization @@ -358,6 +358,8 @@ parameter = { "haushaltsgeraet_wh": 5000, # Duration of appliance usage (hours) "haushaltsgeraet_dauer": 2, + # Minimum Soc PV Battery + "min_soc_prozent": 15, } # Initialize the optimization problem diff --git a/tests/test_class_ems.py b/tests/test_class_ems.py index ec11b37..f2bef74 100644 --- a/tests/test_class_ems.py +++ b/tests/test_class_ems.py @@ -17,7 +17,9 @@ def create_ems_instance(): Fixture to create an EnergieManagementSystem instance with given test parameters. """ # Initialize the battery and the inverter - akku = PVAkku(kapazitaet_wh=5000, start_soc_prozent=80, hours=48) + akku = PVAkku( + kapazitaet_wh=5000, start_soc_prozent=80, hours=48, min_soc_prozent=10 + ) akku.reset() wechselrichter = Wechselrichter(10000, akku) @@ -30,7 +32,9 @@ def create_ems_instance(): home_appliance.set_startzeitpunkt(2) # Example initialization of electric car battery - eauto = PVAkku(kapazitaet_wh=26400, start_soc_prozent=10, hours=48) + eauto = PVAkku( + kapazitaet_wh=26400, start_soc_prozent=10, hours=48, min_soc_prozent=10 + ) # Parameters based on previous example data pv_prognose_wh = [ @@ -286,33 +290,33 @@ def test_simulation(create_ems_instance): result["Netzbezug_Wh_pro_Stunde"][0] == 0.0 ), "The value at index 0 of 'Netzbezug_Wh_pro_Stunde' should be None." assert ( - result["Netzbezug_Wh_pro_Stunde"][1] == 21239.13 - ), "The value at index 1 of 'Netzbezug_Wh_pro_Stunde' should be 21239.13." + result["Netzbezug_Wh_pro_Stunde"][1] == 21679.13 + ), "The value at index 1 of 'Netzbezug_Wh_pro_Stunde' should be21679.13." # Verify the total balance assert ( - abs(result["Gesamtbilanz_Euro"] - 9.091642129454547) < 1e-5 - ), "Total balance should be 9.091642129454547." + abs(result["Gesamtbilanz_Euro"] - 9.302960148909092) < 1e-5 + ), "Total balance should be 9.302960148909092." # Check total revenue and total costs assert ( - abs(result["Gesamteinnahmen_Euro"] - 1.237432954545454) < 1e-5 - ), "Total revenue should be 1.237432954545454." + abs(result["Gesamteinnahmen_Euro"] - 1.3169784090909087) < 1e-5 + ), "Total revenue should be 1.3169784090909087." assert ( - abs(result["Gesamtkosten_Euro"] - 10.329075084000001) < 1e-5 - ), "Total costs should be 10.329075084000001 ." + abs(result["Gesamtkosten_Euro"] - 10.619938558000001) < 1e-5 + ), "Total costs should be 10.619938558000001 ." # Check the losses assert ( - abs(result["Gesamt_Verluste"] - 6111.586363636363) < 1e-5 - ), "Total losses should be 6111.586363636363." + abs(result["Gesamt_Verluste"] - 5855.222727272727) < 1e-5 + ), "Total losses should be 5855.222727272727." # Check the values in 'akku_soc_pro_stunde' assert ( result["akku_soc_pro_stunde"][-1] == 28.675 ), "The value at index -1 of 'akku_soc_pro_stunde' should be 28.675." assert ( - result["akku_soc_pro_stunde"][1] == 0.0 + result["akku_soc_pro_stunde"][1] == 10.0 ), "The value at index 1 of 'akku_soc_pro_stunde' should be 0.0." # Check home appliances diff --git a/tests/test_class_optimize.py b/tests/test_class_optimize.py index 224c6e4..fb20dfd 100644 --- a/tests/test_class_optimize.py +++ b/tests/test_class_optimize.py @@ -1398,6 +1398,7 @@ def setup_opt_class(): ) # Yield the class and parameters for use in tests +@pytest.mark.skip(reason="Expensive - Skipped per default") def test_optimierung_ems(setup_opt_class): opt_class, parameter, start_hour = setup_opt_class