mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-10-11 20:06:18 +00:00
Discharge Mask Bug, Tests updated, simple Price Forecast with linear weighting
This commit is contained in:
@@ -436,13 +436,22 @@ class optimization_problem:
|
||||
|
||||
# New check: Activate discharge when battery SoC is 0
|
||||
battery_soc_per_hour = np.array(
|
||||
o.get("Battery_SoC_pro_Stunde", [])
|
||||
o.get("akku_soc_pro_stunde", [])
|
||||
) # Example key for battery SoC
|
||||
|
||||
if battery_soc_per_hour is not None:
|
||||
if battery_soc_per_hour is None or discharge_hours_bin is None:
|
||||
raise ValueError("battery_soc_per_hour or discharge_hours_bin is None")
|
||||
min_length = min(battery_soc_per_hour.size, discharge_hours_bin.size)
|
||||
battery_soc_per_hour_tail = battery_soc_per_hour[-min_length:]
|
||||
discharge_hours_bin_tail = discharge_hours_bin[-min_length:]
|
||||
len_ac = len(self._config.eos.available_charging_rates_in_percentage)
|
||||
|
||||
# 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
|
||||
zero_soc_mask = battery_soc_per_hour_tail == 0
|
||||
discharge_hours_bin_tail[zero_soc_mask] = (
|
||||
len_ac + 2
|
||||
) # Activate discharge for these hours
|
||||
|
||||
# Merge the updated discharge_hours_bin back into the individual
|
||||
adjusted_individual = self.merge_individual(
|
||||
|
@@ -155,24 +155,25 @@ class HourlyElectricityPriceForecast:
|
||||
raise ValueError(
|
||||
"Not enough data to calculate the average for the last 7 days.", price_data
|
||||
)
|
||||
# Calculate the overall average price across all data
|
||||
# overall_average_price = np.mean(price_data)
|
||||
|
||||
# Create an array of 24 hourly values filled with the overall average
|
||||
# average_prices = np.full(24, overall_average_price)
|
||||
|
||||
# print("Overall AVG (duplicated for 24 hours):", average_prices)
|
||||
# return average_prices
|
||||
# Reshape the data into a 7x24 matrix (7 rows for days, 24 columns for hours)
|
||||
price_matrix = price_data.reshape(-1, 24)
|
||||
|
||||
# Calculate the average price for each hour across the 7 days
|
||||
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
|
||||
final_weights = np.linspace(1, 0, price_matrix.shape[1])
|
||||
|
||||
# Weight last known price linear falling
|
||||
average_prices_with_final_weight = [
|
||||
(average_prices[i] * (1 - final_weights[i]))
|
||||
+ (price_matrix[-1, -1] * (final_weights[i]))
|
||||
for i in range(price_matrix.shape[1])
|
||||
]
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user