Skip to content

Commit 938b5e9

Browse files
Fix #136 (#141)
1 parent 72001ec commit 938b5e9

File tree

11 files changed

+608
-125
lines changed

11 files changed

+608
-125
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.gridsuite.shortcircuit.server.report;
2+
3+
import com.powsybl.commons.report.TypedValue;
4+
import org.gridsuite.shortcircuit.server.report.mappers.AdnSummarizeMapper;
5+
import org.gridsuite.shortcircuit.server.report.mappers.SeverityMapper;
6+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
/**
11+
* Just initialize all the mappers
12+
*/
13+
@Configuration
14+
public class MapperBeans {
15+
@Bean
16+
public SeverityMapper powsyblAdnGeneratorsAndBatteriesSeverity() {
17+
// in generatorConversion and batteryConversion
18+
return new SeverityMapper("disconnectedTerminalGenerator", TypedValue.TRACE_SEVERITY);
19+
}
20+
21+
@Bean
22+
public SeverityMapper powsyblAdnLinesSeverity() {
23+
// in branchConversion.twoWindingsTransformerConversion
24+
return new SeverityMapper("lineConversion", "addConstantRatio", TypedValue.TRACE_SEVERITY);
25+
}
26+
27+
@Bean
28+
public SeverityMapper powsyblAdnTwoWindingsTransformersSeverity() {
29+
// in branchConversion.twoWindingsTransformerConversion
30+
return new SeverityMapper("twoWindingsTransformerConversion", "addConstantRatio", TypedValue.TRACE_SEVERITY);
31+
}
32+
33+
@Bean
34+
public AdnSummarizeMapper powsyblAdnGeneratorsSummary() {
35+
return new AdnSummarizeMapper("generators",
36+
"generatorConversion",
37+
"disconnectedTerminalGenerator",
38+
"shortcircuit.server.disconnectedTerminalEquipmentSummary",
39+
ShortCircuitRunContext::getAdnSummarizeCounterGenerator);
40+
}
41+
42+
@Bean
43+
public AdnSummarizeMapper powsyblAdnBatteriesSummary() {
44+
return new AdnSummarizeMapper("batteries",
45+
"batteryConversion",
46+
"disconnectedTerminalGenerator",
47+
"shortcircuit.server.disconnectedTerminalEquipmentSummary",
48+
ShortCircuitRunContext::getAdnSummarizeCounterBattery);
49+
}
50+
51+
@Bean
52+
public AdnSummarizeMapper powsyblAdnLinesSummary() {
53+
// in branchConversion.twoWindingsTransformerConversion
54+
return new AdnSummarizeMapper("lines",
55+
"lineConversion",
56+
"addConstantRatio",
57+
"shortcircuit.server.addConstantRatioSummary",
58+
ShortCircuitRunContext::getAdnSummarizeCounterLines);
59+
}
60+
61+
@Bean
62+
public AdnSummarizeMapper powsyblAdnTwoWindingsTransformersSummary() {
63+
// in branchConversion.twoWindingsTransformerConversion
64+
return new AdnSummarizeMapper("two windings transformers",
65+
"twoWindingsTransformerConversion",
66+
"addConstantRatio",
67+
"shortcircuit.server.addConstantRatioSummary",
68+
ShortCircuitRunContext::getAdnSummarizeCounterT2W);
69+
}
70+
71+
/* There is also possibly adn nodes:
72+
* branchConversion.twoWindingsTransformerConversion
73+
* branchConversion.threeWindingsTransformerConversion
74+
* branchConversion.lineConversion
75+
* branchConversion.tieLineConversion
76+
* danglinglinesConversion
77+
*/
78+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.gridsuite.shortcircuit.server.report.mappers;
2+
3+
import com.powsybl.commons.report.ReportNode;
4+
import com.powsybl.commons.report.TypedValue;
5+
import lombok.Data;
6+
import lombok.NonNull;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.apache.commons.lang3.mutable.MutableLong;
9+
import org.gridsuite.shortcircuit.server.report.ReportMapper;
10+
import org.gridsuite.shortcircuit.server.report.ShortcircuitServerReportResourceBundle;
11+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
12+
13+
import java.util.function.Function;
14+
15+
/**
16+
* Insert a summarized log line for some of the verbose ADN logs.
17+
*
18+
* @see com.rte_france.powsybl.iidm.export.adn.ADNHelper
19+
* @see com.rte_france.powsybl.iidm.export.adn.BranchHelper
20+
*/
21+
@Slf4j
22+
@Data
23+
public class AdnSummarizeMapper implements ReportMapper {
24+
@NonNull private final String equipmentsLabel;
25+
@NonNull private final String parentMessageKey; //"Conversion of ..."
26+
@NonNull private final String toSummarizeMessageKey;
27+
@NonNull private final String summaryMessageKey;
28+
@NonNull private final Function<ShortCircuitRunContext, MutableLong> logsToSummarizeCountGetter; // =0L
29+
30+
/** {@inheritDoc} */
31+
@Override
32+
public void transformNode(final @NonNull ReportNode node, @NonNull final ShortCircuitRunContext context) {
33+
if (this.parentMessageKey.equals(node.getMessageKey())) {
34+
log.debug("ADN logs node for {} detected, will analyse them...", this.equipmentsLabel);
35+
for (final ReportNode child : node.getChildren()) {
36+
if (this.toSummarizeMessageKey.equals(child.getMessageKey())) {
37+
this.logsToSummarizeCountGetter.apply(context).increment();
38+
}
39+
}
40+
/* finalize computation of summaries */
41+
final long logsToSummarizeCount = this.logsToSummarizeCountGetter.apply(context).longValue();
42+
log.debug("Found {} lines in shortcircuit logs matching {}", logsToSummarizeCount, this.toSummarizeMessageKey);
43+
if (logsToSummarizeCount > 0L) {
44+
node.newReportNode()
45+
.withResourceBundles(ShortcircuitServerReportResourceBundle.BASE_NAME) //TODO what is this bug with tests?
46+
.withMessageTemplate(this.summaryMessageKey)
47+
.withTimestamp()
48+
.withSeverity(TypedValue.WARN_SEVERITY)
49+
.withUntypedValue("equipmentsLabel", this.equipmentsLabel)
50+
.withUntypedValue("nb", logsToSummarizeCount)
51+
.add();
52+
}
53+
}
54+
}
55+
}

src/main/java/org/gridsuite/shortcircuit/server/report/mappers/AdnTraceLevelAndSummarizeMapper.java

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.gridsuite.shortcircuit.server.report.mappers;
2+
3+
import com.powsybl.commons.report.ReportNode;
4+
import com.powsybl.commons.report.TypedValue;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Data;
7+
import lombok.NonNull;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.gridsuite.shortcircuit.server.report.ReportMapper;
10+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
11+
import org.jetbrains.annotations.NotNull;
12+
import org.jetbrains.annotations.Nullable;
13+
14+
/**
15+
* Pass some of the verbose logs to {@link TypedValue#TRACE_SEVERITY TRACE} severity for example.
16+
*/
17+
@Slf4j
18+
@AllArgsConstructor
19+
@Data
20+
public class SeverityMapper implements ReportMapper {
21+
@Nullable private final String parentMessageKey; //"Conversion of ..."
22+
@NonNull private final String messageKey;
23+
@NonNull private final TypedValue severity;
24+
25+
public SeverityMapper(@NotNull String messageKey, @NotNull TypedValue severity) {
26+
this(null, messageKey, severity);
27+
}
28+
29+
/** {@inheritDoc} */
30+
@Override
31+
public void transformNode(final @NonNull ReportNode node, @Nullable final ShortCircuitRunContext unused) {
32+
if (parentMessageKey == null) {
33+
this.testAndSet(node);
34+
} else {
35+
if (this.parentMessageKey.equals(node.getMessageKey())) {
36+
log.debug("ADN logs node {} detected, will analyse it...", this.parentMessageKey);
37+
for (final ReportNode child : node.getChildren()) {
38+
this.testAndSet(child);
39+
}
40+
}
41+
}
42+
}
43+
44+
private void testAndSet(final @NotNull ReportNode node) {
45+
if (this.messageKey.equals(node.getMessageKey())) {
46+
node.addSeverity(this.severity);
47+
}
48+
}
49+
}

src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitRunContext.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
package org.gridsuite.shortcircuit.server.service;
88

99
import com.powsybl.shortcircuit.ShortCircuitParameters;
10-
import lombok.Getter;
1110
import com.powsybl.ws.commons.computation.dto.ReportInfos;
1211
import com.powsybl.ws.commons.computation.service.AbstractComputationRunContext;
12+
import lombok.Getter;
1313
import lombok.Setter;
14+
import org.apache.commons.lang3.mutable.MutableLong;
1415
import org.gridsuite.shortcircuit.server.dto.ShortCircuitLimits;
1516

1617
import java.util.*;
@@ -20,17 +21,24 @@
2021
*/
2122
@Getter
2223
public class ShortCircuitRunContext extends AbstractComputationRunContext<ShortCircuitParameters> {
23-
2424
@Setter
2525
private Map<String, ShortCircuitLimits> shortCircuitLimits = new HashMap<>();
2626
private final String busId;
2727
@Setter
2828
private List<String> voltageLevelsWithWrongIsc = new ArrayList<>();
2929

30+
/** @see org.gridsuite.shortcircuit.server.report.mappers.AdnSummarizeMapper */
31+
private final MutableLong adnSummarizeCounterGenerator = new MutableLong();
32+
/** @see org.gridsuite.shortcircuit.server.report.mappers.AdnSummarizeMapper */
33+
private final MutableLong adnSummarizeCounterBattery = new MutableLong();
34+
/** @see org.gridsuite.shortcircuit.server.report.mappers.AdnSummarizeMapper */
35+
private final MutableLong adnSummarizeCounterLines = new MutableLong();
36+
/** @see org.gridsuite.shortcircuit.server.report.mappers.AdnSummarizeMapper */
37+
private final MutableLong adnSummarizeCounterT2W = new MutableLong();
38+
3039
public ShortCircuitRunContext(UUID networkUuid, String variantId, String receiver, ShortCircuitParameters parameters,
3140
UUID reportUuid, String reporterId, String reportType, String userId, String provider, String busId) {
3241
super(networkUuid, variantId, receiver, new ReportInfos(reportUuid, reporterId, reportType), userId, provider, parameters);
3342
this.busId = busId;
3443
}
35-
3644
}

src/main/resources/application-local.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ gridsuite:
1818
services:
1919
report-server:
2020
base-uri: http://localhost:5028
21+
22+
logging:
23+
level:
24+
# please let us debug that server
25+
org.gridsuite.shortcircuit.server.report: DEBUG
26+
# helpers logs the same content as the ReportNode tree being constructed: that is noise for us
27+
com.rte_france.powsybl.iidm.export.adn: ERROR
28+
com.rte_france.powsybl.courcirc.Courcirc: WARN
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
shortcircuit.server.addConstantRatioSummary = Adding constant ratio voltage transformation on ${nb} ${equipmentsLabel} because both voltage levels have different nominal voltage
1+
shortcircuit.server.addConstantRatioSummary = Adding constant ratio voltage transformation on ${nb} ${equipmentsLabel} because extremities voltage levels have different nominal voltage
22
shortcircuit.server.disconnectedTerminalEquipmentSummary = Regulating terminal of ${nb} connected ${equipmentsLabel} is disconnected. Regulation is disabled.
33
shortcircuit.server.VoltageLevelsWithWrongIscValues = Voltage levels having wrong isc values
44
shortcircuit.server.VoltageLevelsWithWrongIscValuesSummarize = Some voltage levels have wrong isc values, isc min must be <= isc max: ${voltageLevels}

0 commit comments

Comments
 (0)