emhass 0.4.4__py3-none-any.whl → 0.4.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
emhass/command_line.py CHANGED
@@ -383,7 +383,8 @@ def forecast_model_predict(input_data_dict: dict, logger: logging.Logger,
383
383
  return predictions
384
384
 
385
385
  def forecast_model_tune(input_data_dict: dict, logger: logging.Logger,
386
- debug: Optional[bool] = False, mlf: Optional[mlforecaster] = None) -> pd.DataFrame:
386
+ debug: Optional[bool] = False, mlf: Optional[mlforecaster] = None
387
+ ) -> Tuple[pd.DataFrame, mlforecaster]:
387
388
  """Tune a forecast model hyperparameters using bayesian optimization.
388
389
 
389
390
  :param input_data_dict: A dictionnary with multiple data used by the action functions
@@ -417,7 +418,7 @@ def forecast_model_tune(input_data_dict: dict, logger: logging.Logger,
417
418
  filename = model_type+'_mlf.pkl'
418
419
  with open(pathlib.Path(root) / filename, 'wb') as outp:
419
420
  pickle.dump(mlf, outp, pickle.HIGHEST_PROTOCOL)
420
- return df_pred_optim
421
+ return df_pred_optim, mlf
421
422
 
422
423
  def publish_data(input_data_dict: dict, logger: logging.Logger,
423
424
  save_data_to_file: Optional[bool] = False,
@@ -590,7 +591,7 @@ def main():
590
591
  _, _, mlf = forecast_model_fit(input_data_dict, logger, debug=args.debug)
591
592
  else:
592
593
  mlf = None
593
- df_pred_optim = forecast_model_tune(input_data_dict, logger, debug=args.debug, mlf=mlf)
594
+ df_pred_optim, mlf = forecast_model_tune(input_data_dict, logger, debug=args.debug, mlf=mlf)
594
595
  opt_res = None
595
596
  elif args.action == 'publish-data':
596
597
  opt_res = publish_data(input_data_dict, logger)
@@ -609,7 +610,7 @@ def main():
609
610
  elif args.action == 'forecast-model-predict':
610
611
  return df_pred
611
612
  elif args.action == 'forecast-model-tune':
612
- return df_pred_optim
613
+ return df_pred_optim, mlf
613
614
 
614
615
  if __name__ == '__main__':
615
616
  main()
emhass/utils.py CHANGED
@@ -244,63 +244,62 @@ def treat_runtimeparams(runtimeparams: str, params: str, retrieve_hass_conf: dic
244
244
  logger.warning("This value in prod_price_forecast was detected as non digits: "+str(x))
245
245
  else:
246
246
  params['passed_data']['prod_price_forecast'] = None
247
- # Treat passed data for forecast model fit/predict/tune
248
- if set_type == 'forecast-model-fit' or set_type == 'forecast-model-predict' or set_type == 'forecast-model-tune':
249
- if 'days_to_retrieve' not in runtimeparams.keys():
250
- days_to_retrieve = 30
251
- else:
252
- days_to_retrieve = runtimeparams['days_to_retrieve']
253
- params['passed_data']['days_to_retrieve'] = days_to_retrieve
254
- if 'model_type' not in runtimeparams.keys():
255
- model_type = "load_forecast"
256
- else:
257
- model_type = runtimeparams['model_type']
258
- params['passed_data']['model_type'] = model_type
259
- if 'var_model' not in runtimeparams.keys():
260
- var_model = "sensor.power_load_no_var_loads"
261
- else:
262
- var_model = runtimeparams['var_model']
263
- params['passed_data']['var_model'] = var_model
264
- if 'sklearn_model' not in runtimeparams.keys():
265
- sklearn_model = "KNeighborsRegressor"
266
- else:
267
- sklearn_model = runtimeparams['sklearn_model']
268
- params['passed_data']['sklearn_model'] = sklearn_model
269
- if 'num_lags' not in runtimeparams.keys():
270
- num_lags = 48
271
- else:
272
- num_lags = runtimeparams['num_lags']
273
- params['passed_data']['num_lags'] = num_lags
274
- if 'split_date_delta' not in runtimeparams.keys():
275
- split_date_delta = '48h'
276
- else:
277
- split_date_delta = runtimeparams['split_date_delta']
278
- params['passed_data']['split_date_delta'] = split_date_delta
279
- if 'perform_backtest' not in runtimeparams.keys():
280
- perform_backtest = False
281
- else:
282
- perform_backtest = runtimeparams['perform_backtest']
283
- params['passed_data']['perform_backtest'] = perform_backtest
284
- if 'model_predict_publish' not in runtimeparams.keys():
285
- model_predict_publish = False
286
- else:
287
- model_predict_publish = runtimeparams['model_predict_publish']
288
- params['passed_data']['model_predict_publish'] = model_predict_publish
289
- if 'model_predict_entity_id' not in runtimeparams.keys():
290
- model_predict_entity_id = "sensor.p_load_forecast_custom_model"
291
- else:
292
- model_predict_entity_id = runtimeparams['model_predict_entity_id']
293
- params['passed_data']['model_predict_entity_id'] = model_predict_entity_id
294
- if 'model_predict_unit_of_measurement' not in runtimeparams.keys():
295
- model_predict_unit_of_measurement = "W"
296
- else:
297
- model_predict_unit_of_measurement = runtimeparams['model_predict_unit_of_measurement']
298
- params['passed_data']['model_predict_unit_of_measurement'] = model_predict_unit_of_measurement
299
- if 'model_predict_friendly_name' not in runtimeparams.keys():
300
- model_predict_friendly_name = "Load Power Forecast custom ML model"
301
- else:
302
- model_predict_friendly_name = runtimeparams['model_predict_friendly_name']
303
- params['passed_data']['model_predict_friendly_name'] = model_predict_friendly_name
247
+ # Treat passed data for forecast model fit/predict/tune at runtime
248
+ if 'days_to_retrieve' not in runtimeparams.keys():
249
+ days_to_retrieve = 30
250
+ else:
251
+ days_to_retrieve = runtimeparams['days_to_retrieve']
252
+ params['passed_data']['days_to_retrieve'] = days_to_retrieve
253
+ if 'model_type' not in runtimeparams.keys():
254
+ model_type = "load_forecast"
255
+ else:
256
+ model_type = runtimeparams['model_type']
257
+ params['passed_data']['model_type'] = model_type
258
+ if 'var_model' not in runtimeparams.keys():
259
+ var_model = "sensor.power_load_no_var_loads"
260
+ else:
261
+ var_model = runtimeparams['var_model']
262
+ params['passed_data']['var_model'] = var_model
263
+ if 'sklearn_model' not in runtimeparams.keys():
264
+ sklearn_model = "KNeighborsRegressor"
265
+ else:
266
+ sklearn_model = runtimeparams['sklearn_model']
267
+ params['passed_data']['sklearn_model'] = sklearn_model
268
+ if 'num_lags' not in runtimeparams.keys():
269
+ num_lags = 48
270
+ else:
271
+ num_lags = runtimeparams['num_lags']
272
+ params['passed_data']['num_lags'] = num_lags
273
+ if 'split_date_delta' not in runtimeparams.keys():
274
+ split_date_delta = '48h'
275
+ else:
276
+ split_date_delta = runtimeparams['split_date_delta']
277
+ params['passed_data']['split_date_delta'] = split_date_delta
278
+ if 'perform_backtest' not in runtimeparams.keys():
279
+ perform_backtest = False
280
+ else:
281
+ perform_backtest = runtimeparams['perform_backtest']
282
+ params['passed_data']['perform_backtest'] = perform_backtest
283
+ if 'model_predict_publish' not in runtimeparams.keys():
284
+ model_predict_publish = False
285
+ else:
286
+ model_predict_publish = runtimeparams['model_predict_publish']
287
+ params['passed_data']['model_predict_publish'] = model_predict_publish
288
+ if 'model_predict_entity_id' not in runtimeparams.keys():
289
+ model_predict_entity_id = "sensor.p_load_forecast_custom_model"
290
+ else:
291
+ model_predict_entity_id = runtimeparams['model_predict_entity_id']
292
+ params['passed_data']['model_predict_entity_id'] = model_predict_entity_id
293
+ if 'model_predict_unit_of_measurement' not in runtimeparams.keys():
294
+ model_predict_unit_of_measurement = "W"
295
+ else:
296
+ model_predict_unit_of_measurement = runtimeparams['model_predict_unit_of_measurement']
297
+ params['passed_data']['model_predict_unit_of_measurement'] = model_predict_unit_of_measurement
298
+ if 'model_predict_friendly_name' not in runtimeparams.keys():
299
+ model_predict_friendly_name = "Load Power Forecast custom ML model"
300
+ else:
301
+ model_predict_friendly_name = runtimeparams['model_predict_friendly_name']
302
+ params['passed_data']['model_predict_friendly_name'] = model_predict_friendly_name
304
303
  # Treat optimization configuration parameters passed at runtime
305
304
  if 'num_def_loads' in runtimeparams.keys():
306
305
  optim_conf['num_def_loads'] = runtimeparams['num_def_loads']
emhass/web_server.py CHANGED
@@ -31,15 +31,15 @@ def get_injection_dict(df, plot_size = 1366):
31
31
  # Create plots
32
32
  cols_p = [i for i in df.columns.to_list() if 'P_' in i]
33
33
  fig_0 = px.line(df[cols_p], title='Systems powers schedule after optimization results',
34
- template='plotly_white', width=plot_size, height=0.5*plot_size, line_shape="hv")
34
+ template='presentation', width=plot_size, height=0.5*plot_size, line_shape="hv")
35
35
  fig_0.update_layout(xaxis_title='Timestamp', yaxis_title='System powers (W)')
36
36
  if 'SOC_opt' in df.columns.to_list():
37
37
  fig_1 = px.line(df['SOC_opt'], title='Battery state of charge schedule after optimization results',
38
- template='plotly_white', width=plot_size, height=0.5*plot_size, line_shape="hv")
38
+ template='presentation', width=plot_size, height=0.5*plot_size, line_shape="hv")
39
39
  fig_1.update_layout(xaxis_title='Timestamp', yaxis_title='Battery SOC (%)')
40
40
  cols_cost = [i for i in df.columns.to_list() if 'cost_' in i or 'unit_' in i]
41
41
  fig_2 = px.line(df[cols_cost], title='Systems costs obtained from optimization results',
42
- template='plotly_white', width=plot_size, height=0.5*plot_size, line_shape="hv")
42
+ template='presentation', width=plot_size, height=0.5*plot_size, line_shape="hv")
43
43
  fig_2.update_layout(xaxis_title='Timestamp', yaxis_title='System costs (currency)')
44
44
  # Get full path to image
45
45
  image_path_0 = fig_0.to_html(full_html=False, default_width='75%')
@@ -66,7 +66,7 @@ def get_injection_dict(df, plot_size = 1366):
66
66
 
67
67
  def get_injection_dict_forecast_model_fit(df_fit_pred, mlf):
68
68
  fig = df_fit_pred.plot()
69
- fig.layout.template = 'plotly_white'
69
+ fig.layout.template = 'presentation'
70
70
  fig.update_yaxes(title_text = mlf.model_type)
71
71
  fig.update_xaxes(title_text = "Time")
72
72
  image_path_0 = fig.to_html(full_html=False, default_width='75%')
@@ -78,6 +78,20 @@ def get_injection_dict_forecast_model_fit(df_fit_pred, mlf):
78
78
  injection_dict['figure_0'] = image_path_0
79
79
  return injection_dict
80
80
 
81
+ def get_injection_dict_forecast_model_tune(df_pred_optim, mlf):
82
+ fig = df_pred_optim.plot()
83
+ fig.layout.template = 'presentation'
84
+ fig.update_yaxes(title_text = mlf.model_type)
85
+ fig.update_xaxes(title_text = "Time")
86
+ image_path_0 = fig.to_html(full_html=False, default_width='75%')
87
+ # The dict of plots
88
+ injection_dict = {}
89
+ injection_dict['title'] = '<h2>Custom machine learning forecast model tune</h2>'
90
+ injection_dict['subsubtitle0'] = '<h4>Performed a tuning routine using bayesian optimization for '+mlf.model_type+'</h4>'
91
+ injection_dict['subsubtitle0'] = '<h4>Forecasting variable '+mlf.var_model+'</h4>'
92
+ injection_dict['figure_0'] = image_path_0
93
+ return injection_dict
94
+
81
95
  def build_params(params, options, addon):
82
96
  if addon == 1:
83
97
  # Updating variables in retrieve_hass_conf
@@ -207,12 +221,9 @@ def action_call(action_name):
207
221
  return make_response(msg, 201)
208
222
  elif action_name == 'forecast-model-tune':
209
223
  app.logger.info(" >> Performing a machine learning forecast model tune...")
210
- df_pred_optim = forecast_model_tune(input_data_dict, app.logger)
211
- table1 = df_pred_optim.reset_index().to_html(classes='mystyle', index=False)
212
- injection_dict = {}
213
- injection_dict['title'] = '<h2>Custom machine learning forecast model tuning</h2>'
214
- injection_dict['subsubtitle0'] = '<h4>Performed a tuning routine using bayesian optimization</h4>'
215
- injection_dict['table1'] = table1
224
+ df_pred_optim, mlf = forecast_model_tune(input_data_dict, app.logger)
225
+ injection_dict = get_injection_dict_forecast_model_tune(
226
+ df_pred_optim, mlf)
216
227
  with open(str(data_path / 'injection_dict.pkl'), "wb") as fid:
217
228
  pickle.dump(injection_dict, fid)
218
229
  msg = f'EMHASS >> Action forecast-model-tune executed... \n'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: emhass
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: An Energy Management System for Home Assistant
5
5
  Home-page: https://github.com/davidusb-geek/emhass
6
6
  Author: David HERNANDEZ
@@ -1,15 +1,15 @@
1
1
  emhass/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- emhass/command_line.py,sha256=N32ULIn7McmwnNITdVNwz_jR4mIVwDHopOBn81mZm-s,33553
2
+ emhass/command_line.py,sha256=IbHexJGwDnqDVvRN1V07QXmE5sm1XtO8oHhBjp87Fi4,33594
3
3
  emhass/forecast.py,sha256=FGpqMsomnwhcB3iJBV6feeFdRGlwN64qB9nZBvpliAE,42845
4
4
  emhass/machine_learning_forecaster.py,sha256=FaWZv8aMS8ihx1Z6RhY6yuNkbkouZV8CujXAMmcFnAI,14966
5
5
  emhass/optimization.py,sha256=QL9LpOhhpo_YgmF3_lvXWPGdz-ZeH62_zUCwm2swlyM,30582
6
6
  emhass/retrieve_hass.py,sha256=lsLSiWB2XC1TTlAw_GR7YWjVXti4ZXKhICROST8UlTw,15888
7
- emhass/utils.py,sha256=ZLMTjNumyRfSY3Wjk3TQ1YDtCd_3hiLPnWJFyRIHE1w,22776
8
- emhass/web_server.py,sha256=zAAujAHbqDZDOPRpAV5sKjPfvWNL1IDtyOoosZ06JRY,17790
7
+ emhass/utils.py,sha256=_EuITuTur7RwI3_oBRWEmEQk1F_Ke1wZ4pOSp57VRC4,22445
8
+ emhass/web_server.py,sha256=wQT0HD8N86zC2V28L4zVUqVfP6sj0U-ZmltoUc51rXs,18255
9
9
  emhass/static/style.css,sha256=5qGJl0MZGSaSvr0HUcGQ9UgMtDKP2CiyE-1H-jbsLuU,6760
10
10
  emhass/templates/index.html,sha256=1l0V3hrK-BvTmtRt4YN-3Wqvi-BrkT5oakMgWF2tQEA,5602
11
- emhass-0.4.4.dist-info/METADATA,sha256=GpdbB48IBWBN_B6ifJN5ERBCgoz1EmYu8-88LZwrwEc,24995
12
- emhass-0.4.4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
13
- emhass-0.4.4.dist-info/entry_points.txt,sha256=tJULCm7mHGYb_IxyzPN_4KFYvhxv209_jq68jPiByy0,53
14
- emhass-0.4.4.dist-info/top_level.txt,sha256=L7fIX4awfmxQbAePtSdVg2e6x_HhghfReHfsKSpKr9I,7
15
- emhass-0.4.4.dist-info/RECORD,,
11
+ emhass-0.4.5.dist-info/METADATA,sha256=6bxTtY3oC4I7RTRrFagmLF9e_bYYhEDe8C7ijmlBkpg,24995
12
+ emhass-0.4.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
13
+ emhass-0.4.5.dist-info/entry_points.txt,sha256=tJULCm7mHGYb_IxyzPN_4KFYvhxv209_jq68jPiByy0,53
14
+ emhass-0.4.5.dist-info/top_level.txt,sha256=L7fIX4awfmxQbAePtSdVg2e6x_HhghfReHfsKSpKr9I,7
15
+ emhass-0.4.5.dist-info/RECORD,,
File without changes