PR review

This commit is contained in:
Dominique Lasserre 2025-01-19 14:54:15 +01:00
parent 437d38f508
commit e0b1ece524
6 changed files with 14 additions and 10 deletions

View File

@ -199,7 +199,7 @@ def generate_config_table_md(
table += ":::\n\n" # Add an empty line after the table
ins = create_model_from_examples(config)
if ins is not None:
if ins:
# Transform to JSON (and manually to dict) to use custom serializers and then merge with parent keys
ins_json = ins.model_dump_json(include_computed_fields=False)
ins_dict = json.loads(ins_json)

View File

@ -341,10 +341,13 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
self._setup()
def _create_initial_config_file(self) -> None:
if self.config_file_path is not None and not self.config_file_path.exists():
if self.config_file_path and not self.config_file_path.exists():
self.config_file_path.parent.mkdir(parents=True, exist_ok=True)
with open(self.config_file_path, "w") as f:
f.write(self.model_dump_json(indent=4))
try:
with open(self.config_file_path, "w") as f:
f.write(self.model_dump_json(indent=4))
except Exception as e:
logger.error(f"Could not write configuration file '{self.config_file_path}': {e}")
def _update_data_folder_path(self) -> None:
"""Updates path to the data directory."""

View File

@ -275,6 +275,7 @@ class optimization_problem(ConfigMixin, DevicesMixin, EnergyManagementSystemMixi
# EV charge hours as a NumPy array of ints (if optimize_ev is True)
eautocharge_hours_index = (
# append ev charging states to individual
np.array(
individual[self.config.prediction.hours : self.config.prediction.hours * 2],
dtype=int,

View File

@ -63,12 +63,12 @@ class ElecPriceImport(ElecPriceProvider, PredictionImportProvider):
return "ElecPriceImport"
def _update_data(self, force_update: Optional[bool] = False) -> None:
if self.config.elecprice.provider_settings.import_file_path is not None:
if self.config.elecprice.provider_settings.import_file_path:
self.import_from_file(
self.config.elecprice.provider_settings.import_file_path,
key_prefix="elecprice",
)
if self.config.elecprice.provider_settings.import_json is not None:
if self.config.elecprice.provider_settings.import_json:
self.import_from_json(
self.config.elecprice.provider_settings.import_json, key_prefix="elecprice"
)

View File

@ -62,7 +62,7 @@ class LoadImport(LoadProvider, PredictionImportProvider):
return "LoadImport"
def _update_data(self, force_update: Optional[bool] = False) -> None:
if self.config.load.provider_settings.import_file_path is not None:
if self.config.load.provider_settings.import_file_path:
self.import_from_file(self.config.provider_settings.import_file_path, key_prefix="load")
if self.config.load.provider_settings.import_json is not None:
if self.config.load.provider_settings.import_json:
self.import_from_json(self.config.load.provider_settings.import_json, key_prefix="load")

View File

@ -63,11 +63,11 @@ class WeatherImport(WeatherProvider, PredictionImportProvider):
return "WeatherImport"
def _update_data(self, force_update: Optional[bool] = False) -> None:
if self.config.weather.provider_settings.import_file_path is not None:
if self.config.weather.provider_settings.import_file_path:
self.import_from_file(
self.config.weather.provider_settings.import_file_path, key_prefix="weather"
)
if self.config.weather.provider_settings.import_json is not None:
if self.config.weather.provider_settings.import_json:
self.import_from_json(
self.config.weather.provider_settings.import_json, key_prefix="weather"
)