From fbe1bf9facba09000cd2adbba7a016f367560766 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Tue, 23 Apr 2024 11:40:05 +0200 Subject: [PATCH] Merge branch 'refs/heads/hotfix/v2.16.8' into dev # Conflicts: # antarest/core/exceptions.py # antarest/study/business/areas/renewable_management.py # antarest/study/business/areas/st_storage_management.py # antarest/study/business/areas/thermal_management.py # antarest/study/business/thematic_trimming_field_infos.py # antarest/study/storage/variantstudy/model/model.py # antarest/study/web/study_data_blueprint.py # tests/integration/study_data_blueprint/test_renewable.py # tests/integration/study_data_blueprint/test_st_storage.py # tests/integration/study_data_blueprint/test_thermal.py # tests/storage/repository/filesystem/config/test_config_files.py # tests/study/business/areas/test_st_storage_management.py # webapp/src/components/App/Singlestudy/explore/Configuration/General/dialogs/ThematicTrimmingDialog/utils.ts # webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/AddDialog.tsx --- antarest/study/business/area_management.py | 4 +-- .../business/areas/st_storage_management.py | 4 +-- .../business/binding_constraint_management.py | 8 +++--- antarest/study/business/link_management.py | 3 ++- .../rawstudy/model/filesystem/config/model.py | 4 +-- .../model/filesystem/config/st_storage.py | 2 +- .../business/utils_binding_constraint.py | 6 ++--- .../command/create_binding_constraint.py | 27 +++---------------- antarest/study/web/study_data_blueprint.py | 3 +-- 9 files changed, 19 insertions(+), 42 deletions(-) diff --git a/antarest/study/business/area_management.py b/antarest/study/business/area_management.py index f13dfc5e28..db04120884 100644 --- a/antarest/study/business/area_management.py +++ b/antarest/study/business/area_management.py @@ -7,14 +7,14 @@ from antarest.core.exceptions import ConfigFileNotFound, DuplicateAreaName, LayerNotAllowedToBeDeleted, LayerNotFound from antarest.core.model import JSON -from antarest.study.business.utils import AllOptionalMetaclass, camel_case_model, execute_or_add_commands +from antarest.study.business.all_optional_meta import AllOptionalMetaclass, camel_case_model +from antarest.study.business.utils import execute_or_add_commands from antarest.study.model import Patch, PatchArea, PatchCluster, RawStudy, Study from antarest.study.repository import StudyMetadataRepository from antarest.study.storage.patch_service import PatchService from antarest.study.storage.rawstudy.model.filesystem.config.area import ( AdequacyPathProperties, AreaFolder, - AreaUI, OptimizationProperties, ThermalAreasProperties, UIProperties, diff --git a/antarest/study/business/areas/st_storage_management.py b/antarest/study/business/areas/st_storage_management.py index 05ade38c1c..bb0987502c 100644 --- a/antarest/study/business/areas/st_storage_management.py +++ b/antarest/study/business/areas/st_storage_management.py @@ -236,7 +236,7 @@ def create_storage_output( cluster_id: str, config: t.Mapping[str, t.Any], ) -> "STStorageOutput": - obj = create_st_storage_config(study_version=study_version, **config, id=cluster_id) + obj = create_st_storage_config(study_version, **config, id=cluster_id) kwargs = obj.dict(by_alias=False) return STStorageOutput(**kwargs) @@ -361,7 +361,7 @@ def get_all_storages_props( storages_by_areas = collections.defaultdict(dict) for area_id, cluster_obj in storages.items(): for cluster_id, cluster in cluster_obj.items(): - storages_by_areas[area_id][cluster_id] = STStorageOutput.from_config(cluster_id, cluster) + storages_by_areas[area_id][cluster_id] = create_storage_output(int(study.version), cluster_id, cluster) return storages_by_areas diff --git a/antarest/study/business/binding_constraint_management.py b/antarest/study/business/binding_constraint_management.py index af37a9e1c5..9c29c5925d 100644 --- a/antarest/study/business/binding_constraint_management.py +++ b/antarest/study/business/binding_constraint_management.py @@ -10,11 +10,9 @@ from antarest.core.exceptions import ( BindingConstraintNotFound, - ConfigFileNotFound, ConstraintAlreadyExistError, ConstraintIdNotFoundError, DuplicateConstraintName, - IncoherenceBetweenMatricesLength, InvalidConstraintName, InvalidFieldForVersionError, MatrixWidthMismatchError, @@ -323,7 +321,7 @@ class ConstraintOutput870(ConstraintOutput830): def _get_references_by_widths( file_study: FileStudy, bcs: t.Sequence[ConstraintOutput] -) -> Mapping[int, Sequence[Tuple[str, str]]]: +) -> t.Mapping[int, t.Sequence[t.Tuple[str, str]]]: """ Iterates over each BC and its associated matrices. For each matrix, it checks its width according to the expected matrix shapes. @@ -363,7 +361,7 @@ def _get_references_by_widths( return references_by_width -def _validate_binding_constraints(file_study: FileStudy, bcs: Sequence[ConstraintOutput]) -> bool: +def _validate_binding_constraints(file_study: FileStudy, bcs: t.Sequence[ConstraintOutput]) -> bool: """ Validates the binding constraints within a group. """ @@ -371,7 +369,7 @@ def _validate_binding_constraints(file_study: FileStudy, bcs: Sequence[Constrain if len(references_by_widths) > 1: most_common = collections.Counter(references_by_widths.keys()).most_common() - invalid_constraints: Dict[str, str] = {} + invalid_constraints: t.Dict[str, str] = {} for width, _ in most_common[1:]: references = references_by_widths[width] diff --git a/antarest/study/business/link_management.py b/antarest/study/business/link_management.py index 746a998ba6..375a539fd8 100644 --- a/antarest/study/business/link_management.py +++ b/antarest/study/business/link_management.py @@ -4,7 +4,8 @@ from antarest.core.exceptions import ConfigFileNotFound from antarest.core.model import JSON -from antarest.study.business.utils import AllOptionalMetaclass, camel_case_model, execute_or_add_commands +from antarest.study.business.all_optional_meta import AllOptionalMetaclass, camel_case_model +from antarest.study.business.utils import execute_or_add_commands from antarest.study.model import RawStudy from antarest.study.storage.rawstudy.model.filesystem.config.links import LinkProperties from antarest.study.storage.storage_service import StudyStorageService diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/model.py b/antarest/study/storage/rawstudy/model/filesystem/config/model.py index 2ec15e6915..ff79c51073 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/model.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/model.py @@ -2,11 +2,11 @@ import typing as t from pathlib import Path -from pydantic import BaseModel -from pydantic import Field, root_validator +from pydantic import BaseModel, Field, root_validator from antarest.core.utils.utils import DTO from antarest.study.business.enum_ignore_case import EnumIgnoreCase + from .binding_constraint import BindingConstraintFrequency from .field_validators import extract_filtering from .renewable import RenewableConfigType diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py b/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py index 9d8dd72229..3355ba571a 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py @@ -149,7 +149,7 @@ class STStorage880Config(STStorage880Properties, LowerCaseIdentifier): STStorageConfigType = t.Union[STStorageConfig, STStorage880Config] -def get_st_storage_config_cls(study_version: t.Union[str, int]) -> t.Type[STStorageConfig]: +def get_st_storage_config_cls(study_version: t.Union[str, int]) -> t.Type[STStorageConfigType]: """ Retrieves the short-term storage configuration class based on the study version. diff --git a/antarest/study/storage/variantstudy/business/utils_binding_constraint.py b/antarest/study/storage/variantstudy/business/utils_binding_constraint.py index 552afed5e0..ebbeeec739 100644 --- a/antarest/study/storage/variantstudy/business/utils_binding_constraint.py +++ b/antarest/study/storage/variantstudy/business/utils_binding_constraint.py @@ -1,9 +1,7 @@ import typing as t -from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import ( - BindingConstraintFrequency, -) -from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig, BindingConstraintDTO +from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import BindingConstraintFrequency +from antarest.study.storage.rawstudy.model.filesystem.config.model import BindingConstraintDTO, FileStudyTreeConfig def parse_bindings_coeffs_and_save_into_config( diff --git a/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py b/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py index b5397e4513..96e9643165 100644 --- a/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py +++ b/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py @@ -91,6 +91,10 @@ class BindingConstraintProperties830(BindingConstraintPropertiesBase): filter_year_by_year: str = Field("", alias="filter-year-by-year") filter_synthesis: str = Field("", alias="filter-synthesis") + @validator("filter_synthesis", "filter_year_by_year", pre=True) + def _validate_filtering(cls, v: t.Any) -> str: + return validate_filtering(v) + class BindingConstraintProperties870(BindingConstraintProperties830): group: str = DEFAULT_GROUP @@ -130,10 +134,6 @@ def create_binding_constraint_config(study_version: t.Union[str, int], **kwargs: cls = get_binding_constraint_config_cls(study_version) return cls.from_dict(**kwargs) - @validator("filter_synthesis", "filter_year_by_year", pre=True) - def _validate_filtering(cls, v: t.Any) -> str: - return validate_filtering(v) - class OptionalProperties(BindingConstraintProperties870, metaclass=AllOptionalMetaclass, use_none=True): pass @@ -144,25 +144,6 @@ class OptionalProperties(BindingConstraintProperties870, metaclass=AllOptionalMe # ================================================================================= -BindingConstraintPropertiesType = t.Union[BindingConstraintProperties870, BindingConstraintProperties] - - -def get_binding_constraint_config_cls(study_version: t.Union[str, int]) -> t.Type[BindingConstraintPropertiesType]: - """ - Retrieves the short-term storage configuration class based on the study version. - - Args: - study_version: The version of the study. - - Returns: - The short-term storage configuration class. - """ - version = int(study_version) - if version >= 870: - return BindingConstraintProperties870 - return BindingConstraintProperties - - class BindingConstraintMatrices(BaseModel, extra=Extra.forbid, allow_population_by_field_name=True): """ Class used to store the matrices of a binding constraint. diff --git a/antarest/study/web/study_data_blueprint.py b/antarest/study/web/study_data_blueprint.py index 11d5945bd2..ecdd5ff191 100644 --- a/antarest/study/web/study_data_blueprint.py +++ b/antarest/study/web/study_data_blueprint.py @@ -18,8 +18,7 @@ from antarest.study.business.adequacy_patch_management import AdequacyPatchFormFields from antarest.study.business.advanced_parameters_management import AdvancedParamsFormFields from antarest.study.business.allocation_management import AllocationFormFields, AllocationMatrix -from antarest.study.business.area_management import AreaCreationDTO, AreaInfoDTO, AreaType, LayerInfoDTO, \ - UpdateAreaUi +from antarest.study.business.area_management import AreaCreationDTO, AreaInfoDTO, AreaType, LayerInfoDTO, UpdateAreaUi from antarest.study.business.areas.hydro_management import InflowStructure, ManagementOptionsFormFields from antarest.study.business.areas.properties_management import PropertiesFormFields from antarest.study.business.areas.renewable_management import (