From b63d99fb9ab9d2ad960b2672f11656da224fbb5c Mon Sep 17 00:00:00 2001 From: Sigurd Borge Date: Thu, 26 Sep 2024 10:05:11 +0200 Subject: [PATCH] Refactored binding constraint time series to use the correct object type --- .../binding_constraint_local.py | 45 +++++++++++-------- .../services/local_services/test_study.py | 10 ++--- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/antares/service/local_services/binding_constraint_local.py b/src/antares/service/local_services/binding_constraint_local.py index cf5fcc96..0b30bfb9 100644 --- a/src/antares/service/local_services/binding_constraint_local.py +++ b/src/antares/service/local_services/binding_constraint_local.py @@ -24,7 +24,7 @@ ) from antares.service.base_services import BaseBindingConstraintService from antares.tools.ini_tool import IniFile, IniFileTypes -from antares.tools.time_series_tool import TimeSeriesFile, TimeSeriesFileType +from antares.tools.time_series_tool import TimeSeriesFile, TimeSeriesFileType, TimeSeries class BindingConstraintLocalService(BaseBindingConstraintService): @@ -34,7 +34,7 @@ def __init__(self, config: LocalConfiguration, study_name: str, **kwargs: Any) - self.study_name = study_name self._binding_constraints: dict[str, BindingConstraint] = {} self.ini_file = IniFile(self.config.study_path, IniFileTypes.BINDING_CONSTRAINTS_INI) - self._time_series: dict[str, TimeSeriesFile] = {} + self._time_series: dict[str, TimeSeries] = {} def create_binding_constraint( self, @@ -62,28 +62,37 @@ def create_binding_constraint( constraint.properties.operator in (BindingConstraintOperator.LESS, BindingConstraintOperator.BOTH) and less_term_matrix is not None ): - self._time_series[f"{name}_lt"] = TimeSeriesFile( - TimeSeriesFileType.BINDING_CONSTRAINT_LESS, - self.config.study_path, - constraint_id=constraint.id.lower(), - time_series=less_term_matrix, + self._time_series[f"{name}_lt"] = TimeSeries( + less_term_matrix, + TimeSeriesFile( + TimeSeriesFileType.BINDING_CONSTRAINT_LESS, + self.config.study_path, + constraint_id=constraint.id.lower(), + time_series=less_term_matrix, + ), ) if constraint.properties.operator == BindingConstraintOperator.EQUAL and equal_term_matrix is not None: - self._time_series[f"{name}_eq"] = TimeSeriesFile( - TimeSeriesFileType.BINDING_CONSTRAINT_EQUAL, - self.config.study_path, - constraint_id=constraint.id.lower(), - time_series=equal_term_matrix, + self._time_series[f"{name}_eq"] = TimeSeries( + equal_term_matrix, + TimeSeriesFile( + TimeSeriesFileType.BINDING_CONSTRAINT_EQUAL, + self.config.study_path, + constraint_id=constraint.id.lower(), + time_series=equal_term_matrix, + ), ) if ( constraint.properties.operator in (BindingConstraintOperator.GREATER, BindingConstraintOperator.BOTH) and greater_term_matrix is not None ): - self._time_series[f"{name}_gt"] = TimeSeriesFile( - TimeSeriesFileType.BINDING_CONSTRAINT_GREATER, - self.config.study_path, - constraint_id=constraint.id.lower(), - time_series=greater_term_matrix, + self._time_series[f"{name}_gt"] = TimeSeries( + greater_term_matrix, + TimeSeriesFile( + TimeSeriesFileType.BINDING_CONSTRAINT_GREATER, + self.config.study_path, + constraint_id=constraint.id.lower(), + time_series=greater_term_matrix, + ), ) return constraint @@ -101,7 +110,7 @@ def binding_constraints(self) -> dict[str, BindingConstraint]: return self._binding_constraints @property - def time_series(self) -> dict[str, TimeSeriesFile]: + def time_series(self) -> dict[str, TimeSeries]: return self._time_series def add_constraint_terms(self, constraint: BindingConstraint, terms: list[ConstraintTerm]) -> list[ConstraintTerm]: diff --git a/tests/antares/services/local_services/test_study.py b/tests/antares/services/local_services/test_study.py index acaa2efc..872e48df 100644 --- a/tests/antares/services/local_services/test_study.py +++ b/tests/antares/services/local_services/test_study.py @@ -1288,16 +1288,16 @@ def test_binding_constraint_with_timeseries_stores_ts_file(self, local_study_wit # Then assert local_study_with_hydro._binding_constraints_service.time_series[ f"{constraints['lesser'].id.lower()}_lt" - ].file_path.is_file() + ].local_file.file_path.is_file() assert local_study_with_hydro._binding_constraints_service.time_series[ f"{constraints['equal'].id.lower()}_eq" - ].file_path.is_file() + ].local_file.file_path.is_file() assert local_study_with_hydro._binding_constraints_service.time_series[ f"{constraints['greater'].id.lower()}_gt" - ].file_path.is_file() + ].local_file.file_path.is_file() assert local_study_with_hydro._binding_constraints_service.time_series[ f"{constraints['both'].id.lower()}_lt" - ].file_path.is_file() + ].local_file.file_path.is_file() assert local_study_with_hydro._binding_constraints_service.time_series[ f"{constraints['both'].id.lower()}_gt" - ].file_path.is_file() + ].local_file.file_path.is_file()