Skip to content

Commit

Permalink
fix: renaming upload_ methods by rename_
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiwahada committed Feb 20, 2025
1 parent 61c3f87 commit 8d7b8bc
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 80 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
20 changes: 10 additions & 10 deletions src/antares/craft/model/st_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ def get_upper_rule_curve(self) -> pd.DataFrame:
def get_storage_inflows(self) -> pd.DataFrame:
return self._storage_service.get_storage_matrix(self, STStorageMatrixName.INFLOWS)

def upload_pmax_injection(self, p_max_injection_matrix: pd.DataFrame) -> None:
self._storage_service.upload_storage_matrix(self, STStorageMatrixName.PMAX_INJECTION, p_max_injection_matrix)
def update_pmax_injection(self, p_max_injection_matrix: pd.DataFrame) -> None:
self._storage_service.update_storage_matrix(self, STStorageMatrixName.PMAX_INJECTION, p_max_injection_matrix)

def upload_pmax_withdrawal(self, p_max_withdrawal_matrix: pd.DataFrame) -> None:
self._storage_service.upload_storage_matrix(self, STStorageMatrixName.PMAX_WITHDRAWAL, p_max_withdrawal_matrix)
def update_pmax_withdrawal(self, p_max_withdrawal_matrix: pd.DataFrame) -> None:
self._storage_service.update_storage_matrix(self, STStorageMatrixName.PMAX_WITHDRAWAL, p_max_withdrawal_matrix)

def upload_lower_rule_curve(self, lower_rule_curve_matrix: pd.DataFrame) -> None:
self._storage_service.upload_storage_matrix(self, STStorageMatrixName.LOWER_CURVE_RULE, lower_rule_curve_matrix)
def update_lower_rule_curve(self, lower_rule_curve_matrix: pd.DataFrame) -> None:
self._storage_service.update_storage_matrix(self, STStorageMatrixName.LOWER_CURVE_RULE, lower_rule_curve_matrix)

def upload_upper_rule_curve(self, upper_rule_curve_matrix: pd.DataFrame) -> None:
self._storage_service.upload_storage_matrix(self, STStorageMatrixName.UPPER_RULE_CURVE, upper_rule_curve_matrix)
def update_upper_rule_curve(self, upper_rule_curve_matrix: pd.DataFrame) -> None:
self._storage_service.update_storage_matrix(self, STStorageMatrixName.UPPER_RULE_CURVE, upper_rule_curve_matrix)

def upload_storage_inflows(self, inflows_matrix: pd.DataFrame) -> None:
self._storage_service.upload_storage_matrix(self, STStorageMatrixName.INFLOWS, inflows_matrix)
def update_storage_inflows(self, inflows_matrix: pd.DataFrame) -> None:
self._storage_service.update_storage_matrix(self, STStorageMatrixName.INFLOWS, inflows_matrix)
8 changes: 4 additions & 4 deletions src/antares/craft/service/api_services/link_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
LinkUploadError,
)
from antares.craft.model.link import Link, LinkProperties, LinkUi
from antares.craft.service.api_services.utils import get_matrix, upload_series
from antares.craft.service.api_services.utils import get_matrix, update_series
from antares.craft.service.base_services import BaseLinkService
from typing_extensions import override

Expand Down Expand Up @@ -187,7 +187,7 @@ def get_parameters(self, area_from: str, area_to: str) -> pd.DataFrame:
def create_parameters(self, series: pd.DataFrame, area_from: str, area_to: str) -> None:
try:
series_path = f"input/links/{area_from}/{area_to}_parameters"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
update_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise LinkUploadError(area_from, area_to, "parameters", e.message) from e

Expand All @@ -204,7 +204,7 @@ def get_capacity_direct(self, area_from: str, area_to: str) -> pd.DataFrame:
def create_capacity_direct(self, series: pd.DataFrame, area_from: str, area_to: str) -> None:
try:
series_path = f"input/links/{area_from}/capacities/{area_to}_direct"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
update_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise LinkUploadError(area_from, area_to, "directcapacity", e.message) from e

Expand All @@ -221,7 +221,7 @@ 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:
try:
series_path = f"input/links/{area_from}/capacities/{area_to}_indirect"
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
update_series(self._base_url, self.study_id, self._wrapper, series, series_path)
except APIError as e:
raise LinkUploadError(area_from, area_to, "indirectcapacity", e.message) from e

