Skip to content

Commit

Permalink
Merge remote-tracking branch 'david/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gieljnssns committed May 3, 2024
2 parents f7033f3 + 4b45d65 commit be90211
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ protobuf>=3.0.0
pytz>=2021.1
requests>=2.25.1
beautifulsoup4>=4.9.3
h5py==3.10.0
h5py==3.11.0
pulp>=2.4
pyyaml>=5.4.1
tables<=3.9.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'pytz>=2021.1',
'requests>=2.25.1',
'beautifulsoup4>=4.9.3',
'h5py==3.10.0',
'h5py==3.11.0',
'pulp>=2.4',
'pyyaml>=5.4.1',
'tables<=3.9.1',
Expand Down
8 changes: 8 additions & 0 deletions src/emhass/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def set_input_data_dict(emhass_conf: dict, costfun: str,
if get_data_from_file:
with open(emhass_conf['data_path'] / 'test_df_final.pkl', 'rb') as inp:
rh.df_final, days_list, var_list = pickle.load(inp)
retrieve_hass_conf['var_load'] = str(var_list[0])
retrieve_hass_conf['var_PV'] = str(var_list[1])
retrieve_hass_conf['var_interp'] = [retrieve_hass_conf['var_PV'], retrieve_hass_conf['var_load']]
retrieve_hass_conf['var_replace_zero'] = [retrieve_hass_conf['var_PV']]
else:
days_list = utils.get_days_list(retrieve_hass_conf["days_to_retrieve"])
var_list = [retrieve_hass_conf["var_load"], retrieve_hass_conf["var_PV"]]
Expand Down Expand Up @@ -132,6 +136,10 @@ def set_input_data_dict(emhass_conf: dict, costfun: str,
if get_data_from_file:
with open(emhass_conf['data_path'] / 'test_df_final.pkl', 'rb') as inp:
rh.df_final, days_list, var_list = pickle.load(inp)
retrieve_hass_conf['var_load'] = str(var_list[0])
retrieve_hass_conf['var_PV'] = str(var_list[1])
retrieve_hass_conf['var_interp'] = [retrieve_hass_conf['var_PV'], retrieve_hass_conf['var_load']]
retrieve_hass_conf['var_replace_zero'] = [retrieve_hass_conf['var_PV']]
else:
days_list = utils.get_days_list(1)
var_list = [retrieve_hass_conf["var_load"], retrieve_hass_conf["var_PV"]]
Expand Down
7 changes: 6 additions & 1 deletion src/emhass/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,12 @@ def get_load_forecast(self, days_min_load_forecast: Optional[int] = 3, method: O
if self.get_data_from_file:
filename_path = self.emhass_conf['data_path'] / 'test_df_final.pkl'
with open(filename_path, 'rb') as inp:
rh.df_final, days_list, _ = pickle.load(inp)
rh.df_final, days_list, var_list = pickle.load(inp)
self.var_load = var_list[0]
self.retrieve_hass_conf['var_load'] = self.var_load
var_interp = [var_list[0]]
self.var_list = [var_list[0]]
self.var_load_new = self.var_load+'_positive'
else:
days_list = get_days_list(days_min_load_forecast)
if not rh.get_data(days_list, var_list):
Expand Down
2 changes: 2 additions & 0 deletions src/emhass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def treat_runtimeparams(
]
if "weight_battery_charge" in runtimeparams.keys():
optim_conf["weight_battery_charge"] = runtimeparams["weight_battery_charge"]
if 'freq' in runtimeparams.keys():
retrieve_hass_conf['freq'] = pd.to_timedelta(runtimeparams['freq'], "minutes")
# Treat plant configuration parameters passed at runtime
if "SOCtarget" in runtimeparams.keys():
plant_conf["SOCtarget"] = runtimeparams["SOCtarget"]
Expand Down
10 changes: 7 additions & 3 deletions tests/test_command_line_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ def get_test_params():
'lat': 45.83,
'lon': 6.86,
'alt': 8000.0
}
})
}})
#Force config params for testing
params["retrieve_hass_conf"]['var_PV'] = 'sensor.power_photovoltaics'
params["retrieve_hass_conf"]['var_load'] = 'sensor.power_load_no_var_loads'
params["retrieve_hass_conf"]['var_replace_zero'] = ['sensor.power_photovoltaics']
params["retrieve_hass_conf"]['var_interp'] = ['sensor.power_photovoltaics','sensor.power_load_no_var_loads']
return params

def setUp(self):
Expand Down Expand Up @@ -419,7 +423,7 @@ def test_main_wrong_action(self):
self.assertEqual(opt_res, None)

