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 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public abstract class AbstractNode extends AbstractIdentifiable implements Node
private int width;
private int height;
private Point position;
private final boolean fictitious;

protected AbstractNode(String diagramId, String equipmentId, String name) {
protected AbstractNode(String diagramId, String equipmentId, String name, boolean fictitious) {
super(diagramId, equipmentId, name);
position = new Point();
width = 0;
height = 0;
this.fictitious = fictitious;
}

@Override
Expand Down Expand Up @@ -47,6 +49,11 @@ public double getY() {
return position.getY();
}

@Override
public boolean isFictitious() {
return fictitious;
}

public int getWidth() {
return width;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BusNode extends AbstractNode {
private int nbNeighbouringBusNodes;

public BusNode(String diagramId, String id) {
super(diagramId, id, null);
super(diagramId, id, null, false);
}

public void setRingIndex(int ringIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface Node extends Identifiable {
double getX();

double getY();

boolean isFictitious();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TextNode extends AbstractNode {
private Point edgeConnection;

public TextNode(String diagramId) {
super(diagramId, null, null);
super(diagramId, null, null, false);
edgeConnection = new Point();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ThreeWtNode extends AbstractNode {

public ThreeWtNode(String diagramId, String equipmentId, String nameOrId) {
super(diagramId, equipmentId, nameOrId);
super(diagramId, equipmentId, nameOrId, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public class VoltageLevelNode extends AbstractNode {

private final List<BusNode> busNodes = new ArrayList<>();
private final boolean fictitious;
private final boolean visible;
private boolean hasUnknownBusNode = false;

Expand All @@ -24,8 +23,7 @@ public VoltageLevelNode(String diagramId, String equipmentId, String nameOrId, b
}

public VoltageLevelNode(String diagramId, String equipmentId, String nameOrId, boolean fictitious, boolean visible) {
super(diagramId, equipmentId, nameOrId);
this.fictitious = fictitious;
super(diagramId, equipmentId, nameOrId, fictitious);
this.visible = visible;
}

Expand Down Expand Up @@ -57,8 +55,4 @@ public void setHasUnknownBusNode(boolean hasUnknownBusNode) {
public boolean hasUnknownBusNode() {
return hasUnknownBusNode;
}

public boolean isFictitious() {
return fictitious;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public DiagramMetadata addMetadata(Graph graph) {
getPrefixedId(node.getDiagramId()),
node.getEquipmentId(),
round(node.getX()),
round(node.getY()))));
round(node.getY()),
node.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,9 @@ public double getX() {
public double getY() {
return y;
}

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public boolean isFictitious() {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
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
Loading
Loading