Skip to content

Commit

Permalink
style: use constants instead of repeated strings
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed May 31, 2024
1 parent 709fee5 commit 8c3bc8d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions antarest/study/business/scenario_builder_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from antarest.study.storage.storage_service import StudyStorageService
from antarest.study.storage.variantstudy.model.command.update_scenario_builder import UpdateScenarioBuilder

# Symbols used in scenario builder data
_AREA_RELATED_SYMBOLS = "l", "h", "w", "s", "bc", "hgp"
_LINK_RELATED_SYMBOLS = ("ntc",)
_HYDRO_LEVEL_RELATED_SYMBOLS = "hl", "hfl"
_CLUSTER_RELATED_SYMBOLS = "t", "r"

_HYDRO_LEVEL_PERCENT = 100

_Section: te.TypeAlias = t.MutableMapping[str, t.Union[int, float]]
Expand All @@ -29,16 +35,16 @@ def get_config(self, study: Study) -> Rulesets:
for key, value in data.items():
symbol, *parts = key.split(",")
scenario = ruleset.setdefault(symbol, {})
if symbol in ("l", "h", "w", "s", "bc", "hgp"):
if symbol in _AREA_RELATED_SYMBOLS:
scenario_area = scenario.setdefault(parts[0], {})
scenario_area[parts[1]] = int(value)
elif symbol in ("hl", "hfl"):
elif symbol in _HYDRO_LEVEL_RELATED_SYMBOLS:
scenario_area = scenario.setdefault(parts[0], {})
scenario_area[parts[1]] = float(value) * _HYDRO_LEVEL_PERCENT
elif symbol in ("ntc",):
elif symbol in _LINK_RELATED_SYMBOLS:
scenario_link = scenario.setdefault(f"{parts[0]} / {parts[1]}", {})
scenario_link[parts[2]] = int(value)
elif symbol in ("t", "r"):
elif symbol in _CLUSTER_RELATED_SYMBOLS:
scenario_area = scenario.setdefault(parts[0], {})
scenario_area_cluster = scenario_area.setdefault(parts[2], {})
scenario_area_cluster[parts[1]] = int(value)
Expand All @@ -54,13 +60,13 @@ def update_config(self, study: Study, rulesets: Rulesets) -> None:
for ruleset_name, ruleset in rulesets.items():
section = sections[ruleset_name] = {}
for symbol, data in ruleset.items():
if symbol in ("l", "h", "w", "s", "bc", "hgp"):
if symbol in _AREA_RELATED_SYMBOLS:
_populate_common(section, symbol, data)
elif symbol in ("hl", "hfl"):
elif symbol in _HYDRO_LEVEL_RELATED_SYMBOLS:
_populate_hydro_levels(section, symbol, data)
elif symbol in ("ntc",):
elif symbol in _LINK_RELATED_SYMBOLS:
_populate_links(section, symbol, data)
elif symbol in ("t", "r"):
elif symbol in _CLUSTER_RELATED_SYMBOLS:
_populate_clusters(section, symbol, data)
else: # pragma: no cover
raise NotImplementedError(f"Unknown symbol {symbol}")
Expand Down

0 comments on commit 8c3bc8d

Please sign in to comment.