Skip to content

Commit

Permalink
fix(bc): remove_bc command now works for v8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jan 4, 2024
1 parent acb808a commit 6bb66ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from antarest.study.storage.variantstudy.model.command.create_binding_constraint import (
BindingConstraintMatrices,
BindingConstraintProperties,
BindingConstraintProperties870,
CreateBindingConstraint,
)
from antarest.study.storage.variantstudy.model.command.update_binding_constraint import UpdateBindingConstraint
Expand Down Expand Up @@ -61,13 +61,13 @@ class UpdateBindingConstProps(BaseModel):

class BindingConstraintWithName(
BindingConstraintMatrices,
BindingConstraintProperties,
BindingConstraintProperties870,
):
name: str
coeffs: Dict[str, List[float]]


class BindingConstraintConfig(BindingConstraintProperties):
class BindingConstraintConfig(BindingConstraintProperties870):
id: str
name: str
constraints: Optional[List[ConstraintTermDTO]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"AbstractBindingConstraintCommand",
"CreateBindingConstraint",
"check_matrix_values",
"BindingConstraintProperties",
"BindingConstraintProperties870",
"BindingConstraintMatrices",
)

Expand Down Expand Up @@ -79,9 +79,12 @@ class BindingConstraintProperties(BaseModel, extra=Extra.forbid):
comments: Optional[str] = None


class BindingConstraintProperties870(BindingConstraintProperties):
group: str = "default"


class BindingConstraintMatrices(BaseModel, extra=Extra.forbid):
values: Optional[Union[MatrixType, str]] = Field(None, description="2nd member matrix for studies before v8.7")
# todo: verify the names with Alexander
less_term_matrix: Optional[Union[MatrixType, str]] = Field(None, description="less term matrix for v8.7+ studies")
greater_term_matrix: Optional[Union[MatrixType, str]] = Field(
None, description="greater term matrix for v8.7+ studies"
Expand All @@ -103,7 +106,7 @@ def __init__(self, **data: Any) -> None:


class AbstractBindingConstraintCommand(
BindingConstraintProperties, BindingConstraintMatrices, ICommand, metaclass=ABCMeta
BindingConstraintProperties870, BindingConstraintMatrices, ICommand, metaclass=ABCMeta
):
"""
Abstract class for binding constraint commands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def _apply(self, study_data: FileStudy) -> CommandOutput:
new_binding_constraints,
["input", "bindingconstraints", "bindingconstraints"],
)
study_data.tree.delete(["input", "bindingconstraints", self.id])
if study_data.config.version < 870:
study_data.tree.delete(["input", "bindingconstraints", self.id])
else:
for term in ["lt", "gt", "eq"]:
study_data.tree.delete(["input", "bindingconstraints", f"{self.id}_{term}"])
output, _ = self._apply_config(study_data.config)
return output

Expand Down

0 comments on commit 6bb66ed

Please sign in to comment.