base functions

This commit is contained in:
Normann 2025-01-07 00:21:43 +01:00 committed by Andreas
parent 6bcae41213
commit e0bdbdcb81
2 changed files with 7 additions and 6 deletions

View File

@ -13,3 +13,4 @@ pendulum==3.0.0
platformdirs==4.3.6 platformdirs==4.3.6
pvlib==0.11.1 pvlib==0.11.1
pydantic==2.10.4 pydantic==2.10.4
statsmodels==0.14.4

View File

@ -122,7 +122,7 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
self.update_datetime = to_datetime(in_timezone=self.config.timezone) self.update_datetime = to_datetime(in_timezone=self.config.timezone)
return akkudoktor_data return akkudoktor_data
def cap_outliers(data, sigma=2): # remove outliers def cap_outliers(data: np.ndarray, sigma: int = 2) -> np.ndarray:
mean = data.mean() mean = data.mean()
std = data.std() std = data.std()
lower_bound = mean - sigma * std lower_bound = mean - sigma * std
@ -131,13 +131,13 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
return capped_data return capped_data
def predict_ets( def predict_ets(
history, history: np.ndarray, seasonal_periods: int, prediction_hours: int
seasonal_periods, ) -> np.ndarray:
): clean_history = cap_outliers(history)
model = ExponentialSmoothing( model = ExponentialSmoothing(
history, seasonal="add", seasonal_periods=seasonal_periods clean_history, seasonal="add", seasonal_periods=seasonal_periods
).fit() ).fit()
return model.forecast(7 * 24) return model.forecast(prediction_hours)
def _update_data(self, force_update: Optional[bool] = False) -> None: def _update_data(self, force_update: Optional[bool] = False) -> None:
"""Update forecast data in the ElecPriceDataRecord format. """Update forecast data in the ElecPriceDataRecord format.