Skip to content

Commit 17f00d4

Browse files
Add logs on voltage limits (#46)
Signed-off-by: Tristan Chuine <[email protected]>
1 parent f10acf8 commit 17f00d4

16 files changed

+1361
-233
lines changed

.mvn/lombok-config-copy.marker

Whitespace-only changes.

lombok.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import target/configs/powsybl-build-tools.jar!powsybl-build-tools/lombok.config

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
*/
77
package org.gridsuite.voltageinit.server.service;
88

9+
import com.powsybl.commons.reporter.Reporter;
10+
import lombok.AllArgsConstructor;
911
import lombok.Getter;
12+
import lombok.Setter;
1013

14+
import java.util.HashMap;
1115
import java.util.Map;
1216
import java.util.Objects;
1317
import java.util.UUID;
1418

1519
/**
1620
* @author Etienne Homer <etienne.homer at rte-france.com>
1721
*/
22+
@AllArgsConstructor
1823
@Getter
1924
public class VoltageInitRunContext {
2025

@@ -36,15 +41,13 @@ public class VoltageInitRunContext {
3641

3742
private final Map<String, Double> voltageLevelsIdsRestricted;
3843

44+
@Setter private Reporter rootReporter;
45+
3946
public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid, Map<String, Double> voltageLevelsIdsRestricted) {
40-
this.networkUuid = Objects.requireNonNull(networkUuid);
41-
this.variantId = variantId;
42-
this.receiver = receiver;
43-
this.reportUuid = reportUuid;
44-
this.reporterId = reporterId;
45-
this.reportType = reportType;
46-
this.userId = userId;
47-
this.parametersUuid = parametersUuid;
48-
this.voltageLevelsIdsRestricted = voltageLevelsIdsRestricted;
47+
this(Objects.requireNonNull(networkUuid), variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, voltageLevelsIdsRestricted, Reporter.NO_OP);
48+
}
49+
50+
public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid) {
51+
this(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, new HashMap<>());
4952
}
5053
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public VoltageInitService(NotificationService notificationService,
5050
}
5151

5252
public UUID runAndSaveResult(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String userId, String reportType, UUID parametersUuid) {
53-
VoltageInitRunContext runContext = new VoltageInitRunContext(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, new HashMap<>());
53+
VoltageInitRunContext runContext = new VoltageInitRunContext(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid);
5454
Objects.requireNonNull(runContext);
5555
var resultUuid = uuidGeneratorService.generate();
5656

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
import com.google.common.collect.Sets;
1010
import com.powsybl.commons.PowsyblException;
11-
import com.powsybl.commons.reporter.Report;
1211
import com.powsybl.commons.reporter.Reporter;
1312
import com.powsybl.commons.reporter.ReporterModel;
14-
import com.powsybl.commons.reporter.TypedValue;
1513
import com.powsybl.iidm.network.Bus;
1614
import com.powsybl.iidm.network.Network;
1715
import com.powsybl.iidm.network.VariantManagerConstants;
@@ -113,21 +111,6 @@ private Network getNetwork(UUID networkUuid, String variantId) {
113111
return network;
114112
}
115113

116-
public static void addRestrictedVoltageLevelReport(Map<String, Double> voltageLevelsIdsRestricted, Reporter reporter) {
117-
if (!voltageLevelsIdsRestricted.isEmpty()) {
118-
String joinedVoltageLevelsIds = voltageLevelsIdsRestricted.entrySet()
119-
.stream()
120-
.map(entry -> entry.getKey() + " : " + entry.getValue())
121-
.collect(Collectors.joining(", "));
122-
123-
reporter.report(Report.builder()
124-
.withKey("restrictedVoltageLevels")
125-
.withDefaultMessage(String.format("The modifications to the low limits for certain voltage levels have been restricted to avoid negative voltage limits: %s", joinedVoltageLevelsIds))
126-
.withSeverity(TypedValue.WARN_SEVERITY)
127-
.build());
128-
}
129-
}
130-
131114
private Pair<Network, OpenReacResult> run(VoltageInitRunContext context, UUID resultUuid) throws Exception {
132115
Objects.requireNonNull(context);
133116

@@ -136,18 +119,16 @@ private Pair<Network, OpenReacResult> run(VoltageInitRunContext context, UUID re
136119
getNetwork(context.getNetworkUuid(), context.getVariantId()));
137120

138121
AtomicReference<Reporter> rootReporter = new AtomicReference<>(Reporter.NO_OP);
139-
Reporter reporter = Reporter.NO_OP;
140122
if (context.getReportUuid() != null) {
141123
String rootReporterId = context.getReporterId() == null ? VOLTAGE_INIT_TYPE_REPORT : context.getReporterId() + "@" + context.getReportType();
142124
rootReporter.set(new ReporterModel(rootReporterId, rootReporterId));
143-
reporter = rootReporter.get().createSubReporter(context.getReportType(), VOLTAGE_INIT_TYPE_REPORT, VOLTAGE_INIT_TYPE_REPORT, context.getReportUuid().toString());
125+
context.setRootReporter(rootReporter.get().createSubReporter(context.getReportType(), VOLTAGE_INIT_TYPE_REPORT, VOLTAGE_INIT_TYPE_REPORT, context.getReportUuid().toString()));
144126
// Delete any previous VoltageInit computation logs
145127
voltageInitObserver.observe("report.delete", () ->
146128
reportService.deleteReport(context.getReportUuid(), context.getReportType()));
147129
}
148130
CompletableFuture<OpenReacResult> future = runVoltageInitAsync(context, network, resultUuid);
149131
if (context.getReportUuid() != null) {
150-
addRestrictedVoltageLevelReport(context.getVoltageLevelsIdsRestricted(), reporter);
151132
voltageInitObserver.observe("report.send", () ->
152133
reportService.sendReport(context.getReportUuid(), rootReporter.get()));
153134
}

0 commit comments

Comments
 (0)