From af49072a2e2062a19728d288ae515bdd5755bd6d Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 25 Dec 2024 19:12:38 +0100 Subject: [PATCH 1/3] 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( From 83a048fb83c9388f1afc7028123f55568a54a965 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 26 Dec 2024 07:55:29 +0100 Subject: [PATCH 2/3] Ruff --- src/akkudoktoreos/prediction/price_forecast.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/akkudoktoreos/prediction/price_forecast.py b/src/akkudoktoreos/prediction/price_forecast.py index 7b4fd58..47e4ce1 100644 --- a/src/akkudoktoreos/prediction/price_forecast.py +++ b/src/akkudoktoreos/prediction/price_forecast.py @@ -176,7 +176,6 @@ class HourlyElectricityPriceForecast: return np.array(average_prices_with_final_weight) - def get_price_for_daterange( self, start_date_str: str, end_date_str: str, repeat: bool = False ) -> np.ndarray: From 546400aea656e6edef976da5a22c86ae17d90307 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 26 Dec 2024 07:55:29 +0100 Subject: [PATCH 3/3] Ruff --- .sesskey | 1 - src/akkudoktoreos/prediction/price_forecast.py | 1 - 2 files changed, 2 deletions(-) delete mode 100644 .sesskey diff --git a/.sesskey b/.sesskey deleted file mode 100644 index 8454446..0000000 --- a/.sesskey +++ /dev/null @@ -1 +0,0 @@ -e39e31eb-09f7-46cf-b307-e43453c95009 \ No newline at end of file diff --git a/src/akkudoktoreos/prediction/price_forecast.py b/src/akkudoktoreos/prediction/price_forecast.py index 7b4fd58..47e4ce1 100644 --- a/src/akkudoktoreos/prediction/price_forecast.py +++ b/src/akkudoktoreos/prediction/price_forecast.py @@ -176,7 +176,6 @@ class HourlyElectricityPriceForecast: return np.array(average_prices_with_final_weight) - def get_price_for_daterange( self, start_date_str: str, end_date_str: str, repeat: bool = False ) -> np.ndarray: