Skip to content

Commit 3472797

Browse files
authored
add isBusbarSectionPositionFound (#279)
Signed-off-by: Rehili Ghazwa <[email protected]>
1 parent 94ec2cd commit 3472797

12 files changed

+135
-34
lines changed

src/main/java/org/gridsuite/network/map/dto/definition/voltagelevel/VoltageLevelFormInfos.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class VoltageLevelFormInfos extends ElementInfosWithProperties {
5454
@JsonInclude(JsonInclude.Include.NON_NULL)
5555
private Boolean isRetrievedBusbarSections;
5656

57+
@JsonInclude(JsonInclude.Include.NON_NULL)
58+
private Boolean isBusbarSectionPositionFound;
59+
5760
@JsonInclude(JsonInclude.Include.NON_NULL)
5861
private Map<String, List<String>> busBarSectionInfos;
5962
}

src/main/java/org/gridsuite/network/map/dto/mapper/VoltageLevelInfosMapper.java

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.powsybl.iidm.network.*;
1010
import com.powsybl.iidm.network.extensions.BusbarSectionPosition;
11+
import lombok.Builder;
1112
import lombok.Getter;
1213
import lombok.Setter;
1314
import org.gridsuite.network.map.dto.ElementInfos;
@@ -42,41 +43,48 @@ public static ElementInfos toData(Identifiable<?> identifiable, InfoTypeParamete
4243
}
4344

4445
private static VoltageLevelTopologyInfos getTopologyInfos(VoltageLevel voltageLevel) {
45-
VoltageLevelTopologyInfos topologyInfos = new VoltageLevelTopologyInfos();
4646
Map<Integer, Integer> nbSectionsPerBusbar = new HashMap<>();
4747
List<BusBarSectionFormInfos> busbarSectionInfos = new ArrayList<>();
48+
int maxBusbarIndex = 1;
49+
int maxSectionIndex = 1;
50+
boolean busbarSectionPositionFound = true;
4851
for (BusbarSection bbs : voltageLevel.getNodeBreakerView().getBusbarSections()) {
4952
var extension = bbs.getExtension(BusbarSectionPosition.class);
50-
if (extension != null) {
51-
if (extension.getBusbarIndex() > topologyInfos.getBusbarCount()) {
52-
topologyInfos.setBusbarCount(extension.getBusbarIndex());
53-
}
54-
if (extension.getSectionIndex() > topologyInfos.getSectionCount()) {
55-
topologyInfos.setSectionCount(extension.getSectionIndex());
56-
}
57-
nbSectionsPerBusbar.putIfAbsent(extension.getBusbarIndex(), 1);
58-
if (extension.getSectionIndex() > nbSectionsPerBusbar.get(extension.getBusbarIndex())) {
59-
nbSectionsPerBusbar.put(extension.getBusbarIndex(), extension.getSectionIndex());
60-
}
61-
BusBarSectionFormInfos busbarSectionInfo = BusBarSectionFormInfos.builder()
62-
.id(bbs.getId())
63-
.vertPos(extension.getSectionIndex())
64-
.horizPos(extension.getBusbarIndex())
65-
.build();
66-
busbarSectionInfos.add(busbarSectionInfo);
67-
} else {
68-
return new VoltageLevelTopologyInfos();
53+
if (extension == null) {
54+
busbarSectionPositionFound = false;
55+
break;
6956
}
57+
int busbarIndex = extension.getBusbarIndex();
58+
int sectionIndex = extension.getSectionIndex();
59+
maxBusbarIndex = Math.max(maxBusbarIndex, busbarIndex);
60+
maxSectionIndex = Math.max(maxSectionIndex, sectionIndex);
61+
nbSectionsPerBusbar.merge(busbarIndex, sectionIndex, Math::max);
62+
busbarSectionInfos.add(BusBarSectionFormInfos.builder()
63+
.id(bbs.getId())
64+
.vertPos(sectionIndex)
65+
.horizPos(busbarIndex)
66+
.build());
7067
}
71-
if (nbSectionsPerBusbar.values().stream().anyMatch(v -> v != topologyInfos.getSectionCount())) { // Non-symmetrical busbars (nb sections)
72-
return new VoltageLevelTopologyInfos();
68+
VoltageLevelTopologyInfos voltageLevelTopologyInfos = createDefaultTopologyInfosBuilder().build();
69+
if (!busbarSectionPositionFound) {
70+
return voltageLevelTopologyInfos;
7371
}
7472

75-
topologyInfos.setRetrievedBusbarSections(true);
76-
topologyInfos.setSwitchKinds(Collections.nCopies(topologyInfos.getSectionCount() - 1, SwitchKind.DISCONNECTOR));
77-
topologyInfos.setBusbarSections(busbarSectionInfos);
73+
voltageLevelTopologyInfos.setBusbarSections(busbarSectionInfos);
74+
voltageLevelTopologyInfos.setBusbarSectionPositionFound(true);
7875

79-
return topologyInfos;
76+
int finalMaxSectionIndex = maxSectionIndex;
77+
boolean isSymmetrical = nbSectionsPerBusbar.values()
78+
.stream()
79+
.allMatch(v -> v == finalMaxSectionIndex);
80+
81+
if (isSymmetrical) {
82+
voltageLevelTopologyInfos.setBusbarCount(maxBusbarIndex);
83+
voltageLevelTopologyInfos.setSectionCount(maxSectionIndex);
84+
voltageLevelTopologyInfos.setRetrievedBusbarSections(true);
85+
voltageLevelTopologyInfos.setSwitchKinds(Collections.nCopies(maxSectionIndex - 1, SwitchKind.DISCONNECTOR));
86+
}
87+
return voltageLevelTopologyInfos;
8088
}
8189

8290
static VoltageLevelFormInfos toFormInfos(Identifiable<?> identifiable) {
@@ -97,6 +105,7 @@ static VoltageLevelFormInfos toFormInfos(Identifiable<?> identifiable) {
97105
builder.sectionCount(vlTopologyInfos.getSectionCount());
98106
builder.switchKinds(vlTopologyInfos.getSwitchKinds());
99107
builder.isRetrievedBusbarSections(vlTopologyInfos.isRetrievedBusbarSections());
108+
builder.isBusbarSectionPositionFound(vlTopologyInfos.isBusbarSectionPositionFound());
100109
builder.busBarSectionInfos(vlTopologyInfos.getBusBarSectionInfosGrouped());
101110
}
102111

@@ -133,14 +142,22 @@ static VoltageLevelTabInfos toTabInfos(Identifiable<?> identifiable) {
133142
return builder.build();
134143
}
135144

145+
private static VoltageLevelTopologyInfos.VoltageLevelTopologyInfosBuilder createDefaultTopologyInfosBuilder() {
146+
return VoltageLevelTopologyInfos.builder()
147+
.busbarCount(1).sectionCount(1).isRetrievedBusbarSections(false)
148+
.switchKinds(List.of()).busbarSections(List.of()).isBusbarSectionPositionFound(false);
149+
}
150+
151+
@Builder
136152
@Getter
137153
@Setter
138154
public static class VoltageLevelTopologyInfos {
139-
private List<BusBarSectionFormInfos> busbarSections = List.of();
140-
private boolean isRetrievedBusbarSections = false;
141-
private int busbarCount = 1;
142-
private int sectionCount = 1;
143-
private List<SwitchKind> switchKinds = List.of();
155+
private List<BusBarSectionFormInfos> busbarSections;
156+
private boolean isRetrievedBusbarSections; // true if busbar sections are symmetrical
157+
private boolean isBusbarSectionPositionFound;
158+
private int busbarCount;
159+
private int sectionCount;
160+
private List<SwitchKind> switchKinds;
144161

145162
public Map<String, List<String>> getBusBarSectionInfosGrouped() {
146163
return busbarSections.stream()

src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,23 @@ void setUp() {
10551055
.add();
10561056
bbs1.newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.FORCED_OUTAGE).add();
10571057
vlgen5.newExtension(IdentifiableShortCircuitAdder.class).withIpMin(0.0).withIpMax(100.0).add();
1058+
vlgen5.getNodeBreakerView()
1059+
.getBusbarSection("NGEN5")
1060+
.newExtension(BusbarSectionPositionAdder.class)
1061+
.withBusbarIndex(1)
1062+
.withSectionIndex(2)
1063+
.add();
1064+
vlgen5.getNodeBreakerView().newBusbarSection()
1065+
.setId("NGEN5_2")
1066+
.setName("NGEN5_2")
1067+
.setNode(1)
1068+
.add();
1069+
vlgen5.getNodeBreakerView()
1070+
.getBusbarSection("NGEN5_2")
1071+
.newExtension(BusbarSectionPositionAdder.class)
1072+
.withBusbarIndex(2)
1073+
.withSectionIndex(1)
1074+
.add();
10581075

10591076
// Create a connected shunt compensator on a NODE_BREAKER voltage level
10601077
ShuntCompensator shunt4 = vlgen4.newShuntCompensator().setId("SHUNT_VLNB")
@@ -2198,6 +2215,12 @@ void shouldReturnVotlageLevelFormData() throws Exception {
21982215
succeedingTestForElementInfosWithElementId(NETWORK_UUID, VARIANT_ID, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN4", resourceToString("/voltage-level-form-data.json"));
21992216
}
22002217

2218+
@Test
2219+
void shouldReturnVotlageLevelNonSymmetricalBusbarsFormData() throws Exception {
2220+
succeedingTestForElementInfosWithElementId(NETWORK_UUID, null, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-non-symmetrical-busbars-form-data.json"));
2221+
succeedingTestForElementInfosWithElementId(NETWORK_UUID, VARIANT_ID, ElementType.VOLTAGE_LEVEL, InfoType.FORM, "VLGEN5", resourceToString("/voltage-level-non-symmetrical-busbars-form-data.json"));
2222+
}
2223+
22012224
@Test
22022225
void shouldReturnVotlageLevelTabData() throws Exception {
22032226
succeedingTestForElementInfosWithElementId(NETWORK_UUID, null, ElementType.VOLTAGE_LEVEL, InfoType.TAB, "VLGEN4", resourceToString("/voltage-level-tab-data.json"));

src/test/resources/all-data-in-variant.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,11 @@
23272327
"id": "NGEN5",
23282328
"name": "NGEN5",
23292329
"voltageLevelId": "VLGEN5"
2330+
},
2331+
{
2332+
"id": "NGEN5_2",
2333+
"name": "NGEN5_2",
2334+
"voltageLevelId": "VLGEN5"
23302335
}
23312336
]
23322337
}

src/test/resources/all-data.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,11 @@
23092309
"id": "NGEN5",
23102310
"name": "NGEN5",
23112311
"voltageLevelId": "VLGEN5"
2312+
},
2313+
{
2314+
"id": "NGEN5_2",
2315+
"name": "NGEN5_2",
2316+
"voltageLevelId": "VLGEN5"
23122317
}
23132318
]
23142319
}

src/test/resources/bus-bar-section-form-data.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
},
88
{
99
"id": "NGEN5",
10-
"name": "NGEN5"
10+
"name": "NGEN5",
11+
"vertPos": 1,
12+
"horizPos": 2
13+
},
14+
{
15+
"id": "NGEN5_2",
16+
"name": "NGEN5_2",
17+
"vertPos": 2,
18+
"horizPos": 1
1119
}
1220
]

src/test/resources/bus-bar-section-list-data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
{
77
"id": "NGEN5",
88
"name": "NGEN5"
9+
},
10+
{
11+
"id": "NGEN5_2",
12+
"name": "NGEN5_2"
913
}
1014
]

