Skip to content

Commit

Permalink
Changed binding_constraints in the binding_constraint_services from p…
Browse files Browse the repository at this point in the history
…roperty to attribute and removed unused binding_constraint attribute from `Study` as mentioned in discussion in PR #5
  • Loading branch information
Sigurd-Borge committed Sep 27, 2024
1 parent a5ad4a3 commit c52a322
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/antares/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def __init__(
self._settings = settings or StudySettings()
self._areas: Dict[str, Area] = dict()
self._links: Dict[str, Link] = dict()
self._binding_constraints: Dict[str, BindingConstraint] = dict()
for argument in kwargs:
if argument == "ini_files":
self._ini_files: dict[str, IniFile] = kwargs[argument] or dict()
Expand Down
8 changes: 2 additions & 6 deletions src/antares/service/api_services/binding_constraint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, config: APIconf, study_id: str) -> None:
self.study_id = study_id
self._wrapper = RequestWrapper(self.api_config.set_up_api_conf())
self._base_url = f"{self.api_config.get_host()}/api/v1"
self._binding_constraints: dict[str, BindingConstraint] = {}
self.binding_constraints = {}

def create_binding_constraint(
self,
Expand Down Expand Up @@ -105,14 +105,10 @@ def create_binding_constraint(
raise BindingConstraintCreationError(name, e.message) from e

constraint = BindingConstraint(name, self, bc_properties, bc_terms)
self._binding_constraints[constraint.id] = constraint
self.binding_constraints[constraint.id] = constraint

return constraint

@property
def binding_constraints(self) -> dict[str, BindingConstraint]:
return self._binding_constraints

def delete_binding_constraint_term(self, constraint_id: str, term_id: str) -> None:
url = f"{self._base_url}/studies/{self.study_id}/bindingconstraints/{constraint_id}/term/{term_id}"
try:
Expand Down
7 changes: 2 additions & 5 deletions src/antares/service/base_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def get_thermal_matrix(self, thermal_cluster: ThermalCluster, ts_name: ThermalCl


class BaseBindingConstraintService(ABC):
binding_constraints: dict[str, BindingConstraint]

@abstractmethod
def create_binding_constraint(
self,
Expand Down Expand Up @@ -391,11 +393,6 @@ def add_constraint_terms(self, constraint: BindingConstraint, terms: List[Constr
"""
pass

@property
@abstractmethod
def binding_constraints(self) -> dict[str, BindingConstraint]:
pass

@abstractmethod
def delete_binding_constraint_term(self, constraint_id: str, term_id: str) -> None:
"""
Expand Down
10 changes: 3 additions & 7 deletions src/antares/service/local_services/binding_constraint_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __init__(self, config: LocalConfiguration, study_name: str, **kwargs: Any) -
super().__init__(**kwargs)
self.config = config
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, TimeSeries] = {}
self.binding_constraints = {}

def create_binding_constraint(
self,
Expand All @@ -56,7 +56,7 @@ def create_binding_constraint(
constraint.properties = constraint.local_properties.yield_binding_constraint_properties()

# Add binding constraints
self._binding_constraints[constraint.id] = constraint
self.binding_constraints[constraint.id] = constraint
self._write_binding_constraint_ini()

# Add constraint time series
Expand Down Expand Up @@ -103,15 +103,11 @@ def _check_if_empty_ts(time_step: BindingConstraintFrequency, time_series: Optio
def _write_binding_constraint_ini(self) -> None:
binding_constraints_ini_content = {
idx: idx_constraint.local_properties.list_ini_fields
for idx, idx_constraint in enumerate(self._binding_constraints.values())
for idx, idx_constraint in enumerate(self.binding_constraints.values())
}
self.ini_file.ini_dict = binding_constraints_ini_content
self.ini_file.write_ini_file()

@property
def binding_constraints(self) -> dict[str, BindingConstraint]:
return self._binding_constraints

@property
def time_series(self) -> dict[str, TimeSeries]:
return self._time_series
Expand Down

0 comments on commit c52a322

Please sign in to comment.