Expand Down
22 changes: 11 additions & 11 deletions src/antares/craft/service/api_services/services/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from antares.craft.service.api_services.models.renewable import RenewableClusterPropertiesAPI
from antares.craft.service.api_services.models.st_storage import STStoragePropertiesAPI
from antares.craft.service.api_services.models.thermal import ThermalClusterPropertiesAPI
from antares.craft.service.api_services.utils import get_matrix, upload_series
from antares.craft.service.api_services.utils import get_matrix, update_series
from antares.craft.service.base_services import (
BaseAreaService,
BaseHydroService,
Expand Down Expand Up @@ -202,19 +202,19 @@ def create_thermal_cluster(
# Upload matrices
if prepro is not None:
matrix_path = f"input/thermal/prepro/{area_id}/{thermal_id}/data"
upload_series(self._base_url, self.study_id, self._wrapper, prepro, matrix_path)
update_series(self._base_url, self.study_id, self._wrapper, prepro, matrix_path)
if modulation is not None:
matrix_path = f"input/thermal/prepro/{area_id}/{thermal_id}/modulation"
upload_series(self._base_url, self.study_id, self._wrapper, modulation, matrix_path)
update_series(self._base_url, self.study_id, self._wrapper, modulation, matrix_path)
if series is not None:
matrix_path = f"input/thermal/series/{area_id}/{thermal_id}/series"
upload_series(self._base_url, self.study_id, self._wrapper, series, matrix_path)
update_series(self._base_url, self.study_id, self._wrapper, series, matrix_path)
if co2_cost is not None:
matrix_path = f"input/thermal/series/{area_id}/{thermal_id}/CO2Cost"
upload_series(self._base_url, self.study_id, self._wrapper, co2_cost, matrix_path)
update_series(self._base_url, self.study_id, self._wrapper, co2_cost, matrix_path)
if fuel_cost is not None:
matrix_path = f"input/thermal/series/{area_id}/{thermal_id}/fuelCost"
upload_series(self._base_url, self.study_id, self._wrapper, fuel_cost, matrix_path)
update_series(self._base_url, self.study_id, self._wrapper, fuel_cost, matrix_path)

except APIError as e:
raise ThermalCreationError(cluster_name, area_id, e.message) from e
Expand Down Expand Up @@ -322,39 +322,39 @@ def create_load(self, area_id: str, series: pd.DataFrame) -> None:
expected_rows = 8760
if rows_number < expected_rows:
raise MatrixUploadError(area_id, "load", f"Expected {expected_rows} rows and received {rows_number}.")
upload_series(self._base_url, self.study_id, self._wrapper, series, series_path)
update_series(self._base_url, self.study_id, self._wrapper, series, series_path)
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)
update_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)
update_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)
update_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)
update_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

Expand Down
20 changes: 10 additions & 10 deletions src/antares/craft/service/api_services/services/hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from antares.craft.model.hydro import HydroProperties, HydroPropertiesUpdate
from antares.craft.service.api_services.models.hydro import HydroPropertiesAPI
from antares.craft.service.api_services.utils import get_matrix, upload_series
from antares.craft.service.api_services.utils import get_matrix, update_series
from antares.craft.service.base_services import BaseHydroService
from typing_extensions import override

