Skip to content

Commit

Permalink
lint with ruff to check if it pass
Browse files Browse the repository at this point in the history
  • Loading branch information
killian-scalian committed Dec 17, 2024
1 parent d33d439 commit 9527a07
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 25 deletions.
13 changes: 9 additions & 4 deletions src/andromede/input_converter/src/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
from antares.model.study import read_study_local, Study
from typing import Optional
from pydantic import BaseModel
from andromede.study.parsing import InputComponents
import yaml
from andromede.input_converter.src.utils import resolve_path, convert_area_to_components
from andromede.input_converter.src.utils import (
resolve_path,
convert_renewable_to_components,
convert_area_to_components,
)


class StudyConverter:
def __init__(self, study_path: Optional[str]):
"""
Initialize processor
"""
self.study_path = resolve_path(study_path) if study_path else None
self.study = None
self.study = None

def load_study(self) -> Study:
return read_study_local(self.study_path)
Expand All @@ -31,7 +37,6 @@ def convert_study_to_input_components(self):
areas = self.study.read_areas()
convert_area_to_components(areas)


def validate_with_pydantic(self, data, model_class) -> BaseModel:
return model_class(**data)

Expand All @@ -40,4 +45,4 @@ def transform_to_yaml(self, data, output_path):
yaml.dump(data, yaml_file)

def process_all(self) -> None:
raise NotImplementedError
raise NotImplementedError
5 changes: 4 additions & 1 deletion src/andromede/input_converter/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

DEFAULT: dict = {}


