2024-04-02 16:46:16 +02:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
class Haushaltsgeraet:
|
|
|
|
def __init__(self, hours=None, verbrauch_kwh=None, dauer_h=None):
|
2024-09-20 12:23:22 +02:00
|
|
|
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.dauer_h = dauer_h # Duration of use in hours
|
|
|
|
self.lastkurve = np.zeros(self.hours) # Initialize the load curve with zeros
|
2024-04-02 16:46:16 +02:00
|
|
|
|
2024-09-20 12:23:22 +02:00
|
|
|
def set_startzeitpunkt(self, start_hour, global_start_hour=0):
|
2024-04-02 16:46:16 +02:00
|
|
|
"""
|
2024-09-20 12:23:22 +02:00
|
|
|
Sets the start time of the device and generates the corresponding load curve.
|
|
|
|
:param start_hour: The hour at which the device should start.
|
2024-04-02 16:46:16 +02:00
|
|
|
"""
|
|
|
|
self.reset()
|
2024-09-20 12:23:22 +02:00
|
|
|
|
|
|
|
# Check if the duration of use is within the available time frame
|
2024-04-02 16:46:16 +02:00
|
|
|
if start_hour + self.dauer_h > self.hours:
|
2024-09-20 12:23:22 +02:00
|
|
|
raise ValueError("The duration of use exceeds the available time frame.")
|
2024-04-02 16:46:16 +02:00
|
|
|
if start_hour < global_start_hour:
|
2024-09-20 12:23:22 +02:00
|
|
|
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
|
2024-04-02 16:46:16 +02:00
|
|
|
|
2024-09-20 12:23:22 +02:00
|
|
|
# Set the power for the duration of use in the load curve array
|
2024-04-02 16:46:16 +02:00
|
|
|
self.lastkurve[start_hour:start_hour + self.dauer_h] = leistung_pro_stunde
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
"""
|
2024-09-20 12:23:22 +02:00
|
|
|
Resets the load curve.
|
2024-04-02 16:46:16 +02:00
|
|
|
"""
|
|
|
|
self.lastkurve = np.zeros(self.hours)
|
|
|
|
|
|
|
|
def get_lastkurve(self):
|
|
|
|
"""
|
2024-09-20 12:23:22 +02:00
|
|
|
Returns the current load curve.
|
2024-04-02 16:46:16 +02:00
|
|
|
"""
|
|
|
|
return self.lastkurve
|
|
|
|
|
|
|
|
def get_last_fuer_stunde(self, hour):
|
|
|
|
"""
|
2024-09-20 12:23:22 +02:00
|
|
|
Returns the load for a specific hour.
|
|
|
|
:param hour: The hour for which the load is queried.
|
|
|
|
:return: The load in watts for the specified hour.
|
2024-04-02 16:46:16 +02:00
|
|
|
"""
|
|
|
|
if hour < 0 or hour >= self.hours:
|
2024-09-20 12:23:22 +02:00
|
|
|
raise ValueError("The specified hour is outside the available time frame.")
|
2024-04-02 16:46:16 +02:00
|
|
|
|
|
|
|
return self.lastkurve[hour]
|
|
|
|
|
|
|
|
def spaetestmoeglicher_startzeitpunkt(self):
|
|
|
|
"""
|
2024-09-20 12:23:22 +02:00
|
|
|
Returns the latest possible start time at which the device can still run completely.
|
2024-04-02 16:46:16 +02:00
|
|
|
"""
|
|
|
|
return self.hours - self.dauer_h
|