Skip to content

Commit

Permalink
Merge pull request #1997 from AntaresSimulatorTeam/bugfix/v8.7-bindin…
Browse files Browse the repository at this point in the history
…g-constraints-fix

fix(ui-api-bc): v8.7 binding constraints fix
  • Loading branch information
hdinia authored Apr 4, 2024
2 parents 86c8b31 + bc04f27 commit 9633b03
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def constraint_model_adapter(constraint: Mapping[str, Any], version: int) -> Con
"terms": constraint.get("terms", []),
}

# TODO: Implement a model for version-specific fields. Output filters are sent regardless of the version.
if version >= 840:
constraint_output["filter_year_by_year"] = constraint.get("filter_year_by_year") or constraint.get(
"filter-year-by-year", ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class BindingConstraintProperties(BaseModel, extra=Extra.forbid, allow_populatio
enabled: bool = True
time_step: BindingConstraintFrequency = BindingConstraintFrequency.HOURLY
operator: BindingConstraintOperator = BindingConstraintOperator.EQUAL
comments: t.Optional[str] = None
filter_year_by_year: t.Optional[str] = None
filter_synthesis: t.Optional[str] = None
comments: t.Optional[str] = ""
filter_year_by_year: t.Optional[str] = ""
filter_synthesis: t.Optional[str] = ""


class BindingConstraintProperties870(BindingConstraintProperties):
group: t.Optional[str] = None
group: t.Optional[str] = ""


class BindingConstraintMatrices(BaseModel, extra=Extra.forbid, allow_population_by_field_name=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm
"name": "BD 2",
"id": "bd 2",
"enabled": False,
"comments": "",
"area1.cluster": 50.0,
"operator": "both",
"type": "daily",
Expand Down Expand Up @@ -127,6 +128,7 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm
"id": "bd 1",
"enabled": False,
"area1%area2": "800.0%30",
"comments": "",
"operator": "both",
"type": "weekly",
}
Expand All @@ -151,6 +153,7 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm
"id": "bd 2",
"enabled": False,
"area1.cluster": 50.0,
"comments": "",
"operator": "both",
"type": "daily",
}
Expand Down Expand Up @@ -338,7 +341,7 @@ def test_revert(command_context: CommandContext):
operator=BindingConstraintOperator.EQUAL,
coeffs={"a": [0.3]},
values=hourly_matrix_id,
comments=None,
comments="",
command_context=command_context,
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ interface Props {
reloadConstraintsList: VoidFunction;
}

const defaultValues = {
name: "",
group: "default",
enabled: true,
timeStep: TimeStep.HOURLY,
operator: BindingConstraintOperator.LESS,
comments: "",
};

// TODO rename AddConstraintDialog
function AddDialog({
open,
Expand All @@ -50,6 +41,16 @@ function AddDialog({
const { enqueueSnackbar } = useSnackbar();
const dispatch = useAppDispatch();
const [t] = useTranslation();
const studyVersion = Number(study.version);

const defaultValues = {
name: "",
group: studyVersion >= 870 ? "default" : "",
enabled: true,
timeStep: TimeStep.HOURLY,
operator: BindingConstraintOperator.LESS,
comments: "",
};

const operatorOptions = useMemo(
() =>
Expand Down Expand Up @@ -142,10 +143,13 @@ function AddDialog({
control={control}
rules={{
validate: (v) =>
validateString(v, { existingValues: existingConstraints }),
validateString(v, {
existingValues: existingConstraints,
specialChars: "@&_-()",
}),
}}
/>
{Number(study.version) >= 870 && (
{studyVersion >= 870 && (
<StringFE
name="group"
label={t("global.group")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ function BindingConstraints() {
);

useEffect(() => {
if (constraints.data && !currentConstraintId) {
const firstConstraintId = constraints.data[0].id;
dispatch(setCurrentBindingConst(firstConstraintId));
const { data } = constraints;

if (!data || data.length === 0 || currentConstraintId) {
return;
}

const firstConstraintId = data[0].id;
dispatch(setCurrentBindingConst(firstConstraintId));
}, [constraints, currentConstraintId, dispatch]);

////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 9633b03

Please sign in to comment.