mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 00:45:22 +00:00
- Home Appliances fixed
- Unittest with Home Appliances
This commit is contained in:
parent
0a0c3eed87
commit
9b7817e3dc
@ -96,9 +96,11 @@ class EnergieManagementSystem:
|
||||
|
||||
# Accumulate loads and PV generation
|
||||
verbrauch = self.gesamtlast[stunde]
|
||||
|
||||
if self.haushaltsgeraet:
|
||||
verbrauch += self.haushaltsgeraet.get_last_fuer_stunde(stunde)
|
||||
haushaltsgeraet_wh_pro_stunde[stunde_since_now] = verbrauch
|
||||
ha_load = self.haushaltsgeraet.get_last_fuer_stunde(stunde)
|
||||
verbrauch += ha_load
|
||||
haushaltsgeraet_wh_pro_stunde[stunde_since_now] = ha_load
|
||||
|
||||
# E-Auto handling
|
||||
if self.eauto:
|
||||
|
@ -2,10 +2,10 @@ import numpy as np
|
||||
|
||||
|
||||
class Haushaltsgeraet:
|
||||
def __init__(self, hours=None, verbrauch_kwh=None, dauer_h=None):
|
||||
def __init__(self, hours=None, verbrauch_wh=None, dauer_h=None):
|
||||
self.hours = hours # Total duration for which the planning is done
|
||||
self.verbrauch_kwh = (
|
||||
verbrauch_kwh # Total energy consumption of the device in kWh
|
||||
self.verbrauch_wh = (
|
||||
verbrauch_wh # Total energy consumption of the device in kWh
|
||||
)
|
||||
self.dauer_h = dauer_h # Duration of use in hours
|
||||
self.lastkurve = np.zeros(self.hours) # Initialize the load curve with zeros
|
||||
@ -24,7 +24,7 @@ class Haushaltsgeraet:
|
||||
raise ValueError("The start time is earlier than the available time frame.")
|
||||
|
||||
# Calculate power per hour based on total consumption and duration
|
||||
leistung_pro_stunde = self.verbrauch_kwh / self.dauer_h # Convert to watt-hours
|
||||
leistung_pro_stunde = self.verbrauch_wh / self.dauer_h # Convert to watt-hours
|
||||
|
||||
# Set the power for the duration of use in the load curve array
|
||||
self.lastkurve[start_hour : start_hour + self.dauer_h] = leistung_pro_stunde
|
||||
|
@ -288,9 +288,9 @@ class optimization_problem:
|
||||
spuelmaschine = (
|
||||
Haushaltsgeraet(
|
||||
hours=self.prediction_hours,
|
||||
verbrauch_kwh=parameter["haushaltsgeraet_wh"],
|
||||
verbrauch_wh=parameter["haushaltsgeraet_wh"],
|
||||
dauer_h=parameter["haushaltsgeraet_dauer"],
|
||||
).set_startzeitpunkt(start_hour)
|
||||
)
|
||||
if parameter["haushaltsgeraet_dauer"] > 0
|
||||
else None
|
||||
)
|
||||
|
@ -355,13 +355,13 @@ parameter = {
|
||||
# Initial solution for the optimization
|
||||
"start_solution": start_solution,
|
||||
# Household appliance consumption (Wh)
|
||||
"haushaltsgeraet_wh": 937,
|
||||
"haushaltsgeraet_wh": 5000,
|
||||
# Duration of appliance usage (hours)
|
||||
"haushaltsgeraet_dauer": 0,
|
||||
"haushaltsgeraet_dauer": 2,
|
||||
}
|
||||
|
||||
# Initialize the optimization problem
|
||||
opt_class = optimization_problem(prediction_hours=48, strafe=10, optimization_hours=24)
|
||||
opt_class = optimization_problem(prediction_hours=48, strafe=10, optimization_hours=24, verbose=True)
|
||||
|
||||
# Perform the optimisation based on the provided parameters and start hour
|
||||
ergebnis = opt_class.optimierung_ems(parameter=parameter, start_hour=start_hour)
|
||||
|
@ -6,7 +6,7 @@ from modules.class_inverter import Wechselrichter # Example import
|
||||
from modules.class_haushaltsgeraet import Haushaltsgeraet
|
||||
prediction_hours = 48
|
||||
optimization_hours = 24
|
||||
|
||||
start_hour = 1
|
||||
|
||||
# Example initialization of necessary components
|
||||
@pytest.fixture
|
||||
@ -22,11 +22,11 @@ def create_ems_instance():
|
||||
# Household device (currently not used, set to None)
|
||||
home_appliance = Haushaltsgeraet(
|
||||
hours=prediction_hours,
|
||||
verbrauch_kwh=2000,
|
||||
verbrauch_wh=2000,
|
||||
dauer_h=2,
|
||||
).set_startzeitpunkt(2)
|
||||
)
|
||||
home_appliance.set_startzeitpunkt(2)
|
||||
|
||||
|
||||
# Example initialization of electric car battery
|
||||
eauto = PVAkku(kapazitaet_wh=26400, start_soc_prozent=10, hours=48)
|
||||
|
||||
@ -206,7 +206,7 @@ def test_simulation(create_ems_instance):
|
||||
ems = create_ems_instance
|
||||
|
||||
# Simulate starting from hour 1 (this value can be adjusted)
|
||||
start_hour = 1
|
||||
|
||||
result = ems.simuliere(start_stunde=start_hour)
|
||||
|
||||
# Assertions to validate results
|
||||
@ -262,11 +262,11 @@ def test_simulation(create_ems_instance):
|
||||
|
||||
# Verify specific values in the 'Last_Wh_pro_Stunde' array
|
||||
assert (
|
||||
result["Last_Wh_pro_Stunde"][1] == 23759.13
|
||||
), "The value at index 1 of 'Last_Wh_pro_Stunde' should be 23759.13."
|
||||
result["Last_Wh_pro_Stunde"][1] == 24759.13
|
||||
), "The value at index 1 of 'Last_Wh_pro_Stunde' should be 24759.13."
|
||||
assert (
|
||||
result["Last_Wh_pro_Stunde"][2] == 996.88
|
||||
), "The value at index 2 of 'Last_Wh_pro_Stunde' should be 996.88."
|
||||
result["Last_Wh_pro_Stunde"][2] == 1996.88
|
||||
), "The value at index 2 of 'Last_Wh_pro_Stunde' should be 1996.88."
|
||||
assert (
|
||||
result["Last_Wh_pro_Stunde"][12] == 1132.03
|
||||
), "The value at index 12 of 'Last_Wh_pro_Stunde' should be 1132.03."
|
||||
@ -284,21 +284,21 @@ 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] == 20239.13
|
||||
), "The value at index 1 of 'Netzbezug_Wh_pro_Stunde' should be 20239.13."
|
||||
result["Netzbezug_Wh_pro_Stunde"][1] == 21239.13
|
||||
), "The value at index 1 of 'Netzbezug_Wh_pro_Stunde' should be 21239.13."
|
||||
|
||||
# Verify the total balance
|
||||
assert (
|
||||
abs(result["Gesamtbilanz_Euro"] - 8.434942129454546) < 1e-5
|
||||
), "Total balance should be 8.434942129454546."
|
||||
abs(result["Gesamtbilanz_Euro"] - 9.091642129454547) < 1e-5
|
||||
), "Total balance should be 9.091642129454547."
|
||||
|
||||
# Check total revenue and total costs
|
||||
assert (
|
||||
abs(result["Gesamteinnahmen_Euro"] - 1.237432954545454) < 1e-5
|
||||
), "Total revenue should be 1.237432954545454."
|
||||
assert (
|
||||
abs(result["Gesamtkosten_Euro"] - 9.672375084) < 1e-5
|
||||
), "Total costs should be 9.672375084."
|
||||
abs(result["Gesamtkosten_Euro"] - 10.329075084000001 ) < 1e-5
|
||||
), "Total costs should be 10.329075084000001 ."
|
||||
|
||||
# Check the losses
|
||||
assert (
|
||||
@ -314,8 +314,13 @@ def test_simulation(create_ems_instance):
|
||||
), "The value at index 1 of 'akku_soc_pro_stunde' should be 0.0."
|
||||
|
||||
# Check home appliances
|
||||
assert (
|
||||
sum(ems.haushaltsgeraet.get_lastkurve()) == 2000
|
||||
), "The sum of 'ems.haushaltsgeraet.get_lastkurve()' should be 2000."
|
||||
|
||||
assert (
|
||||
sum(result["Haushaltsgeraet_wh_pro_stunde"]) == 2000
|
||||
), "The value at index -1 of 'Haushaltsgeraet_wh_pro_stunde' should be 2000."
|
||||
), "The sum of 'Haushaltsgeraet_wh_pro_stunde' should be 2000."
|
||||
|
||||
|
||||
print("All tests passed successfully.")
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user