@patch('sys.argv', ['main', '--action', 'perfect-optim', '--config', str(emhass_conf['config_path']),
'--debug', 'True'])
'--debug', 'True', '--params', json.dumps(get_test_params())])
def test_main_perfect_forecast_optim(self):
opt_res = main()
self.assertIsInstance(opt_res, pd.DataFrame)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def setUp(self):
if self.get_data_from_file:
with open(emhass_conf['data_path'] / 'test_df_final.pkl', 'rb') as inp:
self.rh.df_final, self.days_list, self.var_list = pickle.load(inp)
self.retrieve_hass_conf['var_load'] = str(self.var_list[0])
self.retrieve_hass_conf['var_PV'] = str(self.var_list[1])
self.retrieve_hass_conf['var_interp'] = [retrieve_hass_conf['var_PV'], retrieve_hass_conf['var_load']]
self.retrieve_hass_conf['var_replace_zero'] = [retrieve_hass_conf['var_PV']]
else:
self.days_list = utils.get_days_list(self.retrieve_hass_conf['days_to_retrieve'])
self.var_list = [self.retrieve_hass_conf['var_load'], self.retrieve_hass_conf['var_PV']]
Expand All @@ -74,7 +78,7 @@ def setUp(self):
self.P_load_forecast = self.fcst.get_load_forecast(method=optim_conf['load_forecast_method'])
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.opt = Optimization(self.retrieve_hass_conf, self.optim_conf, self.plant_conf,
self.fcst.var_load_cost, self.fcst.var_prod_price,
'profit', emhass_conf, logger)
self.input_data_dict = {
Expand Down Expand Up @@ -209,6 +213,10 @@ def test_get_forecasts_with_lists(self):
if self.get_data_from_file:
with open((emhass_conf['data_path'] / 'test_df_final.pkl'), 'rb') as inp:
rh.df_final, days_list, var_list = pickle.load(inp)
retrieve_hass_conf['var_load'] = str(self.var_list[0])
retrieve_hass_conf['var_PV'] = str(self.var_list[1])
retrieve_hass_conf['var_interp'] = [retrieve_hass_conf['var_PV'], retrieve_hass_conf['var_load']]
retrieve_hass_conf['var_replace_zero'] = [retrieve_hass_conf['var_PV']]
else:
days_list = utils.get_days_list(retrieve_hass_conf['days_to_retrieve'])
var_list = [retrieve_hass_conf['var_load'], retrieve_hass_conf['var_PV']]
Expand Down Expand Up @@ -342,6 +350,10 @@ def test_get_forecasts_with_lists_special_case(self):
if self.get_data_from_file:
with open(emhass_conf['data_path'] / 'test_df_final.pkl', 'rb') as inp:
rh.df_final, days_list, var_list = pickle.load(inp)
retrieve_hass_conf['var_load'] = str(self.var_list[0])
retrieve_hass_conf['var_PV'] = str(self.var_list[1])
retrieve_hass_conf['var_interp'] = [retrieve_hass_conf['var_PV'], retrieve_hass_conf['var_load']]
retrieve_hass_conf['var_replace_zero'] = [retrieve_hass_conf['var_PV']]
else:
days_list = utils.get_days_list(retrieve_hass_conf['days_to_retrieve'])
var_list = [retrieve_hass_conf['var_load'], retrieve_hass_conf['var_PV']]
Expand Down
4 changes: 4 additions & 0 deletions tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def setUp(self):
if get_data_from_file:
with open(emhass_conf['data_path'] / 'test_df_final.pkl', 'rb') as inp:
self.rh.df_final, self.days_list, self.var_list = pickle.load(inp)
self.retrieve_hass_conf['var_load'] = str(self.var_list[0])
self.retrieve_hass_conf['var_PV'] = str(self.var_list[1])
self.retrieve_hass_conf['var_interp'] = [retrieve_hass_conf['var_PV'], retrieve_hass_conf['var_load']]
self.retrieve_hass_conf['var_replace_zero'] = [retrieve_hass_conf['var_PV']]
else:
self.days_list = get_days_list(self.retrieve_hass_conf['days_to_retrieve'])
self.var_list = [self.retrieve_hass_conf['var_load'], self.retrieve_hass_conf['var_PV']]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_retrieve_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def setUp(self):
save_data_to_file = False
params = None
retrieve_hass_conf, _, _ = get_yaml_parse(emhass_conf, use_secrets=False)

#Force config params for testing
retrieve_hass_conf['var_PV'] = 'sensor.power_photovoltaics'
retrieve_hass_conf['var_load'] = 'sensor.power_load_no_var_loads'
retrieve_hass_conf['var_replace_zero'] = ['sensor.power_photovoltaics']
retrieve_hass_conf['var_interp'] = ['sensor.power_photovoltaics','sensor.power_load_no_var_loads']

self.retrieve_hass_conf = retrieve_hass_conf
self.rh = RetrieveHass(self.retrieve_hass_conf['hass_url'], self.retrieve_hass_conf['long_lived_token'],
self.retrieve_hass_conf['freq'], self.retrieve_hass_conf['time_zone'],
Expand Down

0 comments on commit be90211

Please sign in to comment.