From 2c0e35584537bb70b2085b8311a341c285cc5920 Mon Sep 17 00:00:00 2001 From: Bla Bla Date: Fri, 8 Mar 2024 14:22:11 +0100 Subject: [PATCH] =?UTF-8?q?W=C3=A4rmepumpen=20Klasse=20f=C3=BCr=20meine=20?= =?UTF-8?q?WP=20erzeugt=20(Achtung=20Standard)=20PV=20Prognose=20aufsummie?= =?UTF-8?q?ren=20der=20Strings=20eingebaut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/class_heatpump.py | 44 ++++++++++++-- modules/class_pv_forecast.py | 35 ++++++++--- modules/visualize.py | 14 ++++- test.py | 115 ++++++++++++++++++++++++++--------- 4 files changed, 164 insertions(+), 44 deletions(-) diff --git a/modules/class_heatpump.py b/modules/class_heatpump.py index f037b6f..4af5709 100644 --- a/modules/class_heatpump.py +++ b/modules/class_heatpump.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta, timezone import numpy as np from pprint import pprint -# Lade die .npz-Datei beim Start der Anwendung + class Waermepumpe: def __init__(self, max_heizleistung, prediction_hours): self.max_heizleistung = max_heizleistung @@ -21,9 +21,11 @@ class Waermepumpe: return heizleistung def elektrische_leistung_berechnen(self, aussentemperatur): - heizleistung = self.heizleistung_berechnen(aussentemperatur) - cop = self.cop_berechnen(aussentemperatur) - return heizleistung / cop + #heizleistung = self.heizleistung_berechnen(aussentemperatur) + #cop = self.cop_berechnen(aussentemperatur) + + return 1164 -77.8*aussentemperatur + 1.62*aussentemperatur**2.0 + #1253.0*np.math.pow(aussentemperatur,-0.0682) def simulate_24h(self, temperaturen): leistungsdaten = [] @@ -37,6 +39,40 @@ class Waermepumpe: leistungsdaten.append(elektrische_leistung) return leistungsdaten +# # Lade die .npz-Datei beim Start der Anwendung +# class Waermepumpe: + # def __init__(self, max_heizleistung, prediction_hours): + # self.max_heizleistung = max_heizleistung + # self.prediction_hours = prediction_hours + + # def cop_berechnen(self, aussentemperatur): + # cop = 3.0 + (aussentemperatur-0) * 0.1 + # return max(cop, 1) + + + # def heizleistung_berechnen(self, aussentemperatur): + # #235.092 kWh + Temperatur * -11.645 + # heizleistung = (((235.0) + aussentemperatur*(-11.645))*1000)/24.0 + # heizleistung = min(self.max_heizleistung,heizleistung) + # return heizleistung + + # def elektrische_leistung_berechnen(self, aussentemperatur): + # heizleistung = self.heizleistung_berechnen(aussentemperatur) + # cop = self.cop_berechnen(aussentemperatur) + # return heizleistung / cop + + # def simulate_24h(self, temperaturen): + # leistungsdaten = [] + + # # Überprüfen, ob das Temperaturarray die richtige Größe hat + # if len(temperaturen) != self.prediction_hours: + # raise ValueError("Das Temperaturarray muss genau "+str(self.prediction_hours)+" Einträge enthalten, einen für jede Stunde des Tages.") + + # for temp in temperaturen: + # elektrische_leistung = self.elektrische_leistung_berechnen(temp) + # leistungsdaten.append(elektrische_leistung) + # return leistungsdaten + diff --git a/modules/class_pv_forecast.py b/modules/class_pv_forecast.py index 1e6efde..3e65731 100644 --- a/modules/class_pv_forecast.py +++ b/modules/class_pv_forecast.py @@ -52,16 +52,35 @@ class PVForecast: def process_data(self, data): self.meta = data.get('meta', {}) - values = data.get('values', [])[0] - for value in values: + all_values = data.get('values', []) + + # Berechnung der Summe der DC- und AC-Leistungen für jeden Zeitstempel + for i in range(len(all_values[0])): # Annahme, dass alle Listen gleich lang sind + sum_dc_power = sum(values[i]['dcPower'] for values in all_values) + sum_ac_power = sum(values[i]['power'] for values in all_values) + + # Erstellen eines ForecastData-Objekts mit den summierten Werten forecast = ForecastData( - date_time=value.get('datetime'), - dc_power=value.get('dcPower'), - ac_power=value.get('power'), - windspeed_10m=value.get('windspeed_10m'), - temperature=value.get('temperature') + date_time=all_values[0][i].get('datetime'), + dc_power=sum_dc_power, + ac_power=sum_ac_power, + # Optional: Weitere Werte wie Windspeed und Temperature, falls benötigt + windspeed_10m=all_values[0][i].get('windspeed_10m'), + temperature=all_values[0][i].get('temperature') ) - self.forecast_data.append(forecast) + + self.forecast_data.append(forecast) + + # values = data.get('values', [])[0] + # for value in values: + # forecast = ForecastData( + # date_time=value.get('datetime'), + # dc_power=value.get('dcPower'), + # ac_power=value.get('power'), + # windspeed_10m=value.get('windspeed_10m'), + # temperature=value.get('temperature') + # ) + # self.forecast_data.append(forecast) def load_data_from_file(self, filepath): with open(filepath, 'r') as file: diff --git a/modules/visualize.py b/modules/visualize.py index 6ae5f12..8d06402 100644 --- a/modules/visualize.py +++ b/modules/visualize.py @@ -3,7 +3,7 @@ from modules.class_load_container import Gesamtlast # Stellen Sie sicher, dass import matplotlib.pyplot as plt -def visualisiere_ergebnisse(gesamtlast,leistung_haushalt,leistung_wp, pv_forecast, strompreise, ergebnisse, soc_eauto, discharge_hours, laden_moeglich): +def visualisiere_ergebnisse(gesamtlast,leistung_haushalt,leistung_wp, pv_forecast, strompreise, ergebnisse, soc_eauto, discharge_hours, laden_moeglich, temperature): # Last und PV-Erzeugung plt.figure(figsize=(14, 10)) @@ -70,7 +70,17 @@ def visualisiere_ergebnisse(gesamtlast,leistung_haushalt,leistung_wp, pv_forecas ax1.axvspan(hour, hour+1, color='green',ymax=value, alpha=0.3, label='Lademöglichkeit' if hour == 0 else "") ax1.legend(loc='upper left') - + ax1 = plt.subplot(3, 2, 6) + ax1.plot(stunden, temperature, label='Temperatur °C', marker='x') + + + ax2 = ax1.twinx() + ax2.plot(stunden, leistung_wp, label='Wärmepumpe W', marker='x') + plt.legend(loc='upper left') + + + + plt.grid(True) diff --git a/test.py b/test.py index dbd421f..ead6618 100644 --- a/test.py +++ b/test.py @@ -37,7 +37,7 @@ discharge_array = np.full(prediction_hours,1) #np.array([1, 0, 1, 0, 1, 1, 1, 1, laden_moeglich = np.full(prediction_hours,1) # np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0]) #np.full(prediction_hours,1) eauto = EAuto(soc=10, capacity = 60000, power_charge = 7000, load_allowed = laden_moeglich) -min_soc_eauto = 100 +min_soc_eauto = 10 hohe_strafe = 10.0 @@ -60,8 +60,9 @@ gesamtlast.hinzufuegen("Haushalt", leistung_haushalt) # PV Forecast ############### #PVforecast = PVForecast(filepath=os.path.join(r'test_data', r'pvprognose.json')) -PVforecast = PVForecast(prediction_hours = prediction_hours, url="https://api.akkudoktor.net/forecast?lat=50.8588&lon=7.3747&power=5400&azimuth=-10&tilt=7&powerInvertor=2500&horizont=20,40,30,30&power=4800&azimuth=-90&tilt=7&powerInvertor=2500&horizont=20,40,45,50&power=1480&azimuth=-90&tilt=70&powerInvertor=1120&horizont=60,45,30,70&power=1600&azimuth=5&tilt=60&powerInvertor=1200&horizont=60,45,30,70&past_days=5&cellCoEff=-0.36&inverterEfficiency=0.8&albedo=0.25&timezone=Europe%2FBerlin&hourly=relativehumidity_2m%2Cwindspeed_10m") +PVforecast = PVForecast(prediction_hours = prediction_hours, url="https://api.akkudoktor.net/forecast?lat=50.8588&lon=7.3747&power=5000&azimuth=-10&tilt=7&powerInvertor=10000&horizont=20,27,22,20&power=4800&azimuth=-90&tilt=7&powerInvertor=10000&horizont=30,30,30,50&power=1400&azimuth=-40&tilt=60&powerInvertor=2000&horizont=60,30,0,30&power=1600&azimuth=5&tilt=45&powerInvertor=1400&horizont=45,25,30,60&past_days=5&cellCoEff=-0.36&inverterEfficiency=0.8&albedo=0.25&timezone=Europe%2FBerlin&hourly=relativehumidity_2m%2Cwindspeed_10m") pv_forecast = PVforecast.get_pv_forecast_for_date_range(date_now,date) #get_forecast_for_date(date) + temperature_forecast = PVforecast.get_temperature_for_date_range(date_now,date) @@ -183,45 +184,46 @@ print("Start Lösung:", start_solution) -# Werkzeug-Setup -creator.create("FitnessMin", base.Fitness, weights=(-1.0,)) -creator.create("Individual", list, fitness=creator.FitnessMin) +# # Werkzeug-Setup +# creator.create("FitnessMin", base.Fitness, weights=(-1.0,)) +# creator.create("Individual", list, fitness=creator.FitnessMin) -toolbox = base.Toolbox() +# toolbox = base.Toolbox() -toolbox.register("attr_bool", random.randint, 0, 1) -toolbox.register("attr_float", random.uniform, 0.0, 1.0) -toolbox.register("individual", tools.initCycle, creator.Individual, (toolbox.attr_bool,toolbox.attr_float), n=prediction_hours) +# toolbox.register("attr_bool", random.randint, 0, 1) +# toolbox.register("attr_float", random.uniform, 0.0, 1.0) +# toolbox.register("individual", tools.initCycle, creator.Individual, (toolbox.attr_bool,toolbox.attr_float), n=prediction_hours) -start_individual = toolbox.individual() -start_individual[:] = start_solution +# start_individual = toolbox.individual() +# start_individual[:] = start_solution -toolbox.register("population", tools.initRepeat, list, toolbox.individual) +# toolbox.register("population", tools.initRepeat, list, toolbox.individual) -toolbox.register("evaluate", evaluate) -toolbox.register("mate", tools.cxTwoPoint) -toolbox.register("mutate", tools.mutFlipBit, indpb=0.05) -toolbox.register("select", tools.selTournament, tournsize=3) +# toolbox.register("evaluate", evaluate) +# toolbox.register("mate", tools.cxTwoPoint) +# toolbox.register("mutate", tools.mutFlipBit, indpb=0.05) +# toolbox.register("select", tools.selTournament, tournsize=3) -# Genetischer Algorithmus -def optimize(): - population = toolbox.population(n=1000) - population[0] = start_individual - hof = tools.HallOfFame(1) +# # Genetischer Algorithmus +# def optimize(): + # population = toolbox.population(n=1000) + # population[0] = start_individual + # hof = tools.HallOfFame(1) - stats = tools.Statistics(lambda ind: ind.fitness.values) - stats.register("avg", np.mean) - stats.register("min", np.min) - stats.register("max", np.max) + # stats = tools.Statistics(lambda ind: ind.fitness.values) + # stats.register("avg", np.mean) + # stats.register("min", np.min) + # stats.register("max", np.max) - algorithms.eaMuPlusLambda(population, toolbox, 100, 200, cxpb=0.5, mutpb=0.2, ngen=1000, stats=stats, halloffame=hof, verbose=True) - #algorithms.eaSimple(population, toolbox, cxpb=0.2, mutpb=0.2, ngen=1000, stats=stats, halloffame=hof, verbose=True) - return hof[0] + # algorithms.eaMuPlusLambda(population, toolbox, 100, 200, cxpb=0.5, mutpb=0.2, ngen=1000, stats=stats, halloffame=hof, verbose=True) + # #algorithms.eaSimple(population, toolbox, cxpb=0.2, mutpb=0.2, ngen=1000, stats=stats, halloffame=hof, verbose=True) + # return hof[0] -best_solution = optimize() +# best_solution = optimize() +best_solution = start_solution print("Beste Lösung:", best_solution) #ems.set_akku_discharge_hours(best_solution) @@ -232,7 +234,60 @@ print(soc_eauto) pprint(o) pprint(eauto.get_stuendlicher_soc()) -visualisiere_ergebnisse(gesamtlast,leistung_haushalt,leistung_wp, pv_forecast, specific_date_prices, o,soc_eauto,best_solution[0::2],best_solution[1::2] ) + + + + +# # Werkzeug-Setup +# creator.create("FitnessMin", base.Fitness, weights=(-1.0,)) +# creator.create("Individual", list, fitness=creator.FitnessMin) + +# toolbox = base.Toolbox() + + + + +# toolbox.register("attr_bool", random.randint, 0, 1) +# toolbox.register("attr_float", random.uniform, 0.0, 1.0) +# toolbox.register("individual", tools.initCycle, creator.Individual, (toolbox.attr_bool,toolbox.attr_float), n=prediction_hours) + +# start_individual = toolbox.individual() +# start_individual[:] = start_solution + +# toolbox.register("population", tools.initRepeat, list, toolbox.individual) + +# toolbox.register("evaluate", evaluate) +# toolbox.register("mate", tools.cxTwoPoint) +# toolbox.register("mutate", tools.mutFlipBit, indpb=0.05) +# toolbox.register("select", tools.selTournament, tournsize=3) + +# # Genetischer Algorithmus +# def optimize(): + # population = toolbox.population(n=1000) + # population[0] = start_individual + # hof = tools.HallOfFame(1) + + # stats = tools.Statistics(lambda ind: ind.fitness.values) + # stats.register("avg", np.mean) + # stats.register("min", np.min) + # stats.register("max", np.max) + + # algorithms.eaMuPlusLambda(population, toolbox, 100, 200, cxpb=0.5, mutpb=0.2, ngen=1000, stats=stats, halloffame=hof, verbose=True) + # #algorithms.eaSimple(population, toolbox, cxpb=0.2, mutpb=0.2, ngen=1000, stats=stats, halloffame=hof, verbose=True) + # return hof[0] + +# best_solution = optimize() +# print("Beste Lösung:", best_solution) + +# #ems.set_akku_discharge_hours(best_solution) +# o,eauto = evaluate_inner(best_solution) + +# soc_eauto = eauto.get_stuendlicher_soc() +# print(soc_eauto) +# pprint(o) +# pprint(eauto.get_stuendlicher_soc()) + +visualisiere_ergebnisse(gesamtlast,leistung_haushalt,leistung_wp, pv_forecast, specific_date_prices, o,soc_eauto,best_solution[0::2],best_solution[1::2] , temperature_forecast) # for data in forecast.get_forecast_data():