src/test/resources/bus-bar-section-operating-status-data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
"id": "NGEN5",
88
"name": "NGEN5",
99
"operatingStatus": "FORCED_OUTAGE"
10+
},
11+
{
12+
"id": "NGEN5_2",
13+
"name": "NGEN5_2"
1014
}
1115
]

src/test/resources/substations-form-data.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"DISCONNECTOR"
105105
],
106106
"isRetrievedBusbarSections": true,
107+
"isBusbarSectionPositionFound": true,
107108
"busBarSectionInfos" : {
108109
"1" : ["NGEN4"]
109110
}
@@ -129,7 +130,11 @@
129130
"sectionCount": 1,
130131
"switchKinds": [],
131132
"isRetrievedBusbarSections": false,
132-
"busBarSectionInfos" : { }
133+
"isBusbarSectionPositionFound": true,
134+
"busBarSectionInfos" : {
135+
"1" : [ "NGEN5"],
136+
"2" : [ "NGEN5_2"]
137+
}
133138
}
134139
]
135140
}

src/test/resources/voltage-level-form-data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"sectionCount": 2,
88
"switchKinds": ["DISCONNECTOR"],
99
"isRetrievedBusbarSections": true,
10+
"isBusbarSectionPositionFound": true,
1011
"busBarSectionInfos" : {
1112
"1" : [ "NGEN4"]
1213
}

0 commit comments

Comments
 (0)