From bbc482945f997cfc012e6cefd5f66a6bdcb5da44 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Mon, 9 Dec 2024 16:55:00 +0100 Subject: [PATCH] Get element type from a node/breaker topo nodes dataframe Signed-off-by: Geoffroy Jamgotchian --- .../powsybl/python/network/Dataframes.java | 11 +++++----- .../powsybl/python/network/NodeContext.java | 20 ++----------------- .../network/impl/node_breaker_topology.py | 3 ++- tests/test_network.py | 2 ++ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/java/src/main/java/com/powsybl/python/network/Dataframes.java b/java/src/main/java/com/powsybl/python/network/Dataframes.java index 1430a3124d..fb89d76296 100644 --- a/java/src/main/java/com/powsybl/python/network/Dataframes.java +++ b/java/src/main/java/com/powsybl/python/network/Dataframes.java @@ -310,18 +310,19 @@ private static List getNodeBreakerViewNodes(VoltageLevel.NodeBreake return nodes.stream().map(node -> { Terminal terminal = nodeBreakerView.getTerminal(node); if (terminal == null) { - return new NodeContext(node, null); + return new NodeContext(node, null, null); } else { - return new NodeContext(node, terminal.getConnectable().getId()); + return new NodeContext(node, terminal.getConnectable().getId(), terminal.getConnectable().getType()); } - }).collect(Collectors.toList()); + }).toList(); } private static DataframeMapper createNodeBreakerViewNodes() { return new DataframeMapperBuilder() .itemsProvider(Dataframes::getNodeBreakerViewNodes) - .intsIndex("node", NodeContext::getNode) - .strings("connectable_id", node -> Objects.toString(node.getConnectableId(), "")) + .intsIndex("node", NodeContext::node) + .strings("connectable_id", node -> Objects.toString(node.connectableId(), "")) + .strings("connectable_type", node -> Objects.toString(node.connectableType(), "")) .build(); } diff --git a/java/src/main/java/com/powsybl/python/network/NodeContext.java b/java/src/main/java/com/powsybl/python/network/NodeContext.java index fae0bea185..19ff5d4b5d 100644 --- a/java/src/main/java/com/powsybl/python/network/NodeContext.java +++ b/java/src/main/java/com/powsybl/python/network/NodeContext.java @@ -7,26 +7,10 @@ */ package com.powsybl.python.network; -import javax.annotation.Nullable; -import java.util.Objects; +import com.powsybl.iidm.network.IdentifiableType; /** * @author Etienne Lesot {@literal } */ -public class NodeContext { - private final int node; - private final String connectableId; - - public NodeContext(int node, @Nullable String connectableId) { - this.node = Objects.requireNonNull(node); - this.connectableId = connectableId; - } - - public int getNode() { - return node; - } - - public String getConnectableId() { - return connectableId; - } +public record NodeContext(int node, String connectableId, IdentifiableType connectableType) { } diff --git a/pypowsybl/network/impl/node_breaker_topology.py b/pypowsybl/network/impl/node_breaker_topology.py index a423929d65..56a25e5866 100644 --- a/pypowsybl/network/impl/node_breaker_topology.py +++ b/pypowsybl/network/impl/node_breaker_topology.py @@ -53,7 +53,8 @@ def nodes(self) -> DataFrame: The dataframe includes the following columns: - - **connectable_id**: Connected element, if any. + - **connectable_id**: Connected element ID, if any. + - **connectable_type**: Connected element type, if any. This dataframe is indexed by the id of the nodes. """ diff --git a/tests/test_network.py b/tests/test_network.py index 74a56861be..ffa99136f4 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -1539,6 +1539,8 @@ def test_node_breaker_view(): assert 0 == switches.loc['S4VL1_BBS_LINES3S4_DISCONNECTOR']['node1'] assert 5 == switches.loc['S4VL1_BBS_LINES3S4_DISCONNECTOR']['node2'] assert 7 == len(nodes) + assert 'S4VL1_BBS' == nodes.iloc[0]['connectable_id'] + assert 'BUSBAR_SECTION' == nodes.iloc[0]['connectable_type'] assert topology.internal_connections.empty with pytest.raises(PyPowsyblError) as exc: