Skip to content

Commit e0b2dd1

Browse files
committed
Add country unit test reference and fix checkstyle
Signed-off-by: Florian Dupuy <[email protected]>
1 parent de9cca6 commit e0b2dd1

File tree

3 files changed

+103
-40
lines changed

3 files changed

+103
-40
lines changed

network-area-diagram/src/main/java/com/powsybl/nad/build/iidm/CountryGraphBuilder.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public class CountryGraphBuilder implements GraphBuilder {
3434

3535
/**
3636
* Creates a new CountryGraphBuilder.
37-
*
38-
* @param network the network
39-
* @param idProvider the ID provider
37+
*
38+
* @param network the network
39+
* @param idProvider the ID provider
4040
* @param labelProvider the label provider
4141
*/
4242
public CountryGraphBuilder(Network network, IdProvider idProvider, CountryLabelProvider labelProvider) {
@@ -48,50 +48,50 @@ public CountryGraphBuilder(Network network, IdProvider idProvider, CountryLabelP
4848
@Override
4949
public Graph buildGraph() {
5050
Graph graph = new Graph();
51-
51+
5252
// Get all countries from substations
5353
Set<Country> countries = getCountries();
54-
54+
5555
// Create a VoltageLevelNode with one BusNode for each country
5656
Map<Country, VoltageLevelNode> countryToVlNode = new EnumMap<>(Country.class);
5757

5858
for (Country country : countries) {
5959
CountryLabelProvider.CountryLegend legend = labelProvider.getCountryLegend(country);
6060
VoltageLevelNode vlNode = new VoltageLevelNode(
61-
idProvider,
62-
country.name(),
63-
country.name(),
64-
false,
65-
true,
66-
legend.header(),
67-
legend.footer()
61+
idProvider,
62+
country.name(),
63+
country.name(),
64+
false,
65+
true,
66+
legend.header(),
67+
legend.footer()
6868
);
69-
69+
7070
BusNode busNode = new BusNode(idProvider, country.name(), Collections.emptyList(), null);
71-
71+
7272
vlNode.addBusNode(busNode);
7373
graph.addNode(vlNode);
7474
graph.addTextNode(vlNode);
75-
75+
7676
countryToVlNode.put(country, vlNode);
7777
}
78-
78+
7979
// Create edges between countries based on lines
8080
createCountryConnections(graph, countryToVlNode);
81-
81+
8282
return graph;
8383
}
8484

8585
/**
8686
* Gets all countries from substations in the network.
87-
*
87+
*
8888
* @return set of countries
8989
*/
9090
private Set<Country> getCountries() {
9191
return network.getSubstationStream()
92-
.map(Substation::getNullableCountry)
93-
.filter(Objects::nonNull)
94-
.collect(Collectors.toSet());
92+
.map(Substation::getNullableCountry)
93+
.filter(Objects::nonNull)
94+
.collect(Collectors.toSet());
9595
}
9696

9797
/**
@@ -100,9 +100,9 @@ private Set<Country> getCountries() {
100100
* @param graph the graph to add edges to
101101
* @param countryToVlNode mapping from country to voltage level node
102102
*/
103-
private void createCountryConnections(Graph graph,
104-
Map<Country, VoltageLevelNode> countryToVlNode) {
105-
103+
private void createCountryConnections(Graph graph,
104+
Map<Country, VoltageLevelNode> countryToVlNode) {
105+
106106
// Map to store aggregated active powers between countries
107107
Map<Border, BorderEdges> borderEdgesMap = new HashMap<>();
108108

@@ -112,12 +112,12 @@ private void createCountryConnections(Graph graph,
112112

113113
// Process HVDC lines
114114
network.getHvdcLineStream().forEach(hvdcLine -> fillBorderEdgesMap(hvdcLine, borderEdgesMap));
115-
115+
116116
// Create BranchEdges for each country pair with connections
117117
borderEdgesMap.forEach((border, borderEdges) -> {
118118
Country country1 = border.country1();
119119
Country country2 = border.country2();
120-
120+
121121
VoltageLevelNode vlNode1 = countryToVlNode.get(country1);
122122
VoltageLevelNode vlNode2 = countryToVlNode.get(country2);
123123

@@ -133,7 +133,7 @@ private void createCountryConnections(Graph graph,
133133
private void fillBorderEdgesMap(Branch<?> branch, Map<Border, BorderEdges> allBorderLines) {
134134
Country country1 = getCountryFromTerminal(branch.getTerminal1());
135135
Country country2 = getCountryFromTerminal(branch.getTerminal2());
136-
136+
137137
if (country1 != null && country2 != null && country1 != country2) {
138138
Border pair = new Border(country1, country2);
139139
allBorderLines.computeIfAbsent(pair, k -> new BorderEdges())
@@ -147,7 +147,7 @@ private void fillBorderEdgesMap(Branch<?> branch, Map<Border, BorderEdges> allBo
147147
private void fillBorderEdgesMap(HvdcLine hvdcLine, Map<Border, BorderEdges> allBorderLines) {
148148
Country country1 = getCountryFromTerminal(hvdcLine.getConverterStation1().getTerminal());
149149
Country country2 = getCountryFromTerminal(hvdcLine.getConverterStation2().getTerminal());
150-
150+
151151
if (country1 != null && country2 != null && country1 != country2) {
152152
Border pair = new Border(country1, country2);
153153
allBorderLines.computeIfAbsent(pair, k -> new BorderEdges())
@@ -167,22 +167,22 @@ private Country getCountryFromTerminal(Terminal terminal) {
167167
*/
168168
private void createCountryEdge(Graph graph, Country country1, Country country2, BorderEdges borderEdges,
169169
VoltageLevelNode vlNode1, VoltageLevelNode vlNode2) {
170-
170+
171171
String edgeId = country1.name() + "-" + country2.name();
172172
Optional<EdgeInfo> edgeInfo1 = labelProvider.getCountryEdgeInfo(country1, country2, borderEdges.lines, borderEdges.tieLines, borderEdges.hvdcLines, BranchEdge.Side.ONE);
173173
Optional<EdgeInfo> edgeInfo2 = labelProvider.getCountryEdgeInfo(country1, country2, borderEdges.lines, borderEdges.tieLines, borderEdges.hvdcLines, BranchEdge.Side.TWO);
174174
String label = labelProvider.getBranchLabel(country1, country2, borderEdges.lines, borderEdges.tieLines, borderEdges.hvdcLines);
175-
175+
176176
BranchEdge edge = new BranchEdge(
177-
idProvider,
178-
edgeId,
179-
edgeId,
180-
BranchEdge.LINE_EDGE,
181-
edgeInfo1.orElse(null),
182-
edgeInfo2.orElse(null),
183-
label
177+
idProvider,
178+
edgeId,
179+
edgeId,
180+
BranchEdge.LINE_EDGE,
181+
edgeInfo1.orElse(null),
182+
edgeInfo2.orElse(null),
183+
label
184184
);
185-
185+
186186
graph.addEdge(vlNode1, vlNode1.getBusNodes().getFirst(), vlNode2, vlNode2.getBusNodes().getFirst(), edge);
187187
}
188188

network-area-diagram/src/test/java/com/powsybl/nad/CountryDiagramTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import com.google.common.jimfs.Jimfs;
1212
import com.powsybl.iidm.network.Network;
1313
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
14-
import com.powsybl.nad.layout.*;
14+
import com.powsybl.nad.layout.BasicForceLayoutFactory;
15+
import com.powsybl.nad.layout.LayoutFactoryUtils;
16+
import com.powsybl.nad.layout.LayoutParameters;
1517
import com.powsybl.nad.svg.LabelProvider;
1618
import com.powsybl.nad.svg.StyleProvider;
1719
import com.powsybl.nad.svg.SvgParameters;
@@ -62,6 +64,6 @@ void testDrawSvg() {
6264
.setLayoutFactory(LayoutFactoryUtils.create(Path.of("/home/dupuyflo/countries_metadata.json"), new BasicForceLayoutFactory()));
6365
Path svgFile = fileSystem.getPath("countries-test.svg");
6466
CountryDiagram.draw(network, svgFile, nadParameters);
65-
assertFileEquals("/IEEE_14_bus_voltage_filter1.svg", svgFile);
67+
assertFileEquals("/eurostag_country_diagram.svg", svgFile);
6668
}
6769
}
Lines changed: 61 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)