Skip to content

Commit ab19309

Browse files
Send alert when some voltage levels limits are out of nominal voltage range (#94)
* Send alert when some voltage levels limits are out of nominal voltage range. * Use new powsybl-optimizer release 0.11.0 Signed-off-by: Franck LECUYER <[email protected]>
1 parent 184b1e3 commit ab19309

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
<properties>
5252
<gridsuite-dependencies.version>38.0.0</gridsuite-dependencies.version>
53-
<powsybl-open-reac.version>0.10.0</powsybl-open-reac.version>
53+
<powsybl-open-reac.version>0.11.0</powsybl-open-reac.version>
5454
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
5555
<liquibase-hibernate-package>org.gridsuite.voltageinit.server</liquibase-hibernate-package>
5656
</properties>

src/main/java/org/gridsuite/voltageinit/server/service/VoltageInitWorkerService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.function.Function;
3636
import java.util.stream.Collectors;
3737

38+
import static org.gridsuite.voltageinit.server.util.ReportUtil.checkReportWithKey;
39+
3840

3941
/**
4042
* @author Etienne Homer <etienne.homer at rte-france.com>
@@ -45,6 +47,7 @@ public class VoltageInitWorkerService extends AbstractWorkerService<OpenReacResu
4547
public static final String COMPUTATION_TYPE = "VoltageInit";
4648
public static final String HEADER_REACTIVE_SLACKS_OVER_THRESHOLD = "REACTIVE_SLACKS_OVER_THRESHOLD";
4749
public static final String HEADER_REACTIVE_SLACKS_THRESHOLD_VALUE = "reactiveSlacksThreshold";
50+
public static final String HEADER_VOLTAGE_LEVEL_LIMITS_OUT_OF_NOMINAL_VOLTAGE_RANGE = "VOLTAGE_LEVEL_LIMITS_OUT_OF_NOMINAL_VOLTAGE_RANGE";
4851
private static final Logger LOGGER = LoggerFactory.getLogger(VoltageInitWorkerService.class);
4952

5053
private static final String ERROR = "error";
@@ -82,6 +85,7 @@ private boolean checkReactiveSlacksOverThreshold(OpenReacResult openReacResult,
8285
return openReacResult.getReactiveSlacks().stream().anyMatch(r -> Math.abs(r.slack) > reactiveSlacksThreshold);
8386
}
8487

88+
@Override
8589
protected CompletableFuture<OpenReacResult> getCompletableFuture(VoltageInitRunContext context, String provider, UUID resultUuid) {
8690
OpenReacParameters parameters = voltageInitParametersService.buildOpenReacParameters(context, context.getNetwork());
8791
OpenReacConfig config = OpenReacConfig.load();
@@ -151,9 +155,11 @@ protected void sendResultMessage(AbstractResultContext<VoltageInitRunContext> re
151155
VoltageInitRunContext context = resultContext.getRunContext();
152156
double reactiveSlacksThreshold = voltageInitParametersService.getReactiveSlacksThreshold(context.getParametersUuid());
153157
boolean resultCheckReactiveSlacks = checkReactiveSlacksOverThreshold(result, reactiveSlacksThreshold);
158+
boolean voltageLevelsWithLimitsOutOfNominalVRange = checkReportWithKey("nbVoltageLevelsWithLimitsOutOfNominalVRange", resultContext.getRunContext().getReportNode());
154159
Map<String, Object> additionalHeaders = new HashMap<>();
155160
additionalHeaders.put(HEADER_REACTIVE_SLACKS_OVER_THRESHOLD, resultCheckReactiveSlacks);
156161
additionalHeaders.put(HEADER_REACTIVE_SLACKS_THRESHOLD_VALUE, reactiveSlacksThreshold);
162+
additionalHeaders.put(HEADER_VOLTAGE_LEVEL_LIMITS_OUT_OF_NOMINAL_VOLTAGE_RANGE, voltageLevelsWithLimitsOutOfNominalVRange);
157163
notificationService.sendResultMessage(resultContext.getResultUuid(), context.getReceiver(), context.getUserId(), additionalHeaders);
158164
}
159165

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.voltageinit.server.util;
8+
9+
import com.powsybl.commons.report.ReportNode;
10+
11+
import java.util.Iterator;
12+
13+
/**
14+
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
15+
*/
16+
public final class ReportUtil {
17+
private ReportUtil() {
18+
}
19+
20+
public static boolean checkReportWithKey(String key, ReportNode reportNode) {
21+
if (reportNode.getMessageKey() != null && reportNode.getMessageKey().equals(key)) {
22+
return true;
23+
}
24+
boolean found = false;
25+
Iterator<ReportNode> reportersIterator = reportNode.getChildren().iterator();
26+
while (!found && reportersIterator.hasNext()) {
27+
found = checkReportWithKey(key, reportersIterator.next());
28+
}
29+
return found;
30+
}
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.voltageinit.utils;
8+
9+
import com.powsybl.commons.report.ReportNode;
10+
import org.gridsuite.voltageinit.server.util.ReportUtil;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static org.junit.jupiter.api.Assertions.assertFalse;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
/**
17+
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
18+
*/
19+
class ReportUtilTest {
20+
@Test
21+
void test() {
22+
ReportNode rootNode = ReportNode.newRootReportNode().withMessageTemplate("VoltageInit", "VoltageInit").build();
23+
ReportNode child1Node = rootNode.newReportNode().withMessageTemplate("key1", "template1").add();
24+
ReportNode child2Node = rootNode.newReportNode().withMessageTemplate("key2", "template2").add();
25+
ReportNode child11Node = child1Node.newReportNode().withMessageTemplate("key11", "template11").add();
26+
ReportNode child21Node = child2Node.newReportNode().withMessageTemplate("key21", "template21").add();
27+
ReportNode child22Node = child2Node.newReportNode().withMessageTemplate("key22", "template22").add();
28+
ReportNode child221Node = child22Node.newReportNode().withMessageTemplate("key221", "template221").add();
29+
30+
assertTrue(ReportUtil.checkReportWithKey("VoltageInit", rootNode));
31+
assertFalse(ReportUtil.checkReportWithKey("key", rootNode));
32+
assertTrue(ReportUtil.checkReportWithKey("key221", rootNode));
33+
assertTrue(ReportUtil.checkReportWithKey("key11", child11Node));
34+
assertTrue(ReportUtil.checkReportWithKey("key21", child21Node));
35+
assertTrue(ReportUtil.checkReportWithKey("key221", child22Node));
36+
assertFalse(ReportUtil.checkReportWithKey("key222", child221Node));
37+
}
38+
}

0 commit comments

Comments
 (0)