From 0089f49b2e4b8f30d92a4ff60137f3170ee5ae86 Mon Sep 17 00:00:00 2001 From: EtienneLt <32468651+EtienneLt@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:22:03 +0100 Subject: [PATCH] add optional on getRegulatedSide (#717) Signed-off-by: Etienne LESOT --- .../validation/TwtValidationData.java | 6 +- .../loadflow/validation/Validations.java | 2 +- ...ag-example1_test_regulated_side_null.xiidm | 63 +++++++++++++++++++ tests/test_loadflow.py | 10 ++- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 tests/eurostag-example1_test_regulated_side_null.xiidm diff --git a/java/src/main/java/com/powsybl/dataframe/loadflow/validation/TwtValidationData.java b/java/src/main/java/com/powsybl/dataframe/loadflow/validation/TwtValidationData.java index 434e64084b..b5e2b78208 100644 --- a/java/src/main/java/com/powsybl/dataframe/loadflow/validation/TwtValidationData.java +++ b/java/src/main/java/com/powsybl/dataframe/loadflow/validation/TwtValidationData.java @@ -2,6 +2,8 @@ import com.powsybl.iidm.network.TwoSides; +import java.util.Optional; + /** * @author Yichen TANG */ @@ -88,8 +90,8 @@ int getHighTapPosition() { return targetV; } - TwoSides getRegulatedSide() { - return regulatedSide; + Optional getRegulatedSide() { + return Optional.ofNullable(regulatedSide); } double getV() { diff --git a/java/src/main/java/com/powsybl/dataframe/loadflow/validation/Validations.java b/java/src/main/java/com/powsybl/dataframe/loadflow/validation/Validations.java index 560c2fd108..4f3bc757cc 100644 --- a/java/src/main/java/com/powsybl/dataframe/loadflow/validation/Validations.java +++ b/java/src/main/java/com/powsybl/dataframe/loadflow/validation/Validations.java @@ -162,7 +162,7 @@ public static DataframeMapper> twtsValidationMapper() { .ints("low_tap_position", TwtValidationData::getLowTapPosition) .ints("high_tap_position", TwtValidationData::getHighTapPosition) .doubles("target_v", TwtValidationData::getTargetV) - .strings("regulated_side", d -> d.getRegulatedSide().name()) + .strings("regulated_side", d -> d.getRegulatedSide().map(Enum::name).orElse("")) .doubles("v", TwtValidationData::getV) .booleans("connected", TwtValidationData::isConnected) .booleans("main_component", TwtValidationData::isMainComponent) diff --git a/tests/eurostag-example1_test_regulated_side_null.xiidm b/tests/eurostag-example1_test_regulated_side_null.xiidm new file mode 100644 index 0000000000..de3f0cec20 --- /dev/null +++ b/tests/eurostag-example1_test_regulated_side_null.xiidm @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_loadflow.py b/tests/test_loadflow.py index 5e4feaff66..95bbf74d2d 100644 --- a/tests/test_loadflow.py +++ b/tests/test_loadflow.py @@ -4,7 +4,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # -import unittest +import pathlib import json import pypowsybl as pp @@ -14,6 +14,7 @@ import pytest import pypowsybl.report as rp +TEST_DIR = pathlib.Path(__file__).parent @pytest.fixture(autouse=True) def set_up(): @@ -310,3 +311,10 @@ def test_result_status_as_bool(): n = pp.network.create_ieee14() r = pp.loadflow.run_ac(n) assert r[0].status + + +def test_wrong_regulated_bus_id(): + net = pp.network.load(str(TEST_DIR.joinpath('eurostag-example1_test_regulated_side_null.xiidm'))) + pp.loadflow.run_ac(net) + parameters = lf.ValidationParameters() + validation = pp.loadflow.run_validation(net, validation_parameters=parameters)