-
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.
refactor(bc): create user class (#84)
- Loading branch information
1 parent
3864f14
commit 4ae8e2a
Showing
14 changed files
with
421 additions
and
267 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
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.base_model 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, | ||
) |
Oops, something went wrong.