Skip to content

Commit

Permalink
feat(api): remove filters
Browse files Browse the repository at this point in the history
  • Loading branch information
salemsd committed Jan 8, 2025
1 parent 0a7bd7c commit f0e6a67
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 65 deletions.
7 changes: 0 additions & 7 deletions src/antares/craft/model/binding_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 2 additions & 33 deletions src/antares/craft/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from antares.craft.model.binding_constraint import (
BindingConstraint,
BindingConstraintProperties,
BindingConstraintReadingFilters,
ConstraintMatrixName,
ConstraintTerm,
)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/antares/craft/service/base_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from antares.craft.model.binding_constraint import (
BindingConstraint,
BindingConstraintProperties,
BindingConstraintReadingFilters,
ConstraintMatrixName,
ConstraintTerm,
)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
BindingConstraintFrequency,
BindingConstraintOperator,
BindingConstraintProperties,
BindingConstraintReadingFilters,
ConstraintMatrixName,
ConstraintTerm,
DefaultBindingConstraintProperties,
Expand Down Expand Up @@ -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
16 changes: 1 addition & 15 deletions tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

0 comments on commit f0e6a67

Please sign in to comment.