Skip to content

Commit

Permalink
rebase with main
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Feb 11, 2025
2 parents 79526e4 + 24e604f commit e7075a5
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
mypy_path = src
packages= antares
strict = true

enable_error_code = explicit-override
25 changes: 25 additions & 0 deletions src/antares/craft/service/api_services/area_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
)
from antares.craft.tools.contents_tool import AreaUiResponse
from antares.craft.tools.matrix_tool import prepare_args_replace_matrix
from typing_extensions import override


class AreaApiService(BaseAreaService):
Expand All @@ -70,6 +71,7 @@ def __init__(
self.renewable_service: BaseRenewableService = renewable_service
self.hydro_service: BaseHydroService = hydro_service

@override
def create_area(
self, area_name: str, properties: Optional[AreaProperties] = None, ui: Optional[AreaUi] = None
) -> Area:
Expand Down Expand Up @@ -144,6 +146,7 @@ def create_area(
hydro=hydro,
)

@override
def create_thermal_cluster(
self, area_id: str, thermal_name: str, properties: Optional[ThermalClusterProperties] = None
) -> ThermalCluster:
Expand Down Expand Up @@ -179,6 +182,7 @@ def create_thermal_cluster(

return ThermalCluster(self.thermal_service, area_id, name, properties)

@override
def create_thermal_cluster_with_matrices(
self,
area_id: str,
Expand Down Expand Up @@ -279,6 +283,7 @@ def _replace_matrix_request(self, json_payload: Union[dict[str, Any], list[dict[
response = self._wrapper.post(url, json=json_payload)
response.raise_for_status()

@override
def create_renewable_cluster(
self,
area_id: str,
Expand Down Expand Up @@ -323,6 +328,7 @@ def create_renewable_cluster(

return RenewableCluster(self.renewable_service, area_id, name, properties)

@override
def create_st_storage(
self, area_id: str, st_storage_name: str, properties: Optional[STStorageProperties] = None
) -> STStorage:
Expand Down Expand Up @@ -357,6 +363,7 @@ def create_st_storage(

return STStorage(self.storage_service, area_id, name, properties)

@override
def create_load(self, area_id: str, series: pd.DataFrame) -> None:
try:
series_path = f"input/load/series/load_{area_id}"
Expand All @@ -368,34 +375,39 @@ def create_load(self, area_id: str, series: pd.DataFrame) -> None:
except APIError as e:
raise MatrixUploadError(area_id, "load", e.message) from e

@override
def create_wind(self, area_id: str, series: pd.DataFrame) -> None:
try:
series_path = f"input/wind/series/wind_{area_id}"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise MatrixUploadError(area_id, "wind", e.message) from e

@override
def create_reserves(self, area_id: str, series: pd.DataFrame) -> None:
try:
series_path = f"input/reserves/{area_id}"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise MatrixUploadError(area_id, "reserves", e.message) from e

@override
def create_solar(self, area_id: str, series: pd.DataFrame) -> None:
try:
series_path = f"input/solar/series/solar_{area_id}"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise MatrixUploadError(area_id, "solar", e.message) from e

@override
def create_misc_gen(self, area_id: str, series: pd.DataFrame) -> None:
try:
series_path = f"input/misc-gen/miscgen-{area_id}"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise MatrixUploadError(area_id, "misc-gen", e.message) from e

@override
def create_hydro(
self,
area_id: str,
Expand All @@ -421,6 +433,7 @@ def create_hydro(

return Hydro(self.hydro_service, area_id, properties)

@override
def read_hydro(
self,
area_id: str,
Expand Down Expand Up @@ -450,6 +463,7 @@ def _create_hydro_series(self, area_id: str, matrices: dict[HydroMatrixName, pd.

self._replace_matrix_request(json_payload)

@override
def update_area_properties(self, area_id: str, properties: AreaProperties) -> AreaProperties:
url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}/properties/form"
try:
Expand All @@ -464,6 +478,7 @@ def update_area_properties(self, area_id: str, properties: AreaProperties) -> Ar

return area_properties

@override
def update_area_ui(self, area_id: str, ui: AreaUi) -> AreaUi:
base_url = f"{self._base_url}/studies/{self.study_id}/areas"
try:
Expand Down Expand Up @@ -495,13 +510,15 @@ def update_area_ui(self, area_id: str, ui: AreaUi) -> AreaUi:

return area_ui

@override
def delete_area(self, area_id: str) -> None:
url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}"
try:
self._wrapper.delete(url)
except APIError as e:
raise AreaDeletionError(area_id, e.message) from e

@override
def delete_thermal_clusters(self, area_id: str, clusters: list[ThermalCluster]) -> None:
url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}/clusters/thermal"
body = [cluster.id for cluster in clusters]
Expand All @@ -510,6 +527,7 @@ def delete_thermal_clusters(self, area_id: str, clusters: list[ThermalCluster])
except APIError as e:
raise ThermalDeletionError(area_id, body, e.message) from e

@override
def delete_renewable_clusters(self, area_id: str, clusters: list[RenewableCluster]) -> None:
url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}/clusters/renewable"
body = [cluster.id for cluster in clusters]
Expand All @@ -518,6 +536,7 @@ def delete_renewable_clusters(self, area_id: str, clusters: list[RenewableCluste
except APIError as e:
raise RenewableDeletionError(area_id, body, e.message) from e

@override
def delete_st_storages(self, area_id: str, storages: list[STStorage]) -> None:
url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}/storages"
body = [storage.id for storage in storages]
Expand All @@ -526,30 +545,35 @@ def delete_st_storages(self, area_id: str, storages: list[STStorage]) -> None:
except APIError as e:
raise STStorageDeletionError(area_id, body, e.message) from e

@override
def get_load_matrix(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(self._base_url, self.study_id, self._wrapper, f"input/load/series/load_{area_id}")
except APIError as e:
raise MatrixDownloadError(area_id, "load", e.message)

@override
def get_solar_matrix(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(self._base_url, self.study_id, self._wrapper, f"input/solar/series/solar_{area_id}")
except APIError as e:
raise MatrixDownloadError(area_id, "solar", e.message)

@override
def get_wind_matrix(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(self._base_url, self.study_id, self._wrapper, f"input/wind/series/wind_{area_id}")
except APIError as e:
raise MatrixDownloadError(area_id, "wind", e.message)

@override
def get_reserves_matrix(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(self._base_url, self.study_id, self._wrapper, f"input/reserves/{area_id}")
except APIError as e:
raise MatrixDownloadError(area_id, "reserves", e.message)

@override
def get_misc_gen_matrix(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(self._base_url, self.study_id, self._wrapper, f"input/misc-gen/miscgen-{area_id}")
Expand All @@ -565,6 +589,7 @@ def craft_ui(self, url_str: str, area_id: str) -> AreaUi:

return current_ui

@override
def read_areas(self) -> list[Area]:
area_list = []

Expand Down
16 changes: 12 additions & 4 deletions src/antares/craft/service/api_services/binding_constraint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# This file is part of the Antares project.

from pathlib import PurePosixPath
from typing import List, Optional
from typing import Optional

import pandas as pd

Expand All @@ -35,6 +35,7 @@
)
from antares.craft.service.api_services.utils import get_matrix
from antares.craft.service.base_services import BaseBindingConstraintService
from typing_extensions import override


class BindingConstraintApiService(BaseBindingConstraintService):
Expand All @@ -45,11 +46,12 @@ def __init__(self, config: APIconf, study_id: str) -> None:
self._wrapper = RequestWrapper(self.api_config.set_up_api_conf())
self._base_url = f"{self.api_config.get_host()}/api/v1"

@override
def create_binding_constraint(
self,
name: str,
properties: Optional[BindingConstraintProperties] = None,
terms: Optional[List[ConstraintTerm]] = None,
terms: Optional[list[ConstraintTerm]] = None,
less_term_matrix: Optional[pd.DataFrame] = None,
equal_term_matrix: Optional[pd.DataFrame] = None,
greater_term_matrix: Optional[pd.DataFrame] = None,
Expand Down Expand Up @@ -89,7 +91,7 @@ def create_binding_constraint(
for key in ["terms", "id", "name"]:
del created_properties[key]
bc_properties = BindingConstraintProperties.model_validate(created_properties)
bc_terms: List[ConstraintTerm] = []
bc_terms: list[ConstraintTerm] = []

if terms:
json_terms = [term.model_dump() for term in terms]
Expand All @@ -108,13 +110,15 @@ def create_binding_constraint(

return constraint

@override
def delete_binding_constraint_term(self, constraint_id: str, term_id: str) -> None:
url = f"{self._base_url}/studies/{self.study_id}/bindingconstraints/{constraint_id}/term/{term_id}"
try:
self._wrapper.delete(url)
except APIError as e:
raise ConstraintTermDeletionError(constraint_id, term_id, e.message) from e

@override
def update_binding_constraint_properties(
self, binding_constraint: BindingConstraint, properties: BindingConstraintProperties
) -> BindingConstraintProperties:
Expand All @@ -135,13 +139,15 @@ def update_binding_constraint_properties(

return new_properties

@override
def get_constraint_matrix(self, constraint: BindingConstraint, matrix_name: ConstraintMatrixName) -> pd.DataFrame:
try:
path = PurePosixPath("input") / "bindingconstraints" / f"{constraint.id}_{matrix_name.value}"
return get_matrix(self._base_url, self.study_id, self._wrapper, path.as_posix())
except APIError as e:
raise ConstraintMatrixDownloadError(constraint.id, matrix_name.value, e.message) from e

@override
def update_constraint_matrix(
self, constraint: BindingConstraint, matrix_name: ConstraintMatrixName, matrix: pd.DataFrame
) -> None:
Expand All @@ -157,7 +163,8 @@ def update_constraint_matrix(
except APIError as e:
raise ConstraintMatrixUpdateError(constraint.id, matrix_name.value, e.message) from e

def add_constraint_terms(self, constraint: BindingConstraint, terms: List[ConstraintTerm]) -> List[ConstraintTerm]:
@override
def add_constraint_terms(self, constraint: BindingConstraint, terms: list[ConstraintTerm]) -> list[ConstraintTerm]:
url = f"{self._base_url}/studies/{self.study_id}/bindingconstraints/{constraint.id}"
try:
json_terms = [term.model_dump() for term in terms]
Expand All @@ -172,6 +179,7 @@ def add_constraint_terms(self, constraint: BindingConstraint, terms: List[Constr

return new_terms

@override
def read_binding_constraints(self) -> list[BindingConstraint]:
url = f"{self._base_url}/studies/{self.study_id}/bindingconstraints"
try:
Expand Down
6 changes: 6 additions & 0 deletions src/antares/craft/service/api_services/hydro_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from antares.craft.exceptions.exceptions import APIError, MatrixDownloadError
from antares.craft.service.api_services.utils import get_matrix
from antares.craft.service.base_services import BaseHydroService
from typing_extensions import override


class HydroApiService(BaseHydroService):
Expand All @@ -27,6 +28,7 @@ def __init__(self, config: APIconf, study_id: str):
self._wrapper = RequestWrapper(self.api_config.set_up_api_conf())
self._base_url = f"{self.api_config.get_host()}/api/v1"

@override
def get_maxpower(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(
Expand All @@ -35,6 +37,7 @@ def get_maxpower(self, area_id: str) -> pd.DataFrame:
except APIError as e:
raise MatrixDownloadError(area_id, "maxpower", e.message) from e

@override
def get_reservoir(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(
Expand All @@ -43,6 +46,7 @@ def get_reservoir(self, area_id: str) -> pd.DataFrame:
except APIError as e:
raise MatrixDownloadError(area_id, "reservoir", e.message) from e

@override
def get_inflow_pattern(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(
Expand All @@ -51,6 +55,7 @@ def get_inflow_pattern(self, area_id: str) -> pd.DataFrame:
except APIError as e:
raise MatrixDownloadError(area_id, "inflow_pattern", e.message) from e

@override
def get_credit_modulations(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(
Expand All @@ -59,6 +64,7 @@ def get_credit_modulations(self, area_id: str) -> pd.DataFrame:
except APIError as e:
raise MatrixDownloadError(area_id, "credit_modulations", e.message) from e

@override
def get_water_values(self, area_id: str) -> pd.DataFrame:
try:
return get_matrix(
Expand Down
Loading

0 comments on commit e7075a5

Please sign in to comment.