From a1d8423a733997fce25e48386fa2f61bbc0136f9 Mon Sep 17 00:00:00 2001 From: john whately <18461782+GeoDerp@users.noreply.github.com> Date: Tue, 24 Dec 2024 01:16:34 +1030 Subject: [PATCH 1/3] treat_runtimeparams fix optimization_time_step timedelta --- src/emhass/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emhass/utils.py b/src/emhass/utils.py index 6a7e5013..f37dce1f 100644 --- a/src/emhass/utils.py +++ b/src/emhass/utils.py @@ -308,7 +308,7 @@ def treat_runtimeparams( runtimeparams.get("optimization_time_step", runtimeparams.get("freq")) ) params["retrieve_hass_conf"]["optimization_time_step"] = pd.to_timedelta( - optimization_time_step + optimization_time_step, "minutes" ) else: optimization_time_step = int( From 906240b100092c13d917bb171f2f377e3d854c71 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Tue, 24 Dec 2024 03:42:35 +0000 Subject: [PATCH 2/3] webserver remove logger duplicate --- src/emhass/web_server.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index e16aa0fc..03fb2f15 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -14,6 +14,7 @@ import yaml from flask import Flask, make_response, request +from flask import logging as log from jinja2 import Environment, PackageLoader from waitress import serve @@ -652,37 +653,30 @@ def action_call(action_name): raise Exception("missing: " + str(emhass_conf["data_path"])) # Define loggers - ch = logging.StreamHandler() formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) - ch.setFormatter(formatter) + log.default_handler.setFormatter(formatter) # Action file logger fileLogger = logging.FileHandler(str(emhass_conf["data_path"] / "actionLogs.txt")) formatter = logging.Formatter("%(levelname)s - %(name)s - %(message)s") fileLogger.setFormatter(formatter) # add format to Handler if logging_level == "DEBUG": app.logger.setLevel(logging.DEBUG) - ch.setLevel(logging.DEBUG) fileLogger.setLevel(logging.DEBUG) elif logging_level == "INFO": app.logger.setLevel(logging.INFO) - ch.setLevel(logging.INFO) fileLogger.setLevel(logging.INFO) elif logging_level == "WARNING": app.logger.setLevel(logging.WARNING) - ch.setLevel(logging.WARNING) fileLogger.setLevel(logging.WARNING) elif logging_level == "ERROR": app.logger.setLevel(logging.ERROR) - ch.setLevel(logging.ERROR) fileLogger.setLevel(logging.ERROR) else: app.logger.setLevel(logging.DEBUG) - ch.setLevel(logging.DEBUG) fileLogger.setLevel(logging.DEBUG) app.logger.propagate = False - app.logger.addHandler(ch) app.logger.addHandler(fileLogger) # Clear Action File logger file, ready for new instance clearFileLog() From a88f6efd8935b5c4b40b9220bf0741a38d8b0ac1 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Tue, 24 Dec 2024 05:34:02 +0000 Subject: [PATCH 3/3] treat_runtimeparams add missing passed_data, move forecast_methods --- src/emhass/utils.py | 116 +++++++++++++++++++++------------------ src/emhass/web_server.py | 1 - 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/src/emhass/utils.py b/src/emhass/utils.py index 0be795fe..45ba9a0d 100644 --- a/src/emhass/utils.py +++ b/src/emhass/utils.py @@ -338,59 +338,6 @@ def treat_runtimeparams( optimization_time_step, delta_forecast, time_zone ) - # Treat passed forecast data lists - list_forecast_key = [ - "pv_power_forecast", - "load_power_forecast", - "load_cost_forecast", - "prod_price_forecast", - "outdoor_temperature_forecast", - ] - forecast_methods = [ - "weather_forecast_method", - "load_forecast_method", - "load_cost_forecast_method", - "production_price_forecast_method", - "outdoor_temperature_forecast_method", - ] - - # Loop forecasts, check if value is a list and greater than or equal to forecast_dates - for method, forecast_key in enumerate(list_forecast_key): - if forecast_key in runtimeparams.keys(): - if isinstance(runtimeparams[forecast_key], list) and len( - runtimeparams[forecast_key] - ) >= len(forecast_dates): - params["passed_data"][forecast_key] = runtimeparams[forecast_key] - params["optim_conf"][forecast_methods[method]] = "list" - else: - logger.error( - f"ERROR: The passed data is either not a list or the length is not correct, length should be {str(len(forecast_dates))}" - ) - logger.error( - f"Passed type is {str(type(runtimeparams[forecast_key]))} and length is {str(len(runtimeparams[forecast_key]))}" - ) - # Check if string contains list, if so extract - if isinstance(runtimeparams[forecast_key], str): - if isinstance(ast.literal_eval(runtimeparams[forecast_key]), list): - runtimeparams[forecast_key] = ast.literal_eval( - runtimeparams[forecast_key] - ) - list_non_digits = [ - x - for x in runtimeparams[forecast_key] - if not (isinstance(x, int) or isinstance(x, float)) - ] - if len(list_non_digits) > 0: - logger.warning( - f"There are non numeric values on the passed data for {forecast_key}, check for missing values (nans, null, etc)" - ) - for x in list_non_digits: - logger.warning( - f"This value in {forecast_key} was detected as non digits: {str(x)}" - ) - else: - params["passed_data"][forecast_key] = None - # Add runtime exclusive (not in config) parameters to params # regressor-model-fit if set_type == "regressor-model-fit": @@ -447,6 +394,16 @@ def treat_runtimeparams( soc_final = runtimeparams["soc_final"] params["passed_data"]["soc_final"] = soc_final + params["passed_data"]["operating_hours_of_each_deferrable_load"] = params[ + "optim_conf" + ].get("operating_hours_of_each_deferrable_load", None) + params["passed_data"]["start_timesteps_of_each_deferrable_load"] = params[ + "optim_conf" + ].get("start_timesteps_of_each_deferrable_load", None) + params["passed_data"]["end_timesteps_of_each_deferrable_load"] = params[ + "optim_conf" + ].get("end_timesteps_of_each_deferrable_load", None) + forecast_dates = copy.deepcopy(forecast_dates)[0:prediction_horizon] # Load the default config @@ -480,6 +437,59 @@ def treat_runtimeparams( params["passed_data"]["soc_init"] = None params["passed_data"]["soc_final"] = None + # Treat passed forecast data lists + list_forecast_key = [ + "pv_power_forecast", + "load_power_forecast", + "load_cost_forecast", + "prod_price_forecast", + "outdoor_temperature_forecast", + ] + forecast_methods = [ + "weather_forecast_method", + "load_forecast_method", + "load_cost_forecast_method", + "production_price_forecast_method", + "outdoor_temperature_forecast_method", + ] + + # Loop forecasts, check if value is a list and greater than or equal to forecast_dates + for method, forecast_key in enumerate(list_forecast_key): + if forecast_key in runtimeparams.keys(): + if isinstance(runtimeparams[forecast_key], list) and len( + runtimeparams[forecast_key] + ) >= len(forecast_dates): + params["passed_data"][forecast_key] = runtimeparams[forecast_key] + params["optim_conf"][forecast_methods[method]] = "list" + else: + logger.error( + f"ERROR: The passed data is either not a list or the length is not correct, length should be {str(len(forecast_dates))}" + ) + logger.error( + f"Passed type is {str(type(runtimeparams[forecast_key]))} and length is {str(len(runtimeparams[forecast_key]))}" + ) + # Check if string contains list, if so extract + if isinstance(runtimeparams[forecast_key], str): + if isinstance(ast.literal_eval(runtimeparams[forecast_key]), list): + runtimeparams[forecast_key] = ast.literal_eval( + runtimeparams[forecast_key] + ) + list_non_digits = [ + x + for x in runtimeparams[forecast_key] + if not (isinstance(x, int) or isinstance(x, float)) + ] + if len(list_non_digits) > 0: + logger.warning( + f"There are non numeric values on the passed data for {forecast_key}, check for missing values (nans, null, etc)" + ) + for x in list_non_digits: + logger.warning( + f"This value in {forecast_key} was detected as non digits: {str(x)}" + ) + else: + params["passed_data"][forecast_key] = None + # Treat passed data for forecast model fit/predict/tune at runtime if ( params["passed_data"].get("historic_days_to_retrieve", None) is not None diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index 03fb2f15..dc975326 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -385,7 +385,6 @@ def action_call(action_name): ActionStr = " >> Setting input data dict" app.logger.info(ActionStr) - app.logger.warning(costfun) input_data_dict = set_input_data_dict( emhass_conf, costfun, params, runtimeparams, action_name, app.logger )