Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get element type from a node/breaker topo nodes dataframe #910

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions java/src/main/java/com/powsybl/python/network/Dataframes.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,19 @@ private static List<NodeContext> 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<VoltageLevel.NodeBreakerView, Void> createNodeBreakerViewNodes() {
return new DataframeMapperBuilder<VoltageLevel.NodeBreakerView, NodeContext, Void>()
.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();
}

Expand Down
20 changes: 2 additions & 18 deletions java/src/main/java/com/powsybl/python/network/NodeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <etienne.lesot at rte-france.com>}
*/
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) {
}
3 changes: 2 additions & 1 deletion pypowsybl/network/impl/node_breaker_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading