Skip to content

Commit

Permalink
min_soc (was killed by someone else, pls dont force push!)
Browse files Browse the repository at this point in the history
  • Loading branch information
drbacke committed Oct 6, 2024
1 parent d8a46eb commit b7dbd7e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
4 changes: 4 additions & 0 deletions flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions modules/class_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def optimierung_ems(
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))
Expand Down
6 changes: 4 additions & 2 deletions single_test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@
# 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
"eauto_charge_efficiency": 0.95,
# 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
Expand All @@ -358,6 +358,8 @@
"haushaltsgeraet_wh": 5000,
# Duration of appliance usage (hours)
"haushaltsgeraet_dauer": 2,
# Minimum Soc PV Battery
"min_soc_prozent": 15,
}

# Initialize the optimization problem
Expand Down
30 changes: 17 additions & 13 deletions tests/test_class_ems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_class_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b7dbd7e

Please sign in to comment.