From 56aa0ac2f5fc6f593b519a2a45703ccd71149768 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 25 Dec 2024 19:12:38 +0100 Subject: [PATCH] Awattar Price changed to more precise value; if SoC=0 discharge =1 forced. Exp Avg for siple Price Forecast --- src/akkudoktoreos/optimization/genetic.py | 20 +++++++++++++++++-- .../prediction/price_forecast.py | 18 ++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/akkudoktoreos/optimization/genetic.py b/src/akkudoktoreos/optimization/genetic.py index 85be8f3..3395bcb 100644 --- a/src/akkudoktoreos/optimization/genetic.py +++ b/src/akkudoktoreos/optimization/genetic.py @@ -432,9 +432,25 @@ class optimization_problem: discharge_hours_bin, eautocharge_hours_index, washingstart_int ) - individual[:] = adjusted_individual # Aktualisiere das ursprüngliche individual + individual[:] = adjusted_individual - # Berechnung weiterer Metriken + # New check: Activate discharge when battery SoC is 0 + battery_soc_per_hour = np.array( + o.get("Battery_SoC_pro_Stunde", []) + ) # Example key for battery SoC + + if battery_soc_per_hour is not None: + # Find hours where battery SoC is 0 + zero_soc_mask = battery_soc_per_hour == 0 + discharge_hours_bin[zero_soc_mask] = 1 # Activate discharge for these hours + + # Merge the updated discharge_hours_bin back into the individual + adjusted_individual = self.merge_individual( + discharge_hours_bin, eautocharge_hours_index, washingstart_int + ) + individual[:] = adjusted_individual + + # More metrics individual.extra_data = ( # type: ignore[attr-defined] o["Gesamtbilanz_Euro"], o["Gesamt_Verluste"], diff --git a/src/akkudoktoreos/prediction/price_forecast.py b/src/akkudoktoreos/prediction/price_forecast.py index e2313d2..f73b5f9 100644 --- a/src/akkudoktoreos/prediction/price_forecast.py +++ b/src/akkudoktoreos/prediction/price_forecast.py @@ -98,7 +98,7 @@ class HourlyElectricityPriceForecast: # Extract the price from 00:00 of the previous day previous_day_prices = [ - entry["marketpriceEurocentPerKWh"] # + self.charges + entry["marketprice"] # + self.charges for entry in self.prices if previous_day_str in entry["end"] ] @@ -106,19 +106,16 @@ class HourlyElectricityPriceForecast: # Extract all prices for the specified date date_prices = [ - entry["marketpriceEurocentPerKWh"] # + self.charges + entry["marketprice"] # + self.charges for entry in self.prices if date_str in entry["end"] ] - # print(f"getPrice: {len(date_prices)}") # Add the last price of the previous day at the start of the list if len(date_prices) == 23: date_prices.insert(0, last_price_of_previous_day) - # print(np.array(date_prices) / (1000.0 * 100.0)) - # print("PRICE:") - # print(np.array(date_prices) / (1000.0 * 100.0) + self.charges) - return np.array(date_prices) / (1000.0 * 100.0) + self.charges + + return np.array(date_prices) / (1000.0 * 1000.0) + self.charges def get_average_price_last_7_days(self, end_date_str: Optional[str] = None) -> np.ndarray: """Calculate the hourly average electricity price for the last 7 days. @@ -170,8 +167,11 @@ class HourlyElectricityPriceForecast: price_matrix = price_data.reshape(-1, 24) # Calculate the average price for each hour across the 7 days - average_prices = np.mean(price_matrix, axis=0) - # print("AVG:", average_prices) + average_prices = np.average( + price_matrix, + axis=0, + weights=np.array([1, 2, 4, 8, 16, 32, 64]) / np.sum(np.array([1, 2, 4, 8, 16, 32, 64])), + ) return average_prices def get_price_for_daterange(