Skip to content

Commit

Permalink
Refactored binding constraint time series to use the correct object type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigurd-Borge committed Sep 26, 2024
1 parent 1115467 commit b63d99f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
45 changes: 27 additions & 18 deletions src/antares/service/local_services/binding_constraint_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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]:
Expand Down
10 changes: 5 additions & 5 deletions tests/antares/services/local_services/test_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit b63d99f

Please sign in to comment.