Skip to content

Commit

Permalink
little refacot
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Feb 12, 2025
1 parent 8414040 commit 786fe1b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/antares/craft/model/hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def update_properties(self, properties: HydroPropertiesUpdate) -> None:
self._properties = self.read_properties()

def read_properties(self) -> HydroProperties:
return self._service.read_properties(self.area_id)
properties = self._service.read_properties(self.area_id)
self._properties = properties
return properties

def get_maxpower(self) -> pd.DataFrame:
return self._service.get_maxpower(self.area_id)
Expand Down
7 changes: 2 additions & 5 deletions src/antares/craft/service/api_services/area_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
BaseShortTermStorageService,
BaseThermalService,
)
from antares.craft.tools.contents_tool import AreaUiResponse, transform_name_to_id
from antares.craft.tools.contents_tool import AreaUiResponse
from antares.craft.tools.matrix_tool import prepare_args_replace_matrix
from typing_extensions import override

Expand Down Expand Up @@ -507,9 +507,6 @@ def read_areas(self) -> list[Area]:
dict_thermals = {thermal.id: thermal for thermal in thermals}
dict_st_storage = {storage.id: storage for storage in st_storages}

area_id = transform_name_to_id(area)
hydro_properties = self.hydro_service.read_properties(area_id)
hydro = Hydro(self.hydro_service, area_id, hydro_properties)
area_obj = Area(
area,
self,
Expand All @@ -522,8 +519,8 @@ def read_areas(self) -> list[Area]:
st_storages=dict_st_storage,
properties=json_properties,
ui=ui_response,
hydro=hydro,
)
area_obj.hydro.read_properties()

area_list.append(area_obj)

Expand Down
6 changes: 2 additions & 4 deletions src/antares/craft/service/api_services/models/hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
from typing import Union

from antares.craft.model.hydro import HydroProperties, HydroPropertiesUpdate
from antares.craft.service.api_services.models.base_model import APIBaseModel
from antares.craft.tools.all_optional_meta import all_optional_model
from pydantic import BaseModel
from pydantic.alias_generators import to_camel

HydroPropertiesType = Union[HydroProperties, HydroPropertiesUpdate]


@all_optional_model
class HydroPropertiesAPI(BaseModel, populate_by_name=True, alias_generator=to_camel, extra="forbid"):
# todo: use API Model once the other PR is merged
class HydroPropertiesAPI(APIBaseModel):
inter_daily_breakdown: float
intra_daily_modulation: float
inter_monthly_breakdown: float
Expand Down
5 changes: 1 addition & 4 deletions src/antares/craft/service/local_services/area_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,6 @@ def read_areas(self) -> List[Area]:
layer_y=ui_dict["ui"].get("layerY"),
layer_color=ui_dict["ui"].get("layerColor"),
)
area_id = transform_name_to_id(element.name)
hydro_properties = self.hydro_service.read_properties(area_id)
hydro = Hydro(self.hydro_service, area_id, hydro_properties)
area = Area(
name=element.name,
area_service=self,
Expand All @@ -428,8 +425,8 @@ def read_areas(self) -> List[Area]:
hydro_service=self.hydro_service,
properties=area_properties.yield_area_properties(),
ui=ui_properties,
hydro=hydro,
)
area.hydro.read_properties()
areas.append(area)

areas.sort(key=lambda area_obj: area_obj.id)
Expand Down

0 comments on commit 786fe1b

Please sign in to comment.