Skip to content

Commit

Permalink
feat: added update_link_properties in link.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiwahada committed Feb 24, 2025
1 parent 40881f3 commit a4c5de8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
4 changes: 0 additions & 4 deletions src/antares/craft/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ def __init__(self, study_id: str, new_folder_name: str, message: str) -> None:
self.message = f"Could not move the study {study_id} to folder {new_folder_name}: " + message
super().__init__(self.message)

class StudyImportError(Exception):
def __init__(self, study_name: str, destination_folder_name: str, message: str):
self.message = f"Could not import the study {study_name} to folder {destination_folder_name}: " + message
super().__init__(self.message)

class StudyImportError(Exception):
def __init__(self, study_id: str, message: str):
Expand Down
13 changes: 13 additions & 0 deletions src/antares/craft/model/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ class LinkProperties:
filter_synthesis: comma_separated_enum_set = field(default_factory=lambda: FILTER_VALUES)
filter_year_by_year: comma_separated_enum_set = field(default_factory=lambda: FILTER_VALUES)

def update_link_properties(self, link_props: LinkPropertiesUpdate) -> "LinkProperties":
self.hurdles_cost = link_props.hurdles_cost
self.loop_flow = link_props.loop_flow
self.use_phase_shifter = link_props.use_phase_shifter
self.transmission_capacities = link_props.transmission_capacities
self.asset_type = link_props.asset_type
self.display_comments = link_props.display_comments
self.comments = link_props.comments
self.filter_synthesis = link_props.filter_synthesis
self.filter_year_by_year = link_props.filter_year_by_year

return self


@dataclass
class LinkUi:
Expand Down
8 changes: 6 additions & 2 deletions src/antares/craft/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pathlib import Path, PurePath
from types import MappingProxyType
from typing import List, Optional, cast
from typing import Dict, List, Optional, cast

import pandas as pd

Expand All @@ -26,7 +26,7 @@
BindingConstraintProperties,
ConstraintTerm,
)
from antares.craft.model.link import Link, LinkProperties, LinkUi
from antares.craft.model.link import Link, LinkProperties, LinkPropertiesUpdate, LinkUi
from antares.craft.model.output import Output
from antares.craft.model.settings.study_settings import StudySettings, StudySettingsUpdate
from antares.craft.model.simulation import AntaresSimulationParameters, Job
Expand Down Expand Up @@ -311,3 +311,7 @@ def create_variant_api(api_config: APIconf, study_id: str, variant_name: str) ->
from antares.craft.service.api_services.factory import create_variant_api

return create_variant_api(api_config, study_id, variant_name)


def update_multiple_links(dict_links: Dict[str, LinkPropertiesUpdate]) -> None:
pass
9 changes: 8 additions & 1 deletion src/antares/craft/service/api_services/services/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This file is part of the Antares project.

from typing import Optional
from typing import Dict, Optional

import pandas as pd

Expand Down Expand Up @@ -204,3 +204,10 @@ def read_links(self) -> list[Link]:
except APIError as e:
raise LinksRetrievalError(self.study_id, e.message) from e
return links

@override
def update_multiple_links(self) -> Dict[str, LinkPropertiesUpdate]:
url = f"{self._base_url}/studies/{self.study_id}/table-mode/links"
self._wrapper.put(url)

raise NotImplementedError
13 changes: 0 additions & 13 deletions src/antares/craft/service/api_services/services/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,3 @@ def generate_thermal_timeseries(self, nb_years: int) -> None:
wait_task_completion(self._base_url, self._wrapper, task_id)
except (APIError, TaskFailedError, TaskTimeOutError) as e:
raise ThermalTimeseriesGenerationError(self.study_id, e.message)

def import_study(self, config: APIconf, study_path: Path, destination_path: Path) -> None:
def has_valid_extension(path: Path) -> bool:
valid_extensions = {".zip", ".7z"}
return path.suffix in valid_extensions

try:
if has_valid_extension(study_path):
url = f"{self._base_url}/studies/_import?study={study_path}&encode=multipart"
self._wrapper.post(url)
self.move_study(destination_path)
except APIError:
raise NotImplementedError
11 changes: 5 additions & 6 deletions src/antares/craft/service/base_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from pathlib import Path, PurePath
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Dict, Optional

import pandas as pd

from antares.craft.api_conf.api_conf import APIconf
from antares.craft.config.base_configuration import BaseConfiguration
from antares.craft.model.settings.study_settings import StudySettings, StudySettingsUpdate
from antares.craft.model.simulation import AntaresSimulationParameters, Job
Expand Down Expand Up @@ -460,6 +459,10 @@ def get_capacity_indirect(self, area_from: str, area_to: str) -> pd.DataFrame:
def create_capacity_indirect(self, series: pd.DataFrame, area_from: str, area_to: str) -> None:
pass

@abstractmethod
def update_multiple_links(self) -> Dict[str, LinkPropertiesUpdate]:
pass


class BaseThermalService(ABC):
@abstractmethod
Expand Down Expand Up @@ -678,10 +681,6 @@ def delete_output(self, output_name: str) -> None:
def generate_thermal_timeseries(self, number_of_years: int) -> None:
pass

@abstractmethod
def import_study(self, config: APIconf, study_path: Path, destination_path: Path) -> None:
pass


class BaseRenewableService(ABC):
@abstractmethod
Expand Down
4 changes: 4 additions & 0 deletions src/antares/craft/service/local_services/services/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,7 @@ def read_links(self) -> list[Link]:
)
)
return link_clusters

@override
def update_multiple_links(self) -> Dict[str, LinkPropertiesUpdate]:
raise NotImplementedError
4 changes: 0 additions & 4 deletions src/antares/craft/service/local_services/services/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from pathlib import Path, PurePath
from typing import TYPE_CHECKING

from antares.craft.api_conf.api_conf import APIconf
from antares.craft.config.local_configuration import LocalConfiguration
from antares.craft.model.binding_constraint import BindingConstraint
from antares.craft.model.output import Output
Expand Down Expand Up @@ -74,6 +73,3 @@ def move_study(self, new_parent_path: Path) -> PurePath:
@override
def generate_thermal_timeseries(self, number_of_years: int) -> None:
raise NotImplementedError

def import_study(self, config: APIconf, study_path: Path, destination_path: Path) -> None:
raise NotImplementedError

0 comments on commit a4c5de8

Please sign in to comment.