Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Filter with list of voltage levels and depth (#53)
Browse files Browse the repository at this point in the history
* Create new API for list of voltage levels and depth
* Add unit tests

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup authored Feb 17, 2022
1 parent 219db50 commit 16a166e
Show file tree
Hide file tree
Showing 5 changed files with 972 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/com/powsybl/nad/NetworkAreaDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

Expand All @@ -44,6 +45,14 @@ public NetworkAreaDiagram(Network network, String voltageLevelId, int depth) {
this(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth));
}

public NetworkAreaDiagram(Network network, List<String> voltageLevelIds) {
this(network, VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds));
}

public NetworkAreaDiagram(Network network, List<String> voltageLevelIds, int depth) {
this(network, VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth));
}

public NetworkAreaDiagram(Network network, Predicate<VoltageLevel> voltageLevelFilter) {
this.network = Objects.requireNonNull(network);
this.voltageLevelFilter = Objects.requireNonNull(voltageLevelFilter);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.nad.utils.iidm.IidmUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
Expand Down Expand Up @@ -49,6 +50,27 @@ public static VoltageLevelFilter createVoltageLevelDepthFilter(Network network,
return new VoltageLevelFilter(voltageLevels);
}

public static VoltageLevelFilter createVoltageLevelsDepthFilter(Network network, List<String> voltageLevelIds, int depth) {
Objects.requireNonNull(network);
Objects.requireNonNull(voltageLevelIds);
Set<VoltageLevel> startingSet = new HashSet<>();
for (String voltageLevelId : voltageLevelIds) {
VoltageLevel vl = network.getVoltageLevel(voltageLevelId);
if (vl == null) {
throw new PowsyblException("Unknown voltage level id '" + voltageLevelId + "'");
}
startingSet.add(vl);
}

Set<VoltageLevel> voltageLevels = new HashSet<>();
traverseVoltageLevels(startingSet, depth, voltageLevels);
return new VoltageLevelFilter(voltageLevels);
}

public static VoltageLevelFilter createVoltageLevelsFilter(Network network, List<String> voltageLevelIds) {
return createVoltageLevelsDepthFilter(network, voltageLevelIds, 0);
}

private static void traverseVoltageLevels(Set<VoltageLevel> voltageLevelsDepth, int depth, Set<VoltageLevel> visitedVoltageLevels) {
if (depth < 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
Expand Down Expand Up @@ -129,7 +131,7 @@ void test3wt() {
@Test
void testPartial3wt() {
Network network = ThreeWindingsTransformerNetworkFactory.create();
VoltageLevelFilter filter = VoltageLevelFilter.createVoltageLevelDepthFilter(network, "VL_11", 0);
VoltageLevelFilter filter = VoltageLevelFilter.createVoltageLevelsFilter(network, Collections.singletonList("VL_11"));
assertEquals(toString("/3wt_partial.svg"), generateSvgString(network, filter, "/3wt_partial.svg"));
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/powsybl/nad/svg/TopologicalStyleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
Expand Down Expand Up @@ -71,4 +73,11 @@ void testIEEE118PartialGraph() {
VoltageLevelFilter vlDepthFilter = VoltageLevelFilter.createVoltageLevelDepthFilter(network, "VL54", 2);
assertEquals(toString("/IEEE_118_bus_partial.svg"), generateSvgString(network, vlDepthFilter, "/IEEE_118_bus_partial.svg"));
}

@Test
void testIEEE118PartialNonConnectedGraph() {
Network network = IeeeCdfNetworkFactory.create118();
VoltageLevelFilter vlDepthFilter = VoltageLevelFilter.createVoltageLevelsDepthFilter(network, Arrays.asList("VL32", "VL38"), 1);
assertEquals(toString("/IEEE_118_bus_partial_non_connected.svg"), generateSvgString(network, vlDepthFilter, "/IEEE_118_bus_partial_non_connected.svg"));
}
}
Loading

0 comments on commit 16a166e

Please sign in to comment.