From f0e6a6734600218ba4f67f14cf3bf5bea79952df Mon Sep 17 00:00:00 2001 From: salemsd Date: Wed, 8 Jan 2025 11:46:57 +0100 Subject: [PATCH] feat(api): remove filters --- src/antares/craft/model/binding_constraint.py | 7 ---- src/antares/craft/model/study.py | 35 ++----------------- .../api_services/binding_constraint_api.py | 7 +--- src/antares/craft/service/base_services.py | 3 +- .../binding_constraint_local.py | 3 +- tests/integration/test_web_client.py | 16 +-------- 6 files changed, 6 insertions(+), 65 deletions(-) diff --git a/src/antares/craft/model/binding_constraint.py b/src/antares/craft/model/binding_constraint.py index cc348257..667415f0 100644 --- a/src/antares/craft/model/binding_constraint.py +++ b/src/antares/craft/model/binding_constraint.py @@ -119,13 +119,6 @@ class BindingConstraintProperties(DefaultBindingConstraintProperties): pass -class BindingConstraintReadingFilters(BindingConstraintProperties): - area_name: Optional[str] = None - cluster_name: Optional[str] = None - link_id: Optional[str] = None - cluster_id: Optional[str] = None - - class BindingConstraint: def __init__( # type: ignore # TODO: Find a way to avoid circular imports self, diff --git a/src/antares/craft/model/study.py b/src/antares/craft/model/study.py index 4bc21c54..7913cbbb 100644 --- a/src/antares/craft/model/study.py +++ b/src/antares/craft/model/study.py @@ -27,10 +27,7 @@ from antares.craft.model.area import Area, AreaProperties, AreaUi from antares.craft.model.binding_constraint import ( BindingConstraint, - BindingConstraintFrequency, - BindingConstraintOperator, BindingConstraintProperties, - BindingConstraintReadingFilters, ConstraintTerm, ) from antares.craft.model.link import Link, LinkProperties, LinkUi @@ -334,36 +331,8 @@ def create_binding_constraint( self._binding_constraints[binding_constraint.id] = binding_constraint return binding_constraint - def read_binding_constraints( - self, - enabled: Optional[bool] = None, - time_step: Optional[BindingConstraintFrequency] = None, - operator: Optional[BindingConstraintOperator] = None, - comments: Optional[str] = None, - filter_year_by_year: Optional[str] = None, - filter_synthesis: Optional[str] = None, - group: Optional[str] = None, - area_name: Optional[str] = None, - cluster_name: Optional[str] = None, - link_id: Optional[str] = None, - cluster_id: Optional[str] = None, - ) -> list[BindingConstraint]: - filters = BindingConstraintReadingFilters.model_validate( - { - "enabled": enabled, - "time_step": time_step, - "operator": operator, - "comments": comments, - "filter_year_by_year": filter_year_by_year, - "filter_synthesis": filter_synthesis, - "group": group, - "area_name": area_name, - "cluster_name": cluster_name, - "link_id": link_id, - "cluster_id": cluster_id, - } - ) - constraints = self._binding_constraints_service.read_binding_constraints(filters) + def read_binding_constraints(self) -> list[BindingConstraint]: + constraints = self._binding_constraints_service.read_binding_constraints() self._binding_constraints = {constraint.id: constraint for constraint in constraints} return constraints diff --git a/src/antares/craft/service/api_services/binding_constraint_api.py b/src/antares/craft/service/api_services/binding_constraint_api.py index 6ad12b46..3de6a839 100644 --- a/src/antares/craft/service/api_services/binding_constraint_api.py +++ b/src/antares/craft/service/api_services/binding_constraint_api.py @@ -30,7 +30,6 @@ from antares.craft.model.binding_constraint import ( BindingConstraint, BindingConstraintProperties, - BindingConstraintReadingFilters, ConstraintMatrixName, ConstraintTerm, ) @@ -173,12 +172,8 @@ def add_constraint_terms(self, constraint: BindingConstraint, terms: List[Constr return new_terms - def read_binding_constraints(self, filters: BindingConstraintReadingFilters) -> list[BindingConstraint]: - params = filters.model_dump(exclude_none=True) - query_string = "&".join(f"{k}={v}" for k, v in params.items()) + def read_binding_constraints(self) -> list[BindingConstraint]: url = f"{self._base_url}/studies/{self.study_id}/bindingconstraints" - if query_string: - url += f"?{query_string}" try: response = self._wrapper.get(url) constraints_json = response.json() diff --git a/src/antares/craft/service/base_services.py b/src/antares/craft/service/base_services.py index 6820bc7e..187d1803 100644 --- a/src/antares/craft/service/base_services.py +++ b/src/antares/craft/service/base_services.py @@ -20,7 +20,6 @@ from antares.craft.model.binding_constraint import ( BindingConstraint, BindingConstraintProperties, - BindingConstraintReadingFilters, ConstraintMatrixName, ConstraintTerm, ) @@ -511,7 +510,7 @@ def update_constraint_matrix( pass @abstractmethod - def read_binding_constraints(self, filters: BindingConstraintReadingFilters) -> list[BindingConstraint]: + def read_binding_constraints(self) -> list[BindingConstraint]: """ Loads binding constraints into study diff --git a/src/antares/craft/service/local_services/binding_constraint_local.py b/src/antares/craft/service/local_services/binding_constraint_local.py index 1d8b6626..e1ebef5e 100644 --- a/src/antares/craft/service/local_services/binding_constraint_local.py +++ b/src/antares/craft/service/local_services/binding_constraint_local.py @@ -21,7 +21,6 @@ BindingConstraintFrequency, BindingConstraintOperator, BindingConstraintProperties, - BindingConstraintReadingFilters, ConstraintMatrixName, ConstraintTerm, DefaultBindingConstraintProperties, @@ -243,5 +242,5 @@ def update_constraint_matrix( ) -> None: raise NotImplementedError - def read_binding_constraints(self, filters: BindingConstraintReadingFilters) -> list[BindingConstraint]: + def read_binding_constraints(self) -> list[BindingConstraint]: raise NotImplementedError diff --git a/tests/integration/test_web_client.py b/tests/integration/test_web_client.py index cb5f198b..61a6b292 100644 --- a/tests/integration/test_web_client.py +++ b/tests/integration/test_web_client.py @@ -560,16 +560,7 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop): assert expected_values == matrix_values # ===== Test read binding constraints ===== - - # add a disabled constraint for filtering purposes - link_data = LinkData(area1="be", area2="fr") - study.create_binding_constraint( - name="bc_1", - terms=[ConstraintTerm(data=link_data, weight=2.0)], - properties=BindingConstraintProperties(enabled=False), - ) - - constraints = study.read_binding_constraints(cluster_name="cluster_test") + constraints = study.read_binding_constraints() assert len(constraints) > 0 constraint = constraints[0] @@ -587,8 +578,3 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop): assert cluster_term.data.cluster == "cluster_test" assert cluster_term.weight == 4.5 assert cluster_term.offset == 3 - - # ===== filter test ====== - constraints = study.read_binding_constraints(enabled=False) - assert len(constraints) == 1 - assert constraints[0].properties.enabled is False