mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-07-01 10:06:52 +00:00
Neues Lastprognose Modell mit Korrektur
This commit is contained in:
parent
24c47020fa
commit
afeb80ca08
102
flask_server.py
102
flask_server.py
@ -11,6 +11,7 @@ from modules.class_sommerzeit import *
|
||||
from modules.class_soc_calc import *
|
||||
from modules.visualize import *
|
||||
from modules.class_battery_soc_predictor import *
|
||||
from modules.class_load_corrector import *
|
||||
import os
|
||||
from flask import Flask, send_from_directory
|
||||
from pprint import pprint
|
||||
@ -18,7 +19,7 @@ import matplotlib
|
||||
matplotlib.use('Agg') # Setzt das Backend auf Agg
|
||||
import matplotlib.pyplot as plt
|
||||
import string
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from deap import base, creator, tools, algorithms
|
||||
from modules.class_optimize import *
|
||||
import numpy as np
|
||||
@ -32,6 +33,32 @@ opt_class = optimization_problem(prediction_hours=48, strafe=10)
|
||||
|
||||
|
||||
|
||||
@app.route('/last_correction', methods=['GET'])
|
||||
def flask_last_correction():
|
||||
if request.method == 'GET':
|
||||
year_energy = float(request.args.get("year_energy"))
|
||||
date_now,date = get_start_enddate(prediction_hours,startdate=datetime.now().date())
|
||||
###############
|
||||
# Load Forecast
|
||||
###############
|
||||
lf = LoadForecast(filepath=r'load_profiles.npz', year_energy=year_energy)
|
||||
#leistung_haushalt = lf.get_daily_stats(date)[0,...] # Datum anpassen
|
||||
leistung_haushalt = lf.get_stats_for_date_range(date_now,date)[0] # Nur Erwartungswert!
|
||||
|
||||
gesamtlast = Gesamtlast(prediction_hours=prediction_hours)
|
||||
gesamtlast.hinzufuegen("Haushalt", leistung_haushalt)
|
||||
|
||||
# ###############
|
||||
# # WP
|
||||
# ##############
|
||||
# leistung_wp = wp.simulate_24h(temperature_forecast)
|
||||
# gesamtlast.hinzufuegen("Heatpump", leistung_wp)
|
||||
|
||||
last = gesamtlast.gesamtlast_berechnen()
|
||||
print(last)
|
||||
#print(specific_date_prices)
|
||||
return jsonify(last.tolist())
|
||||
|
||||
|
||||
@app.route('/soc', methods=['GET'])
|
||||
def flask_soc():
|
||||
@ -65,6 +92,9 @@ def flask_soc():
|
||||
return jsonify("Done")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/strompreis', methods=['GET'])
|
||||
def flask_strompreis():
|
||||
date_now,date = get_start_enddate(prediction_hours,startdate=datetime.now().date())
|
||||
@ -80,13 +110,49 @@ def flask_strompreis():
|
||||
def flask_gesamtlast():
|
||||
if request.method == 'GET':
|
||||
year_energy = float(request.args.get("year_energy"))
|
||||
date_now,date = get_start_enddate(prediction_hours,startdate=datetime.now().date())
|
||||
prediction_hours = int(request.args.get("hours", 48)) # Default to 24 hours if not specified
|
||||
date_now = datetime.now()
|
||||
end_date = (date_now + timedelta(hours=prediction_hours)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
###############
|
||||
# Load Forecast
|
||||
###############
|
||||
# Instantiate LastEstimator and get measured data
|
||||
estimator = LastEstimator()
|
||||
start_date = (date_now - timedelta(days=60)).strftime('%Y-%m-%d') # Example: last 60 days
|
||||
end_date = date_now.strftime('%Y-%m-%d') # Current date
|
||||
|
||||
last_df = estimator.get_last(start_date, end_date)
|
||||
|
||||
selected_columns = last_df[['timestamp', 'Last']]
|
||||
selected_columns['time'] = pd.to_datetime(selected_columns['timestamp']).dt.floor('H')
|
||||
selected_columns['Last'] = pd.to_numeric(selected_columns['Last'], errors='coerce')
|
||||
cleaned_data = selected_columns.dropna()
|
||||
|
||||
# Instantiate LoadForecast
|
||||
lf = LoadForecast(filepath=r'load_profiles.npz', year_energy=year_energy)
|
||||
#leistung_haushalt = lf.get_daily_stats(date)[0,...] # Datum anpassen
|
||||
leistung_haushalt = lf.get_stats_for_date_range(date_now,date)[0] # Nur Erwartungswert!
|
||||
|
||||
# Generate forecast data
|
||||
forecast_list = []
|
||||
for single_date in pd.date_range(cleaned_data['time'].min().date(), cleaned_data['time'].max().date()):
|
||||
date_str = single_date.strftime('%Y-%m-%d')
|
||||
daily_forecast = lf.get_daily_stats(date_str)
|
||||
mean_values = daily_forecast[0]
|
||||
hours = [single_date + pd.Timedelta(hours=i) for i in range(24)]
|
||||
daily_forecast_df = pd.DataFrame({'time': hours, 'Last Pred': mean_values})
|
||||
forecast_list.append(daily_forecast_df)
|
||||
|
||||
forecast_df = pd.concat(forecast_list, ignore_index=True)
|
||||
|
||||
# Create LoadPredictionAdjuster instance
|
||||
adjuster = LoadPredictionAdjuster(cleaned_data, forecast_df, lf)
|
||||
adjuster.calculate_weighted_mean()
|
||||
adjuster.adjust_predictions()
|
||||
|
||||
# Predict the next hours
|
||||
future_predictions = adjuster.predict_next_hours(prediction_hours)
|
||||
|
||||
leistung_haushalt = future_predictions['Adjusted Pred'].values
|
||||
|
||||
gesamtlast = Gesamtlast(prediction_hours=prediction_hours)
|
||||
gesamtlast.hinzufuegen("Haushalt", leistung_haushalt)
|
||||
@ -99,9 +165,35 @@ def flask_gesamtlast():
|
||||
|
||||
last = gesamtlast.gesamtlast_berechnen()
|
||||
print(last)
|
||||
#print(specific_date_prices)
|
||||
return jsonify(last.tolist())
|
||||
|
||||
|
||||
# # @app.route('/gesamtlast', methods=['GET'])
|
||||
# # def flask_gesamtlast():
|
||||
# # if request.method == 'GET':
|
||||
# # year_energy = float(request.args.get("year_energy"))
|
||||
# # date_now,date = get_start_enddate(prediction_hours,startdate=datetime.now().date())
|
||||
# # ###############
|
||||
# # # Load Forecast
|
||||
# # ###############
|
||||
# # lf = LoadForecast(filepath=r'load_profiles.npz', year_energy=year_energy)
|
||||
# # #leistung_haushalt = lf.get_daily_stats(date)[0,...] # Datum anpassen
|
||||
# # leistung_haushalt = lf.get_stats_for_date_range(date_now,date)[0] # Nur Erwartungswert!
|
||||
|
||||
# # gesamtlast = Gesamtlast(prediction_hours=prediction_hours)
|
||||
# # gesamtlast.hinzufuegen("Haushalt", leistung_haushalt)
|
||||
|
||||
# # # ###############
|
||||
# # # # WP
|
||||
# # # ##############
|
||||
# # # leistung_wp = wp.simulate_24h(temperature_forecast)
|
||||
# # # gesamtlast.hinzufuegen("Heatpump", leistung_wp)
|
||||
|
||||
# # last = gesamtlast.gesamtlast_berechnen()
|
||||
# # print(last)
|
||||
# # #print(specific_date_prices)
|
||||
# # return jsonify(last.tolist())
|
||||
|
||||
@app.route('/pvforecast', methods=['GET'])
|
||||
def flask_pvprognose():
|
||||
if request.method == 'GET':
|
||||
|
Loading…
x
Reference in New Issue
Block a user