Skip to content

Commit

Permalink
renamed haushaltsgeräte to home appliance (Akkudoktor-EOS#196)
Browse files Browse the repository at this point in the history
* * rename Haushaltsgeraete to home appliance
* renamed strafe to penalty (optimization problem)

Signed-off-by: Jürgen Eckel <juergen.eckel@gmail.com>

* removed penalty renaming

Signed-off-by: Jürgen Eckel <juergen.eckel@gmail.com>

* renamed one variable

Signed-off-by: Jürgen Eckel <juergen.eckel@gmail.com>

* * renamed variable names and methods of the home appliance class

* renamed missed method names

* fixed renamed variable

* renamed object

* adjusted to latest repo changes

* renamed file to class_home_applianc.py

* renamed method

---------

Signed-off-by: Jürgen Eckel <juergen.eckel@gmail.com>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
  • Loading branch information
eckelj authored Nov 25, 2024
1 parent 5b58e63 commit 595b733
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict
exclude: '\.rst$' # Exclude .rst files
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
Expand Down
30 changes: 15 additions & 15 deletions docs/akkudoktoreos/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,27 +496,27 @@
"type": "object",
"title": "HTTPValidationError"
},
"HaushaltsgeraetParameters": {
"HomeApplianceParameters": {
"properties": {
"verbrauch_wh": {
"consumption_wh": {
"type": "integer",
"exclusiveMinimum": 0.0,
"title": "Verbrauch Wh",
"title": "Consumption Wh",
"description": "An integer representing the energy consumption of a household device in watt-hours."
},
"dauer_h": {
"duration_h": {
"type": "integer",
"exclusiveMinimum": 0.0,
"title": "Dauer H",
"title": "Duration H",
"description": "An integer representing the usage duration of a household device in hours."
}
},
"type": "object",
"required": [
"verbrauch_wh",
"dauer_h"
"consumption_wh",
"duration_h"
],
"title": "HaushaltsgeraetParameters"
"title": "HomeApplianceParameters"
},
"OptimizationParameters": {
"properties": {
Expand All @@ -535,10 +535,10 @@
"eauto": {
"$ref": "#/components/schemas/EAutoParameters"
},
"spuelmaschine": {
"dishwasher": {
"anyOf": [
{
"$ref": "#/components/schemas/HaushaltsgeraetParameters"
"$ref": "#/components/schemas/HomeApplianceParameters"
},
{
"type": "null"
Expand Down Expand Up @@ -624,7 +624,7 @@
"title": "Start Solution",
"description": "An array of binary values (0 or 1) representing a possible starting solution for the simulation."
},
"spuelstart": {
"washingstart": {
"anyOf": [
{
"type": "integer"
Expand All @@ -633,7 +633,7 @@
"type": "null"
}
],
"title": "Spuelstart",
"title": "Washingstart",
"description": "Can be `null` or contain an object representing the start of washing (if applicable)."
}
},
Expand Down Expand Up @@ -782,7 +782,7 @@
"title": "Gesamtkosten Euro",
"description": "The total costs in euros."
},
"Haushaltsgeraet_wh_pro_stunde": {
"Home_appliance_wh_per_hour": {
"items": {
"anyOf": [
{
Expand All @@ -794,7 +794,7 @@
]
},
"type": "array",
"title": "Haushaltsgeraet Wh Pro Stunde",
"title": "Home Appliance Wh Per Hour",
"description": "The energy consumption of a household appliance in watt-hours per hour."
},
"Kosten_Euro_pro_Stunde": {
Expand Down Expand Up @@ -882,7 +882,7 @@
"Gesamtbilanz_Euro",
"Gesamteinnahmen_Euro",
"Gesamtkosten_Euro",
"Haushaltsgeraet_wh_pro_stunde",
"Home_appliance_wh_per_hour",
"Kosten_Euro_pro_Stunde",
"Netzbezug_Wh_pro_Stunde",
"Netzeinspeisung_Wh_pro_Stunde",
Expand Down
6 changes: 3 additions & 3 deletions single_test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@
# Current SOC of the electric car (%)
"start_soc_prozent": 5,
},
# "spuelmaschine": {
# "dishwasher": {
# # Household appliance consumption (Wh)
# "verbrauch_wh": 5000,
# "consumption_wh": 5000,
# # Duration of appliance usage (hours)
# "dauer_h": 0,
# "duration_h": 0,
# },
# Temperature forecast (48 hours)
"temperature_forecast": temperature_forecast,
Expand Down
64 changes: 64 additions & 0 deletions src/akkudoktoreos/class_home_appliance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy as np
from pydantic import BaseModel, Field


class HomeApplianceParameters(BaseModel):
consumption_wh: int = Field(
gt=0,
description="An integer representing the energy consumption of a household device in watt-hours.",
)
duration_h: int = Field(
gt=0,
description="An integer representing the usage duration of a household device in hours.",
)


class HomeAppliance:
def __init__(self, parameters: HomeApplianceParameters, hours=None):
self.hours = hours # Total duration for which the planning is done
self.consumption_wh = (
parameters.consumption_wh
) # Total energy consumption of the device in kWh
self.duration_h = parameters.duration_h # Duration of use in hours
self.load_curve = np.zeros(self.hours) # Initialize the load curve with zeros

def set_starting_time(self, start_hour, global_start_hour=0):
"""Sets the start time of the device and generates the corresponding load curve.
:param start_hour: The hour at which the device should start.
"""
self.reset()
# Check if the duration of use is within the available time frame
if start_hour + self.duration_h > self.hours:
raise ValueError("The duration of use exceeds the available time frame.")
if start_hour < global_start_hour:
raise ValueError("The start time is earlier than the available time frame.")

# Calculate power per hour based on total consumption and duration
power_per_hour = self.consumption_wh / self.duration_h # Convert to watt-hours

# Set the power for the duration of use in the load curve array
self.load_curve[start_hour : start_hour + self.duration_h] = power_per_hour

def reset(self):
"""Resets the load curve."""
self.load_curve = np.zeros(self.hours)

def get_load_curve(self):
"""Returns the current load curve."""
return self.load_curve

def get_load_for_hour(self, hour):
"""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.
"""
if hour < 0 or hour >= self.hours:
raise ValueError("The specified hour is outside the available time frame.")

return self.load_curve[hour]

def get_latest_starting_point(self):
"""Returns the latest possible start time at which the device can still run completely."""
return self.hours - self.duration_h
42 changes: 21 additions & 21 deletions src/akkudoktoreos/devices/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@
from pydantic import BaseModel, Field


class HaushaltsgeraetParameters(BaseModel):
verbrauch_wh: int = Field(
class HomeApplianceParameters(BaseModel):
consumption_wh: int = Field(
gt=0,
description="An integer representing the energy consumption of a household device in watt-hours.",
)
dauer_h: int = Field(
duration_h: int = Field(
gt=0,
description="An integer representing the usage duration of a household device in hours.",
)


class Haushaltsgeraet:
def __init__(self, parameters: HaushaltsgeraetParameters, hours=24):
class HomeAppliance:
def __init__(self, parameters: HomeApplianceParameters, hours=None):
self.hours = hours # Total duration for which the planning is done
self.verbrauch_wh = (
parameters.verbrauch_wh # Total energy consumption of the device in kWh
)
self.dauer_h = parameters.dauer_h # Duration of use in hours
self.lastkurve = np.zeros(self.hours) # Initialize the load curve with zeros
self.consumption_wh = (
parameters.consumption_wh
) # Total energy consumption of the device in kWh
self.duration_h = parameters.duration_h # Duration of use in hours
self.load_curve = np.zeros(self.hours) # Initialize the load curve with zeros

def set_startzeitpunkt(self, start_hour, global_start_hour=0):
def set_starting_time(self, start_hour, global_start_hour=0):
"""Sets the start time of the device and generates the corresponding load curve.
:param start_hour: The hour at which the device should start.
"""
self.reset()
# Check if the duration of use is within the available time frame
if start_hour + self.dauer_h > self.hours:
if start_hour + self.duration_h > self.hours:
raise ValueError("The duration of use exceeds the available time frame.")
if start_hour < global_start_hour:
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_wh / self.dauer_h # Convert to watt-hours
power_per_hour = self.consumption_wh / self.duration_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
self.load_curve[start_hour : start_hour + self.duration_h] = power_per_hour

def reset(self):
"""Resets the load curve."""
self.lastkurve = np.zeros(self.hours)
self.load_curve = np.zeros(self.hours)

def get_lastkurve(self):
def get_load_curve(self):
"""Returns the current load curve."""
return self.lastkurve
return self.load_curve

def get_last_fuer_stunde(self, hour):
def get_load_for_hour(self, hour):
"""Returns the load for a specific hour.
:param hour: The hour for which the load is queried.
Expand All @@ -57,8 +57,8 @@ def get_last_fuer_stunde(self, hour):
if hour < 0 or hour >= self.hours:
raise ValueError("The specified hour is outside the available time frame.")

return self.lastkurve[hour]
return self.load_curve[hour]

def spaetestmoeglicher_startzeitpunkt(self):
def get_latest_starting_point(self):
"""Returns the latest possible start time at which the device can still run completely."""
return self.hours - self.dauer_h
return self.hours - self.duration_h
6 changes: 3 additions & 3 deletions src/akkudoktoreos/devices/heatpump.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ def simulate_24h(self, temperatures: Sequence[float]) -> List[float]:
start_innentemperatur = 15 # Initial indoor temperature
isolationseffizienz = 0.8 # Insulation efficiency
gewuenschte_innentemperatur = 20 # Desired indoor temperature
wp = Heatpump(max_heizleistung, 24) # Initialize heat pump with prediction hours
hp = Heatpump(max_heizleistung, 24) # Initialize heat pump with prediction hours

# Print COP for various outside temperatures
print(wp.calculate_cop(-10), " ", wp.calculate_cop(0), " ", wp.calculate_cop(10))
print(hp.calculate_cop(-10), " ", hp.calculate_cop(0), " ", hp.calculate_cop(10))

# 24 hours of outside temperatures (example values)
temperaturen = [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -5, -2, 5, ] # fmt: skip

# Calculate the 24-hour power data
leistungsdaten = wp.simulate_24h(temperaturen)
leistungsdaten = hp.simulate_24h(temperaturen)

print(leistungsdaten)
Loading

0 comments on commit 595b733

Please sign in to comment.