Skip to content

Commit

Permalink
refactor(areas): remove areas UI form fields (#1955)
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia authored Feb 28, 2024
1 parent 39ebbfb commit c491baf
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 65 deletions.
34 changes: 0 additions & 34 deletions antarest/study/business/areas/properties_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,12 @@

AREA_PATH = "input/areas/{area}"
THERMAL_PATH = "input/thermal/areas/{field}/{{area}}"
UI_PATH = f"{AREA_PATH}/ui/ui"
OPTIMIZATION_PATH = f"{AREA_PATH}/optimization"
NODAL_OPTIMIZATION_PATH = f"{OPTIMIZATION_PATH}/nodal optimization"
FILTERING_PATH = f"{OPTIMIZATION_PATH}/filtering"
# Keep the order
FILTER_OPTIONS = ["hourly", "daily", "weekly", "monthly", "annual"]
DEFAULT_FILTER_VALUE = FILTER_OPTIONS
DEFAULT_UI = {
"color_r": 230,
"color_g": 108,
"color_b": 44,
}


def encode_color(ui: Dict[str, Any]) -> str:
data = {**DEFAULT_UI, **ui}
return f"{data['color_r']},{data['color_g']},{data['color_b']}"


def decode_color(encoded_color: str, current_ui: Optional[Dict[str, int]]) -> Dict[str, Any]:
r, g, b = map(int, encoded_color.split(","))
return {**(current_ui or {}), "color_r": r, "color_g": g, "color_b": b}


def sort_filter_options(options: Iterable[str]) -> List[str]:
Expand All @@ -60,9 +44,6 @@ class AdequacyPatchMode(EnumIgnoreCase):


class PropertiesFormFields(FormFieldsBaseModel):
color: Optional[str] = Field(regex="^\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*$")
pos_x: Optional[float]
pos_y: Optional[float]
energy_cost_unsupplied: Optional[float]
energy_cost_spilled: Optional[float]
non_dispatch_power: Optional[bool]
Expand All @@ -89,21 +70,6 @@ def validation(cls, values: Dict[str, Any]) -> Dict[str, Any]:


FIELDS_INFO: Dict[str, FieldInfo] = {
# `color` must be before `pos_x` and `pos_y`, because they are include in the `decode_color`'s return dict value
"color": {
"path": UI_PATH,
"encode": encode_color,
"decode": decode_color,
"default_value": encode_color(DEFAULT_UI),
},
"pos_x": {
"path": f"{UI_PATH}/x",
"default_value": 0.0,
},
"pos_y": {
"path": f"{UI_PATH}/y",
"default_value": 0.0,
},
"energy_cost_unsupplied": {
"path": THERMAL_PATH.format(field="unserverdenergycost"),
"default_value": 0.0,
Expand Down
9 changes: 0 additions & 9 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,6 @@ def test_area_management(client: TestClient, admin_access_token: str, study_id:
res_properties_config_json["filterSynthesis"] = set(res_properties_config_json["filterSynthesis"])
res_properties_config_json["filterByYear"] = set(res_properties_config_json["filterByYear"])
assert res_properties_config_json == {
"color": "230,108,44",
"posX": 0.0,
"posY": 0.0,
"energyCostUnsupplied": 0.0,
"energyCostSpilled": 0.0,
"nonDispatchPower": True,
Expand All @@ -1112,9 +1109,6 @@ def test_area_management(client: TestClient, admin_access_token: str, study_id:
f"/v1/studies/{study_id}/areas/area 1/properties/form",
headers=admin_headers,
json={
"color": "123,108,96",
"posX": 3.4,
"posY": 9.0,
"energyCostUnsupplied": 2.0,
"energyCostSpilled": 4.0,
"nonDispatchPower": False,
Expand All @@ -1130,9 +1124,6 @@ def test_area_management(client: TestClient, admin_access_token: str, study_id:
res_properties_config_json["filterSynthesis"] = set(res_properties_config_json["filterSynthesis"])
res_properties_config_json["filterByYear"] = set(res_properties_config_json["filterByYear"])
assert res_properties_config_json == {
"color": "123,108,96",
"posX": 3.4,
"posY": 9.0,
"energyCostUnsupplied": 2.0,
"energyCostSpilled": 4.0,
"nonDispatchPower": False,
Expand Down
2 changes: 0 additions & 2 deletions webapp/public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@
"study.configuration.geographicTrimmingAreas": "Geographic Trimming (areas)",
"study.configuration.geographicTrimmingLinks": "Geographic Trimming (links)",
"study.modelization.properties": "Properties",
"study.modelization.properties.posX": "Position X",
"study.modelization.properties.posY": "Position Y",
"study.modelization.properties.energyCost": "Energy cost (€/Wh)",
"study.modelization.properties.unsupplied": "Unsupplied",
"study.modelization.properties.spilled": "Spilled",
Expand Down
2 changes: 0 additions & 2 deletions webapp/public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@
"study.configuration.geographicTrimmingAreas": "Filtre géographique (zones)",
"study.configuration.geographicTrimmingLinks": "Filtre géographique (liens)",
"study.modelization.properties": "Propriétés",
"study.modelization.properties.posX": "Position X",
"study.modelization.properties.posY": "Position Y",
"study.modelization.properties.energyCost": "Coût de l'énergie",
"study.modelization.properties.unsupplied": "Non distribuée",
"study.modelization.properties.spilled": "Non évacuée",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useOutletContext } from "react-router";
import { useMemo } from "react";
import SelectFE from "../../../../../../common/fieldEditors/SelectFE";
import Fieldset from "../../../../../../common/Fieldset";
import ColorPickerFE from "../../../../../../common/fieldEditors/ColorPickerFE";
import SwitchFE from "../../../../../../common/fieldEditors/SwitchFE";
import NumberFE from "../../../../../../common/fieldEditors/NumberFE";
import { useFormContextPlus } from "../../../../../../common/Form";
Expand All @@ -27,23 +26,6 @@ function Fields() {

return (
<>
<Fieldset legend={t("global.general")}>
<ColorPickerFE
name="color"
label={t("global.color")}
control={control}
/>
<NumberFE
name="posX"
label={t("study.modelization.properties.posX")}
control={control}
/>
<NumberFE
name="posY"
label={t("study.modelization.properties.posY")}
control={control}
/>
</Fieldset>
<Fieldset legend={t("study.modelization.properties.energyCost")}>
<NumberFE
name="energyCostUnsupplied"
Expand Down

0 comments on commit c491baf

Please sign in to comment.