Skip to content

Commit

Permalink
Fix - Fixed wrong init of opt object in unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidusb-geek committed Jun 10, 2022
1 parent 7d6d13b commit afc2a95
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Improving documentation, added "what is this" section and added some infographics.
- Added new forecasts methods chapter in documentation.
- Added publish of sensors for p_grid_forecast & total value of cost function.
- Implemented now/current value forecast correction when using MPC.

## [0.3.15] - 2022-06-06
### Fix
Expand Down
10 changes: 8 additions & 2 deletions src/emhass/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ def get_power_from_weather(self, df_weather: pd.DataFrame,
P_PV_forecast = mc.results.ac

if set_mix_forecast:
P_PV_forecast = forecast.get_mix_forecast(df_now, P_PV_forecast, 0.5, 0.5, 'sensor.power_photovoltaics')
P_PV_forecast = forecast.get_mix_forecast(
df_now, P_PV_forecast,
self.params['passed_data']['alpha'], self.params['passed_data']['beta'],
'sensor.power_photovoltaics')

return P_PV_forecast

Expand Down Expand Up @@ -532,7 +535,10 @@ def get_load_forecast(self, days_min_load_forecast: Optional[int] = 3, method: O

P_Load_forecast = copy.deepcopy(forecast_out['yhat'])
if set_mix_forecast:
P_Load_forecast = forecast.get_mix_forecast(df_now, P_Load_forecast, 0.5, 0.5, 'sensor.power_load_no_var_loads')
P_Load_forecast = forecast.get_mix_forecast(
df_now, P_Load_forecast,
self.params['passed_data']['alpha'], self.params['passed_data']['beta'],
'sensor.power_load_no_var_loads')

return P_Load_forecast

Expand Down
12 changes: 11 additions & 1 deletion src/emhass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def treat_runtimeparams(runtimeparams: str, params:str, retrieve_hass_conf: dict
params = json.loads(params)
else:
params = {'passed_data':{'pv_power_forecast':None,'load_power_forecast':None,'load_cost_forecast':None,'prod_price_forecast':None,
'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None}}
'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None,'alpha':None,'beta':None}}
freq = int(retrieve_hass_conf['freq'].seconds/60.0)
delta_forecast = int(optim_conf['delta_forecast'].days)
forecast_dates = get_forecast_dates(freq, delta_forecast)
Expand All @@ -134,6 +134,16 @@ def treat_runtimeparams(runtimeparams: str, params:str, retrieve_hass_conf: dict
else:
def_total_hours = runtimeparams['def_total_hours']
params['passed_data']['def_total_hours'] = def_total_hours
if 'alpha' not in runtimeparams.keys():
alpha = 0.5
else:
alpha = runtimeparams['alpha']
params['passed_data']['alpha'] = alpha
if 'beta' not in runtimeparams.keys():
beta = 0.5
else:
beta = runtimeparams['beta']
params['passed_data']['beta'] = beta
forecast_dates = copy.deepcopy(forecast_dates)[0:prediction_horizon]
if 'pv_power_forecast' in runtimeparams.keys():
if type(runtimeparams['pv_power_forecast']) == list and len(runtimeparams['pv_power_forecast']) >= len(forecast_dates):
Expand Down
2 changes: 1 addition & 1 deletion src/emhass/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def build_params(params, options, addon):
# The params dict
params['params_secrets'] = params_secrets
params['passed_data'] = {'pv_power_forecast':None,'load_power_forecast':None,'load_cost_forecast':None,'prod_price_forecast':None,
'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None}
'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None,'alpha':None,'beta':None}
return params

@app.route('/')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUp(self):
self.df_input_data_dayahead = pd.concat([self.P_PV_forecast, self.P_load_forecast], axis=1)
self.df_input_data_dayahead.columns = ['P_PV_forecast', 'P_load_forecast']
self.opt = optimization(retrieve_hass_conf, optim_conf, plant_conf,
self.fcst.var_load_cost, self.fcst.var_prod_price, self.days_list,
self.fcst.var_load_cost, self.fcst.var_prod_price,
'profit', root, logger)
self.input_data_dict = {
'root': root,
Expand Down

0 comments on commit afc2a95

Please sign in to comment.