From aad040b30ca7a9b6b5d1438c47aff66e7ed29946 Mon Sep 17 00:00:00 2001 From: Lisrte Date: Mon, 11 Dec 2023 10:52:13 +0100 Subject: [PATCH] Refactor empty automaton report (#317) * Refactor reporter with one empty automaton report * Split empty automaton Signed-off-by: lisrte --- .../com/powsybl/dynawaltz/DynawaltzReports.java | 16 ++++++++++------ .../models/automatons/TapChangerAutomaton.java | 2 +- .../automatons/TapChangerBlockingAutomaton.java | 3 ++- .../xml/AbstractDynamicModelXmlTest.java | 13 ++++++++++++- .../xml/EmptyTapChangerAutomatonXmlTest.java | 5 +++++ .../EmptyTapChangerBlockingAutomatonXmlTest.java | 6 ++++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java index 363c2d555..bb2736d3a 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java @@ -56,20 +56,24 @@ public static void reportDuplicateDynamicId(Reporter reporter, String duplicateI .build()); } - public static void reportEmptyTapChanger(Reporter reporter, String dynamicId) { + public static void reportEmptyAutomaton(Reporter reporter, String automatonName, String dynamicId, String expectedModels) { reporter.report(Report.builder() - .withKey("emptyTC") - .withDefaultMessage("TapChangerAutomaton ${dynamicId} load does not possess a transformer, the automaton will be skipped") + .withKey("emptyAutomaton") + .withDefaultMessage("${automatonName} ${dynamicId} equipment is not a ${expectedModels}, the automaton will be skipped") + .withValue("automatonName", automatonName) .withValue("dynamicId", dynamicId) + .withValue("expectedModels", expectedModels) .withSeverity(TypedValue.WARN_SEVERITY) .build()); } - public static void reportEmptyTapChangerBlockingAutomaton(Reporter reporter, String dynamicId) { + public static void reportEmptyListAutomaton(Reporter reporter, String automatonName, String dynamicId, String expectedModels) { reporter.report(Report.builder() - .withKey("emptyTCB") - .withDefaultMessage("None of TapChangerBlockingAutomaton {} equipments are TapChangerModel, the automaton will be skipped") + .withKey("emptyListAutomaton") + .withDefaultMessage("None of ${automatonName} ${dynamicId} equipments are ${expectedModels}, the automaton will be skipped") + .withValue("automatonName", automatonName) .withValue("dynamicId", dynamicId) + .withValue("expectedModels", expectedModels) .withSeverity(TypedValue.WARN_SEVERITY) .build()); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerAutomaton.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerAutomaton.java index a1e8780fe..a57feea69 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerAutomaton.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerAutomaton.java @@ -63,7 +63,7 @@ public void createMacroConnections(DynaWaltzContext context) { boolean isSkipped = createMacroConnectionsOrSkip(load, LoadWithTransformers.class, this::getVarConnectionsWith, context); if (isSkipped) { connection = ConnectionState.NOT_CONNECTED; - DynawaltzReports.reportEmptyTapChanger(context.getReporter(), getDynamicModelId()); + DynawaltzReports.reportEmptyAutomaton(context.getReporter(), this.getName(), getDynamicModelId(), LoadWithTransformers.class.getSimpleName()); } else { connection = ConnectionState.CONNECTED; } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerBlockingAutomaton.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerBlockingAutomaton.java index 7ed93890c..a56defedd 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerBlockingAutomaton.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/TapChangerBlockingAutomaton.java @@ -102,7 +102,7 @@ public void createMacroConnections(DynaWaltzContext context) { } } else { isConnected = false; - DynawaltzReports.reportEmptyTapChangerBlockingAutomaton(context.getReporter(), getDynamicModelId()); + DynawaltzReports.reportEmptyListAutomaton(context.getReporter(), this.getName(), getDynamicModelId(), TapChangerModel.class.getSimpleName()); } } @@ -111,6 +111,7 @@ private List getVarConnectionsWith(TapChangerModel connected) { } private List getVarConnectionsWith(ActionConnectionPoint connected, String suffix) { + return connected.getUImpinVarName() .map(uImpinVarName -> List.of(new VarConnection("tapChangerBlocking_UMonitored" + suffix, uImpinVarName))) .orElse(Collections.emptyList()); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java index 74a4f73a5..035a4385e 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java @@ -7,7 +7,9 @@ */ package com.powsybl.dynawaltz.xml; +import com.powsybl.commons.reporter.ReporterModel; import com.powsybl.commons.test.AbstractSerDeTest; +import com.powsybl.commons.test.TestUtil; import com.powsybl.dynamicsimulation.Curve; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzContext; @@ -26,6 +28,7 @@ import javax.xml.validation.Validator; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -33,6 +36,7 @@ import java.util.Objects; import static com.powsybl.commons.test.ComparisonUtils.compareTxt; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Laurent Issertial {@literal } @@ -44,6 +48,7 @@ public abstract class AbstractDynamicModelXmlTest extends AbstractSerDeTest { protected List eventModels = new ArrayList<>(); protected List curves = new ArrayList<>(); protected DynaWaltzContext context; + protected ReporterModel reporter = new ReporterModel("testDyd", "Test DYD"); @BeforeEach void setup() { @@ -74,10 +79,16 @@ public void validate(String schemaDefinition, String expectedResourceName, Path void setupDynawaltzContext() { DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(); - context = new DynaWaltzContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, eventModels, curves, parameters, dynawoParameters); + context = new DynaWaltzContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, eventModels, curves, parameters, dynawoParameters, reporter); } protected abstract void setupNetwork(); protected abstract void addDynamicModels(); + + protected void checkReporter(String report) { + StringWriter sw = new StringWriter(); + reporter.export(sw); + assertEquals(report, TestUtil.normalizeLineSeparator(sw.toString())); + } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomatonXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomatonXmlTest.java index 8f83f9185..b22874c0a 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomatonXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomatonXmlTest.java @@ -37,5 +37,10 @@ void writeModel() throws SAXException, IOException, XMLStreamException { DydXml.write(tmpDir, context); ParametersXml.write(tmpDir, context); validate("dyd.xsd", "tap_changer_empty_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME)); + checkReporter(""" + + Test DYD + + Dynawaltz models processing + TapChangerAutomaton BBM_TC equipment is not a LoadWithTransformers, the automaton will be skipped + """); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomatonXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomatonXmlTest.java index 9b849db78..50c115fec 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomatonXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomatonXmlTest.java @@ -50,5 +50,11 @@ void writeModel() throws SAXException, IOException, XMLStreamException { DydXml.write(tmpDir, context); ParametersXml.write(tmpDir, context); validate("dyd.xsd", "tap_changer_blocking_empty_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME)); + checkReporter(""" + + Test DYD + + Dynawaltz models processing + TapChangerAutomaton BBM_TC equipment is not a LoadWithTransformers, the automaton will be skipped + None of TapChangerBlockingAutomaton BBM_TapChangerBlocking equipments are TapChangerModel, the automaton will be skipped + """); } }