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

Add fictitious flag to node metadata in network area diagram #663

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.powsybl.diagram.metadata.AbstractMetadata;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.model.Graph;
import com.powsybl.nad.model.VoltageLevelNode;
import com.powsybl.nad.svg.SvgParameters;

/**
Expand Down Expand Up @@ -107,7 +108,8 @@ public DiagramMetadata addMetadata(Graph graph) {
getPrefixedId(node.getDiagramId()),
node.getEquipmentId(),
round(node.getX()),
round(node.getY()))));
round(node.getY()),
node instanceof VoltageLevelNode vlNode && vlNode.isFictitious())));
graph.getBranchEdgeStream().forEach(edge -> edgesMetadata.add(new EdgeMetadata(
getPrefixedId(edge.getDiagramId()),
edge.getEquipmentId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ public class NodeMetadata extends AbstractMetadataItem {

private final double x;
private final double y;
private final boolean fictitious;

public NodeMetadata(@JsonProperty("svgId") String svgId,
@JsonProperty("equipmentId") String equipmentId,
@JsonProperty("x") double x,
@JsonProperty("y") double y) {
@JsonProperty("y") double y,
@JsonProperty("fictitious") boolean fictitious) {
super(svgId, equipmentId);
this.x = x;
this.y = y;
this.fictitious = fictitious;
}

public double getX() {
Expand All @@ -35,4 +38,8 @@ public double getX() {
public double getY() {
return y;
}

public boolean isFictitious() {
return fictitious;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory;
import com.powsybl.nad.AbstractTest;
Expand Down Expand Up @@ -86,12 +87,22 @@ void test() {

@Test
void test3wt() {
// Referenced json file
String referenceMetadata = "/3wt_metadata.json";
// Write Metadata as temporary json file
Network network = ThreeWindingsTransformerNetworkFactory.create();
testMetadata(network, "/3wt_metadata.json", 3, 4, 3, 3);
}

@Test
void testFictitious() {
Network network = IeeeCdfNetworkFactory.create14();
network.getVoltageLevel("VL12").setFictitious(true);
network.getVoltageLevel("VL14").setFictitious(true);
testMetadata(network, "/IEEE_14_bus_fictitious_metadata.json", 14, 14, 20, 14);
}

private void testMetadata(Network network, String referenceMetadata, int busNodesNumber, int nodesNumber, int edgesNumber, int textNodesNumber) {
Graph graph = new NetworkGraphBuilder(network, VoltageLevelFilter.NO_FILTER).buildGraph();
new BasicForceLayout().run(graph, getLayoutParameters());
// Write Metadata as temporary json file
Path outMetadataPath = tmpDir.resolve("metadata.json");
new DiagramMetadata(getLayoutParameters(), getSvgParameters()).addMetadata(graph).writeJson(outMetadataPath);
// Read generated json file
Expand All @@ -102,10 +113,11 @@ void test3wt() {
assertEquals(expected, actual);
// Read metadata from file
DiagramMetadata diagramMetadata = DiagramMetadata.parseJson(outMetadataPath);
assertEquals(3, diagramMetadata.getBusNodesMetadata().size());
assertEquals(4, diagramMetadata.getNodesMetadata().size());
assertEquals(3, diagramMetadata.getEdgesMetadata().size());
assertEquals(3, diagramMetadata.getTextNodesMetadata().size());
// Check read metadata
assertEquals(busNodesNumber, diagramMetadata.getBusNodesMetadata().size());
assertEquals(nodesNumber, diagramMetadata.getNodesMetadata().size());
assertEquals(edgesNumber, diagramMetadata.getEdgesMetadata().size());
assertEquals(textNodesNumber, diagramMetadata.getTextNodesMetadata().size());
}

private void writeMetadata(DiagramMetadata metadata, Path outPath) {
Expand Down
12 changes: 8 additions & 4 deletions network-area-diagram/src/test/resources/3wt_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,26 @@
"svgId" : "0",
"equipmentId" : "VL_11",
"x" : 75.04,
"y" : -513.76
"y" : -513.76,
"fictitious" : false
}, {
"svgId" : "2",
"equipmentId" : "VL_132",
"x" : -371.52,
"y" : 47.69
"y" : 47.69,
"fictitious" : false
}, {
"svgId" : "4",
"equipmentId" : "VL_33",
"x" : 180.23,
"y" : 204.68
"y" : 204.68,
"fictitious" : false
}, {
"svgId" : "6",
"equipmentId" : "3WT",
"x" : -22.79,
"y" : -128.62
"y" : -128.62,
"fictitious" : false
} ],
"edges" : [ {
"svgId" : "7",
Expand Down
Loading
Loading