Expand Down Expand Up @@ -134,7 +134,7 @@ def get_energy(self, area_id: str) -> pd.DataFrame:
@override
def update_maxpower(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url, self.study_id, self._wrapper, series, f"input/hydro/common/capacity/maxpower_{area_id}"
)
except APIError as e:
Expand All @@ -143,7 +143,7 @@ def update_maxpower(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_reservoir(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url, self.study_id, self._wrapper, series, f"input/hydro/common/capacity/reservoir_{area_id}"
)
except APIError as e:
Expand All @@ -152,7 +152,7 @@ def update_reservoir(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_inflow_pattern(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url,
self.study_id,
self._wrapper,
Expand All @@ -165,7 +165,7 @@ def update_inflow_pattern(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_credits_modulation(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url,
self.study_id,
self._wrapper,
Expand All @@ -178,7 +178,7 @@ def update_credits_modulation(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_water_values(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url,
self.study_id,
self._wrapper,
Expand All @@ -191,14 +191,14 @@ def update_water_values(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_ror_series(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(self._base_url, self.study_id, self._wrapper, series, f"input/hydro/series/{area_id}/ror")
update_series(self._base_url, self.study_id, self._wrapper, series, f"input/hydro/series/{area_id}/ror")
except APIError as e:
raise MatrixUploadError(area_id, "ror", e.message) from e

@override
def update_mod_series(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url,
self.study_id,
self._wrapper,
Expand All @@ -211,7 +211,7 @@ def update_mod_series(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_mingen(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url,
self.study_id,
self._wrapper,
Expand All @@ -224,7 +224,7 @@ def update_mingen(self, area_id: str, series: pd.DataFrame) -> None:
@override
def update_energy(self, area_id: str, series: pd.DataFrame) -> None:
try:
upload_series(
update_series(
self._base_url,
self.study_id,
self._wrapper,
Expand Down
4 changes: 2 additions & 2 deletions src/antares/craft/service/api_services/services/renewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
from antares.craft.model.renewable import RenewableCluster, RenewableClusterProperties, RenewableClusterPropertiesUpdate
from antares.craft.service.api_services.models.renewable import RenewableClusterPropertiesAPI
from antares.craft.service.api_services.utils import get_matrix, upload_series
from antares.craft.service.api_services.utils import get_matrix, update_series
from antares.craft.service.base_services import BaseRenewableService
from typing_extensions import override

Expand Down Expand Up @@ -73,7 +73,7 @@ def update_renewable_matrix(self, renewable_cluster: RenewableCluster, matrix: p
/ "series"
)

upload_series(self._base_url, self.study_id, self._wrapper, matrix, path.as_posix())
update_series(self._base_url, self.study_id, self._wrapper, matrix, path.as_posix())
except APIError as e:
raise RenewableMatrixUpdateError(renewable_cluster.area_id, renewable_cluster.id, e.message) from e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def update_st_storage_properties(
return new_properties

@override
def upload_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName, matrix: pd.DataFrame) -> None:
def update_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName, matrix: pd.DataFrame) -> None:
url = f"{self._base_url}/studies/{self.study_id}/areas/{storage.area_id}/storages/{storage.id}/series/{ts_name.value}"
try:
body = {
Expand Down
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 @@ -142,16 +142,3 @@ def generate_thermal_timeseries(self) -> 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
4 changes: 2 additions & 2 deletions src/antares/craft/service/api_services/services/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ThermalClusterPropertiesUpdate,
)
from antares.craft.service.api_services.models.thermal import ThermalClusterPropertiesAPI
from antares.craft.service.api_services.utils import get_matrix, upload_series
from antares.craft.service.api_services.utils import get_matrix, update_series
from antares.craft.service.base_services import BaseThermalService
from typing_extensions import override

Expand Down Expand Up @@ -77,7 +77,7 @@ def update_thermal_matrix(self, thermal_cluster: ThermalCluster, matrix: pd.Data
/ "series"
)
try:
upload_series(self._base_url, self.study_id, self._wrapper, matrix, path.as_posix())
update_series(self._base_url, self.study_id, self._wrapper, matrix, path.as_posix())
except APIError as e:
raise ThermalMatrixUpdateError(thermal_cluster.area_id, thermal_cluster.name, e.message) from e

Expand Down
2 changes: 1 addition & 1 deletion src/antares/craft/service/api_services/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from antares.craft.exceptions.exceptions import TaskFailedError, TaskTimeOutError


def upload_series(base_url: str, study_id: str, wrapper: RequestWrapper, series: pd.DataFrame, path: str) -> None:
def update_series(base_url: str, study_id: str, wrapper: RequestWrapper, series: pd.DataFrame, path: str) -> None:
url = f"{base_url}/studies/{study_id}/raw?path={path}"
array_data = series.to_numpy().tolist()
wrapper.post(url, json=array_data)
Expand Down
7 changes: 1 addition & 6 deletions src/antares/craft/service/base_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

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 @@ -676,10 +675,6 @@ def delete_output(self, output_name: str) -> None:
def generate_thermal_timeseries(self) -> None:
pass

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


class BaseRenewableService(ABC):
@abstractmethod
Expand Down Expand Up @@ -740,7 +735,7 @@ def get_storage_matrix(self, storage: "STStorage", ts_name: "STStorageMatrixName
pass

@abstractmethod
def upload_storage_matrix(self, storage: "STStorage", ts_name: "STStorageMatrixName", matrix: pd.DataFrame) -> None:
def update_storage_matrix(self, storage: "STStorage", ts_name: "STStorageMatrixName", matrix: pd.DataFrame) -> None:
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def read_st_storages(self, area_id: str) -> List[STStorage]:
raise NotImplementedError

@override
def upload_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName, matrix: pd.DataFrame) -> None:
def update_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName, matrix: pd.DataFrame) -> None:
raise NotImplementedError

@override
Expand Down
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) -> None:
raise NotImplementedError

def import_study(self, config: APIconf, study_path: Path, destination_path: Path) -> None:
raise NotImplementedError
2 changes: 1 addition & 1 deletion tests/antares/services/api_services/test_matrix_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_create_load_fails(self):
):
self.area.create_load(pd.DataFrame(data=np.ones((8760, 1))))

def test_upload_wrongly_formatted_load_matrix_fails(self):
def test_update_wrongly_formatted_load_matrix_fails(self):
with requests_mock.Mocker() as mocker:
url = f"https://antares.com/api/v1/studies/{self.study_id}/raw?path=input/load/series/load_{self.area.id}"
mocker.post(url, json={"description": self.antares_web_description_msg}, status_code=404)
Expand Down
Loading

0 comments on commit 8d7b8bc

Please sign in to comment.