Skip to content

Commit

Permalink
Fix key_error issue (#36)
Browse files Browse the repository at this point in the history
* properties should not be mandatory on thermals. Plus remove area_id in some useless places

* remove area_id mentions in tests

* validate are.st_storage method

* lint

* try again
  • Loading branch information
killian-scalian authored Dec 13, 2024
1 parent f04bf8b commit a4217ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 46 deletions.
9 changes: 3 additions & 6 deletions src/antares/model/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,18 @@ def create_hydro(

def read_st_storages(
self,
area_id: str,
) -> List[STStorage]:
return self._storage_service.read_st_storages(area_id)
return self._storage_service.read_st_storages(self.id)

def read_renewables(
self,
area_id: str,
) -> List[RenewableCluster]:
return self._renewable_service.read_renewables(area_id)
return self._renewable_service.read_renewables(self.id)

def read_thermal_clusters(
self,
area_id: str,
) -> List[ThermalCluster]:
return self._thermal_service.read_thermal_clusters(area_id)
return self._thermal_service.read_thermal_clusters(self.id)

def read_hydro(
self,
Expand Down
70 changes: 35 additions & 35 deletions src/antares/service/local_services/thermal_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,42 @@ def read_thermal_clusters(self, area_id: str) -> List[ThermalCluster]:
for thermal_cluster in thermal_dict:
# TODO refactor this as it is really not clean
thermal_properties = ThermalClusterPropertiesLocal(
group=thermal_dict[thermal_cluster]["group"],
group=thermal_dict[thermal_cluster].get("group"),
thermal_name=thermal_dict[thermal_cluster]["name"],
enabled=thermal_dict[thermal_cluster]["enabled"],
unit_count=thermal_dict[thermal_cluster]["unitcount"],
nominal_capacity=thermal_dict[thermal_cluster]["nominalcapacity"],
gen_ts=thermal_dict[thermal_cluster]["gen-ts"],
min_stable_power=thermal_dict[thermal_cluster]["min-stable-power"],
min_up_time=thermal_dict[thermal_cluster]["min-up-time"],
min_down_time=thermal_dict[thermal_cluster]["min-down-time"],
must_run=thermal_dict[thermal_cluster]["must-run"],
spinning=thermal_dict[thermal_cluster]["spinning"],
volatility_forced=thermal_dict[thermal_cluster]["volatility.forced"],
volatility_planned=thermal_dict[thermal_cluster]["volatility.planned"],
law_forced=thermal_dict[thermal_cluster]["law.forced"],
law_planned=thermal_dict[thermal_cluster]["law.planned"],
marginal_cost=thermal_dict[thermal_cluster]["marginal-cost"],
spread_cost=thermal_dict[thermal_cluster]["spread-cost"],
fixed_cost=thermal_dict[thermal_cluster]["fixed-cost"],
startup_cost=thermal_dict[thermal_cluster]["startup-cost"],
market_bid_cost=thermal_dict[thermal_cluster]["market-bid-cost"],
co2=thermal_dict[thermal_cluster]["co2"],
nh3=thermal_dict[thermal_cluster]["nh3"],
so2=thermal_dict[thermal_cluster]["so2"],
nox=thermal_dict[thermal_cluster]["nox"],
pm2_5=thermal_dict[thermal_cluster]["pm2_5"],
pm5=thermal_dict[thermal_cluster]["pm5"],
pm10=thermal_dict[thermal_cluster]["pm10"],
nmvoc=thermal_dict[thermal_cluster]["nmvoc"],
op1=thermal_dict[thermal_cluster]["op1"],
op2=thermal_dict[thermal_cluster]["op2"],
op3=thermal_dict[thermal_cluster]["op3"],
op4=thermal_dict[thermal_cluster]["op4"],
op5=thermal_dict[thermal_cluster]["op5"],
cost_generation=thermal_dict[thermal_cluster]["costgeneration"],
efficiency=thermal_dict[thermal_cluster]["efficiency"],
variable_o_m_cost=thermal_dict[thermal_cluster]["variableomcost"],
enabled=thermal_dict[thermal_cluster].get("enabled"),
unit_count=thermal_dict[thermal_cluster].get("unitcount"),
nominal_capacity=thermal_dict[thermal_cluster].get("nominalcapacity"),
gen_ts=thermal_dict[thermal_cluster].get("gen-ts"),
min_stable_power=thermal_dict[thermal_cluster].get("min-stable-power"),
min_up_time=thermal_dict[thermal_cluster].get("min-up-time"),
min_down_time=thermal_dict[thermal_cluster].get("min-down-time"),
must_run=thermal_dict[thermal_cluster].get("must-run"),
spinning=thermal_dict[thermal_cluster].get("spinning"),
volatility_forced=thermal_dict[thermal_cluster].get("volatility.forced"),
volatility_planned=thermal_dict[thermal_cluster].get("volatility.planned"),
law_forced=thermal_dict[thermal_cluster].get("law.forced"),
law_planned=thermal_dict[thermal_cluster].get("law.planned"),
marginal_cost=thermal_dict[thermal_cluster].get("marginal-cost"),
spread_cost=thermal_dict[thermal_cluster].get("spread-cost"),
fixed_cost=thermal_dict[thermal_cluster].get("fixed-cost"),
startup_cost=thermal_dict[thermal_cluster].get("startup-cost"),
market_bid_cost=thermal_dict[thermal_cluster].get("market-bid-cost"),
co2=thermal_dict[thermal_cluster].get("co2"),
nh3=thermal_dict[thermal_cluster].get("nh3"),
so2=thermal_dict[thermal_cluster].get("so2"),
nox=thermal_dict[thermal_cluster].get("nox"),
pm2_5=thermal_dict[thermal_cluster].get("pm2_5"),
pm5=thermal_dict[thermal_cluster].get("pm5"),
pm10=thermal_dict[thermal_cluster].get("pm10"),
nmvoc=thermal_dict[thermal_cluster].get("nmvoc"),
op1=thermal_dict[thermal_cluster].get("op1"),
op2=thermal_dict[thermal_cluster].get("op2"),
op3=thermal_dict[thermal_cluster].get("op3"),
op4=thermal_dict[thermal_cluster].get("op4"),
op5=thermal_dict[thermal_cluster].get("op5"),
cost_generation=thermal_dict[thermal_cluster].get("costgeneration"),
efficiency=thermal_dict[thermal_cluster].get("efficiency"),
variable_o_m_cost=thermal_dict[thermal_cluster].get("variableomcost"),
)

thermal_clusters.append(
Expand Down
16 changes: 14 additions & 2 deletions tests/antares/services/local_services/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ def test_read_renewable_local(self, local_study_with_renewable):
],
dtype="object",
)
renewable_list = area.read_renewables(area.id)
renewable_list = area.read_renewables()

if renewable_list:
assert area.id == "fr"
Expand Down Expand Up @@ -1324,7 +1324,7 @@ def test_read_thermals_local(self, local_study_w_thermal):
dtype="object",
)

thermals_list = area.read_thermal_clusters(area.id)
thermals_list = area.read_thermal_clusters()

if thermals_list:
assert area.id == "fr"
Expand Down Expand Up @@ -1429,3 +1429,15 @@ def test_read_links_local(self, local_study_w_links):
assert link.properties.asset_type.value == "ac"
assert isinstance(link.properties.filter_year_by_year, set)
assert isinstance(link.properties.filter_synthesis, set)


class TestReadSTstorage:
def test_read_storage_local(self, local_study_w_thermal):
# TODO not finished at all, just here to validate area.read_st_storage
study_path = local_study_w_thermal.service.config.study_path
local_study_object = read_study_local(study_path)
areas = local_study_object.read_areas()

for area in areas:
with pytest.raises(NotImplementedError):
area.read_st_storages()
6 changes: 3 additions & 3 deletions tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
assert storage_fr.id == "cluster_test"

# test each list of clusters has the same length and objects by comparing their id
thermal_list = area_fr.read_thermal_clusters(area_fr.id)
renewable_list = area_fr.read_renewables(area_fr.id)
storage_list = area_fr.read_st_storages(area_fr.id)
thermal_list = area_fr.read_thermal_clusters()
renewable_list = area_fr.read_renewables()
storage_list = area_fr.read_st_storages()

assert len(thermal_list) == 2
assert len(renewable_list) == 2
Expand Down

0 comments on commit a4217ef

Please sign in to comment.