Update class_load_container.py

initial clean up, unused imports removed, translations, very minor code changes
This commit is contained in:
NormannK 2024-09-20 12:48:02 +02:00 committed by Andreas
parent c2af6cc1b3
commit 8075515e8f

View File

@ -1,39 +1,36 @@
import json
from datetime import datetime, timedelta, timezone
import numpy as np import numpy as np
from pprint import pprint from pprint import pprint
class Gesamtlast: class Gesamtlast:
def __init__(self, prediction_hours=24): def __init__(self, prediction_hours=24):
self.lasten = {} # Enthält Namen und Lasten-Arrays für verschiedene Quellen self.lasten = {} # Contains names and load arrays for different sources
self.prediction_hours=prediction_hours self.prediction_hours = prediction_hours
def hinzufuegen(self, name, last_array): def hinzufuegen(self, name, last_array):
""" """
Fügt ein Array von Lasten für eine bestimmte Quelle hinzu. Adds an array of loads for a specific source.
:param name: Name der Lastquelle (z.B. "Haushalt", "Wärmepumpe") :param name: Name of the load source (e.g., "Household", "Heat Pump")
:param last_array: Array von Lasten, wobei jeder Eintrag einer Stunde entspricht :param last_array: Array of loads, where each entry corresponds to an hour
""" """
if(len(last_array) != self.prediction_hours): if len(last_array) != self.prediction_hours:
raise ValueError(f"Gesamtlast Inkonsistente Längen bei den Arrays: ", name," ", len(last_array) ) raise ValueError(f"Total load inconsistent lengths in arrays: {name} {len(last_array)}")
self.lasten[name] = last_array self.lasten[name] = last_array
def gesamtlast_berechnen(self): def gesamtlast_berechnen(self):
""" """
Berechnet die gesamte Last für jede Stunde und gibt ein Array der Gesamtlasten zurück. Calculates the total load for each hour and returns an array of total loads.
:return: Array der Gesamtlasten, wobei jeder Eintrag einer Stunde entspricht :return: Array of total loads, where each entry corresponds to an hour
""" """
if not self.lasten: if not self.lasten:
return [] return []
# Annahme: Alle Lasten-Arrays haben die gleiche Länge # Assumption: All load arrays have the same length
stunden = len(next(iter(self.lasten.values()))) stunden = len(next(iter(self.lasten.values())))
gesamtlast_array = [0] * stunden gesamtlast_array = [0] * stunden
for last_array in self.lasten.values(): for last_array in self.lasten.values():
gesamtlast_array = [gesamtlast + stundenlast for gesamtlast, stundenlast in zip(gesamtlast_array, last_array)] gesamtlast_array = [gesamtlast + stundenlast for gesamtlast, stundenlast in zip(gesamtlast_array, last_array)]
return np.array(gesamtlast_array) return np.array(gesamtlast_array)