class PathType:
"""file or directory path type for `argparse` parser
Expand Down Expand Up @@ -106,6 +107,7 @@ def __call__(self, string: str) -> Path:
else: # pragma: no cover
raise NotImplementedError((self.file_ok, self.dir_ok))


def parse_commandline() -> argparse.Namespace:
# Parse command-line arguments using argparse to specify configuration file paths,
# logging options, and version display. Returns the parsed arguments.
Expand All @@ -125,6 +127,7 @@ def parse_commandline() -> argparse.Namespace:
)
return parser.parse_args()


def handle_env(config_parser) -> dict:
# Read configuration items from the config parser and set them as environment variables.
# Return a dictionary of the environment variables that were set.
Expand Down Expand Up @@ -158,4 +161,4 @@ def handle_env(config_parser) -> dict:

env_cfg = handle_env(config_parser)
processor = StudyConverter()
processor.process_all()
processor.process_all()
45 changes: 38 additions & 7 deletions src/andromede/input_converter/src/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from pathlib import Path
from antares.model.area import Area
from andromede.study.parsing import InputComponent, InputComponents, InputComponentParameter
from andromede.study.parsing import (
InputComponent,
InputComponents,
InputComponentParameter,
)
from pydantic import BaseModel


def resolve_path(path_str):
path = Path(path_str)
if not path.exists():
Expand All @@ -11,8 +16,14 @@ def resolve_path(path_str):
absolute_path = path.resolve()
return absolute_path

def convert_area_to_components(areas: list[Area])-> BaseModel:
return InputComponents(nodes=[InputComponent(id=area.id, model="area") for area in areas], components=[], connections=[])

def convert_area_to_components(areas: list[Area]) -> BaseModel:
return InputComponents(
nodes=[InputComponent(id=area.id, model="area") for area in areas],
components=[],
connections=[],
)


def convert_renewable_to_components(area: Area) -> list:
renewables = area.read_renewables()
Expand All @@ -21,34 +32,54 @@ def convert_renewable_to_components(area: Area) -> list:
id=renewable.id,
model="renewable",
parameters=[
InputComponentParameter(name="unit_count", type="constant", value=renewable.properties.unit_count),
InputComponentParameter(name="nominal_capacity", type="constant", value=renewable.properties.nominal_capacity),
InputComponentParameter(name=renewable.id, type="timeserie", timeseries=str(renewable.get_timeseries()))
]
InputComponentParameter(
name="unit_count",
type="constant",
value=renewable.properties.unit_count,
),
InputComponentParameter(
name="nominal_capacity",
type="constant",
value=renewable.properties.nominal_capacity,
),
InputComponentParameter(
name=renewable.id,
type="timeserie",
timeseries=str(renewable.get_timeseries()),
),
],
)
for renewable in renewables
]


def convert_hydro_to_components(area: Area) -> list:
raise NotImplementedError


def convert_st_storages_to_components(area: Area) -> list:
raise NotImplementedError


def convert_thermals_to_components(area: Area) -> list:
raise NotImplementedError


def convert_load_matrix_to_components(area: Area) -> list:
raise NotImplementedError


def convert_misc_gen_to_components(area: Area) -> list:
raise NotImplementedError


def convert_reserves_matrix_to_components(area: Area) -> list:
raise NotImplementedError


def convert_wind_matrix_to_components(area: Area) -> list:
raise NotImplementedError


def convert_solar_matrix_to_components(area: Area) -> list:
raise NotImplementedError
30 changes: 24 additions & 6 deletions tests/input_converter/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,27 @@ def default_thermal_cluster_properties() -> ThermalClusterProperties:

@pytest.fixture
def actual_thermal_list_ini(local_study_w_thermal) -> IniFile:
return IniFile(local_study_w_thermal.service.config.study_path, IniFileTypes.THERMAL_LIST_INI, area_id="fr")
return IniFile(
local_study_w_thermal.service.config.study_path,
IniFileTypes.THERMAL_LIST_INI,
area_id="fr",
)


@pytest.fixture
def actual_thermal_areas_ini(local_study_w_thermal) -> IniFile:
return IniFile(local_study_w_thermal.service.config.study_path, IniFileTypes.THERMAL_AREAS_INI)
return IniFile(
local_study_w_thermal.service.config.study_path, IniFileTypes.THERMAL_AREAS_INI
)


@pytest.fixture
def actual_adequacy_patch_ini(local_study_w_areas) -> IniFile:
return IniFile(local_study_w_areas.service.config.study_path, IniFileTypes.AREA_ADEQUACY_PATCH_INI, area_id="fr")
return IniFile(
local_study_w_areas.service.config.study_path,
IniFileTypes.AREA_ADEQUACY_PATCH_INI,
area_id="fr",
)


@pytest.fixture
Expand All @@ -147,7 +157,11 @@ def default_renewable_cluster_properties() -> RenewableClusterProperties:

@pytest.fixture
def actual_renewable_list_ini(local_study_with_renewable) -> IniFile:
return IniFile(local_study_with_renewable.service.config.study_path, IniFileTypes.RENEWABLES_LIST_INI, area_id="fr")
return IniFile(
local_study_with_renewable.service.config.study_path,
IniFileTypes.RENEWABLES_LIST_INI,
area_id="fr",
)


@pytest.fixture
Expand All @@ -174,7 +188,9 @@ def default_st_storage_properties() -> STStorageProperties:
@pytest.fixture
def actual_st_storage_list_ini(local_study_with_st_storage) -> IniFile:
return IniFile(
local_study_with_st_storage.service.config.study_path, IniFileTypes.ST_STORAGE_LIST_INI, area_id="fr"
local_study_with_st_storage.service.config.study_path,
IniFileTypes.ST_STORAGE_LIST_INI,
area_id="fr",
)


Expand Down Expand Up @@ -207,7 +223,9 @@ def default_hydro_properties() -> HydroProperties:

@pytest.fixture
def actual_hydro_ini(local_study_with_hydro) -> IniFile:
return IniFile(local_study_with_hydro.service.config.study_path, IniFileTypes.HYDRO_INI)
return IniFile(
local_study_with_hydro.service.config.study_path, IniFileTypes.HYDRO_INI
)


@pytest.fixture
Expand Down
13 changes: 6 additions & 7 deletions tests/input_converter/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ def test_convert_area_to_input_components(self, local_study_w_areas):
areas = local_study_w_areas.read_areas()
area_components = convert_area_to_components(areas)
expected_area_components = InputComponents(
nodes=[
InputComponent(id="it", model="area", parameters=None),
InputComponent(id="fr", model="area", parameters=None),
],
components=[],
connections=[]
nodes=[
InputComponent(id="it", model="area", parameters=None),
InputComponent(id="fr", model="area", parameters=None),
],
components=[],
connections=[],
)
assert area_components == expected_area_components

0 comments on commit 9527a07

Please sign in to comment.