Skip to content

Commit

Permalink
Rewrote the way playlists are handled to allow control of the option …
Browse files Browse the repository at this point in the history
…playlist_reset
  • Loading branch information
Sigurd-Borge committed Oct 14, 2024
1 parent 4a968fd commit daf2d2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
13 changes: 8 additions & 5 deletions src/antares/model/settings/study_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/antares/service/api_services/study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit daf2d2b

Please sign in to comment.