-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5d6a44
commit 45d00e9
Showing
7 changed files
with
135 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/antares/craft/service/api_services/models/binding_constraint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# | ||
# See AUTHORS.txt | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# | ||
# This file is part of the Antares project. | ||
|
||
from dataclasses import asdict | ||
from typing import Union | ||
|
||
from antares.craft.model.binding_constraint import ( | ||
BindingConstraintFrequency, | ||
BindingConstraintOperator, | ||
BindingConstraintProperties, | ||
BindingConstraintPropertiesUpdate, | ||
) | ||
from antares.craft.service.api_services.models import APIBaseModel | ||
from antares.craft.tools.all_optional_meta import all_optional_model | ||
|
||
BindingConstraintPropertiesType = Union[BindingConstraintProperties, BindingConstraintPropertiesUpdate] | ||
|
||
|
||
@all_optional_model | ||
class BindingConstraintPropertiesAPI(APIBaseModel): | ||
enabled: bool | ||
time_step: BindingConstraintFrequency | ||
operator: BindingConstraintOperator | ||
comments: str | ||
filter_year_by_year: str | ||
filter_synthesis: str | ||
group: str | ||
|
||
@staticmethod | ||
def from_user_model(user_class: BindingConstraintPropertiesType) -> "BindingConstraintPropertiesAPI": | ||
user_dict = asdict(user_class) | ||
return BindingConstraintPropertiesAPI.model_validate(user_dict) | ||
|
||
def to_user_model(self) -> BindingConstraintProperties: | ||
return BindingConstraintProperties( | ||
enabled=self.enabled, | ||
time_step=self.time_step, | ||
operator=self.operator, | ||
comments=self.comments, | ||
filter_year_by_year=self.filter_year_by_year, | ||
filter_synthesis=self.filter_synthesis, | ||
group=self.group, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/antares/craft/service/local_services/models/binding_constraint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# | ||
# See AUTHORS.txt | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# | ||
# This file is part of the Antares project. | ||
|
||
from dataclasses import asdict | ||
from typing import Union | ||
|
||
from antares.craft.model.binding_constraint import ( | ||
BindingConstraintFrequency, | ||
BindingConstraintOperator, | ||
BindingConstraintProperties, | ||
BindingConstraintPropertiesUpdate, | ||
) | ||
from antares.craft.service.local_services.models import LocalBaseModel | ||
from antares.craft.tools.all_optional_meta import all_optional_model | ||
|
||
BindingConstraintPropertiesType = Union[BindingConstraintProperties, BindingConstraintPropertiesUpdate] | ||
|
||
|
||
@all_optional_model | ||
class BindingConstraintPropertiesLocal(LocalBaseModel): | ||
enabled: bool | ||
time_step: BindingConstraintFrequency | ||
operator: BindingConstraintOperator | ||
comments: str | ||
filter_year_by_year: str | ||
filter_synthesis: str | ||
group: str | ||
|
||
@staticmethod | ||
def from_user_model(user_class: BindingConstraintPropertiesType) -> "BindingConstraintPropertiesLocal": | ||
user_dict = asdict(user_class) | ||
return BindingConstraintPropertiesLocal.model_validate(user_dict) | ||
|
||
def to_user_model(self) -> BindingConstraintProperties: | ||
return BindingConstraintProperties( | ||
enabled=self.enabled, | ||
time_step=self.time_step, | ||
operator=self.operator, | ||
comments=self.comments, | ||
filter_year_by_year=self.filter_year_by_year, | ||
filter_synthesis=self.filter_synthesis, | ||
group=self.group, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters