diff --git a/src/antares/model/settings/study_settings.py b/src/antares/model/settings/study_settings.py index 829c9d2e..2b23a578 100644 --- a/src/antares/model/settings/study_settings.py +++ b/src/antares/model/settings/study_settings.py @@ -10,8 +10,6 @@ # # This file is part of the Antares project. -from typing import Dict - from pydantic import BaseModel from antares.model.settings.adequacy_patch import DefaultAdequacyPatchParameters @@ -24,8 +22,13 @@ class PlaylistData(BaseModel): - status: bool - weight: float + status: bool = True + weight: float = 1.0 + + +class PlaylistParameters(BaseModel): + playlist_reset: bool = False + mc_years: dict[int, PlaylistData] = {} class DefaultStudySettings(BaseModel): @@ -40,7 +43,7 @@ class DefaultStudySettings(BaseModel): adequacy_patch_parameters: DefaultAdequacyPatchParameters = DefaultAdequacyPatchParameters() advanced_parameters: DefaultAdvancedParameters = DefaultAdvancedParameters() optimization_parameters: DefaultOptimizationParameters = DefaultOptimizationParameters() - playlist_parameters: Dict[str, PlaylistData] = {} + playlist_parameters: PlaylistParameters = PlaylistParameters() @all_optional_model diff --git a/src/antares/service/api_services/study_api.py b/src/antares/service/api_services/study_api.py index e102ff83..bcf0d72e 100644 --- a/src/antares/service/api_services/study_api.py +++ b/src/antares/service/api_services/study_api.py @@ -25,7 +25,7 @@ from antares.model.settings.advanced_parameters import AdvancedParameters from antares.model.settings.general import GeneralParameters from antares.model.settings.optimization import OptimizationParameters -from antares.model.settings.study_settings import StudySettings +from antares.model.settings.study_settings import PlaylistParameters, StudySettings from antares.model.settings.thematic_trimming import ThematicTrimmingParameters from antares.model.settings.time_series import TimeSeriesParameters from antares.service.base_services import BaseStudyService @@ -42,7 +42,7 @@ def _returns_study_settings( "adequacy_patch_parameters": ("adequacypatch", AdequacyPatchParameters), "advanced_parameters": ("advancedparameters", AdvancedParameters), "optimization_parameters": ("optimization", OptimizationParameters), - "playlist_parameters": ("playlist", None), + "playlist_parameters": ("playlist", PlaylistParameters), } if settings: json_settings = settings.model_dump(mode="json", by_alias=True, exclude_none=True) @@ -58,8 +58,13 @@ def _returns_study_settings( settings_class = settings_tuple[1] url = f"{settings_base_url}/{settings_tuple[0]}/form" response = wrapper.get(url) - if settings_type == "playlist_parameters": - settings_property = response.json() + if settings_type == "playlist_parameters" and json_settings["general_parameters"].selection_mode: + settings_property = settings_class.model_validate( # type: ignore + # Using selection_mode as that is the selector for user-playlist in general-parameters, AntaresWeb + # does not seem to allow any control of playlist_reset outside of debug and defaults to true which is + # the opposite of the documentation. + {"playlist_reset": json_settings["general_parameters"].selection_mode, "mc_years": response.json()} + ) else: settings_property = settings_class.model_validate(response.json()) # type: ignore json_settings[settings_type] = settings_property diff --git a/tests/integration/test_web_client.py b/tests/integration/test_web_client.py index 37642c93..2cde0cef 100644 --- a/tests/integration/test_web_client.py +++ b/tests/integration/test_web_client.py @@ -28,7 +28,7 @@ from antares.model.renewable import RenewableClusterGroup, RenewableClusterProperties, TimeSeriesInterpretation from antares.model.settings.advanced_parameters import AdvancedParameters, UnitCommitmentMode from antares.model.settings.general import GeneralParameters, Mode -from antares.model.settings.study_settings import PlaylistData, StudySettings +from antares.model.settings.study_settings import PlaylistData, PlaylistParameters, StudySettings from antares.model.st_storage import STStorageGroup, STStorageMatrixName, STStorageProperties from antares.model.study import create_study_api from antares.model.thermal import ThermalClusterGroup, ThermalClusterProperties @@ -372,7 +372,9 @@ def test_creation_lifecycle(self): settings = new_study.get_settings() assert settings.general_parameters.mode == Mode.ADEQUACY assert not settings.general_parameters.year_by_year - assert settings.playlist_parameters == {"1": PlaylistData(status=False, weight=1)} + assert settings.playlist_parameters == PlaylistParameters( + playlist_reset=True, mc_years={"1": PlaylistData(status=False, weight=1)} + ) # tests update settings new_settings = StudySettings()