Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor reporter with one empty automaton report #317

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -111,6 +111,7 @@ private List<VarConnection> getVarConnectionsWith(TapChangerModel connected) {
}

private List<VarConnection> getVarConnectionsWith(ActionConnectionPoint connected, String suffix) {

return connected.getUImpinVarName()
.map(uImpinVarName -> List.of(new VarConnection("tapChangerBlocking_UMonitored" + suffix, uImpinVarName)))
.orElse(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,13 +28,15 @@
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;
import java.util.List;
import java.util.Objects;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand All @@ -44,6 +48,7 @@ public abstract class AbstractDynamicModelXmlTest extends AbstractSerDeTest {
protected List<BlackBoxModel> eventModels = new ArrayList<>();
protected List<Curve> curves = new ArrayList<>();
protected DynaWaltzContext context;
protected ReporterModel reporter = new ReporterModel("testDyd", "Test DYD");

@BeforeEach
void setup() {
Expand Down Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
""");
}
}
Loading