From aa41a4efe503a2057c58673680616a10c6cdfc5b Mon Sep 17 00:00:00 2001 From: lisrte Date: Wed, 22 Nov 2023 10:38:10 +0100 Subject: [PATCH] Use TimelineEvent instead of StringTimeSeries Signed-off-by: lisrte --- .../powsybl/dynawaltz/DynaWaltzProvider.java | 18 ++++--- .../com/powsybl/dynawo/it/DynaWaltzTest.java | 53 +++++++++---------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java index 0234e317e..c0f75607a 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java @@ -189,7 +189,8 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th DumpFileParameters dumpFileParameters = parameters.getDumpFileParameters(); DynamicSimulationResult.Status status = DynamicSimulationResult.Status.SUCCEED; - String error = ""; + String statusText = ""; + List timeline = new ArrayList<>(); Map curves = new HashMap<>(); //Dynawo log @@ -216,7 +217,7 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th } else { LOGGER.warn("Output IIDM file not found"); status = DynamicSimulationResult.Status.FAILED; - error = "Dynawo Output IIDM file not found"; + statusText = "Dynawo Output IIDM file not found"; } } @@ -234,7 +235,10 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th Path timelineFile = outputsFolder.resolve(DYNAWO_TIMELINE_FOLDER).resolve(TIMELINE_FILENAME); if (Files.exists(timelineFile)) { Reporter timelineReporter = DynawaltzReports.createDynaWaltzTimelineReporter(reporter); - new CsvTimeLineParser().parse(timelineFile).forEach(e -> CommonReports.reportTimelineEvent(timelineReporter, e)); + new CsvTimeLineParser().parse(timelineFile).forEach(e -> { + CommonReports.reportTimelineEvent(timelineReporter, e); + timeline.add(new TimelineEvent(e.time(), e.modelName(), e.message())); + }); } else { LOGGER.warn("Timeline file not found"); } @@ -248,20 +252,20 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th } else { LOGGER.warn("Curves folder not found"); status = DynamicSimulationResult.Status.FAILED; - error = "Dynawo curves folder not found"; + statusText = "Dynawo curves folder not found"; } } } else { status = DynamicSimulationResult.Status.FAILED; - error = errorMatcher.group().substring(DYNAWO_ERROR_PATTERN.length()); + statusText = errorMatcher.group().substring(DYNAWO_ERROR_PATTERN.length()); } } else { LOGGER.warn("Error file not found"); status = DynamicSimulationResult.Status.FAILED; - error = "Dynawo error log file not found"; + statusText = "Dynawo error log file not found"; } - return new DynamicSimulationResultImpl(status, error, curves, DynamicSimulationResult.emptyTimeLine()); + return new DynamicSimulationResultImpl(status, statusText, curves, timeline); } private void writeInputFiles(Path workingDir) { diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java index e1c148b7d..00f9d9df9 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java @@ -20,7 +20,6 @@ import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.iidm.network.test.SvcTestCaseFactory; import com.powsybl.timeseries.DoubleTimeSeries; -import com.powsybl.timeseries.StringTimeSeries; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,7 +49,7 @@ void setUp() throws Exception { super.setUp(); provider = new DynaWaltzProvider(new DynaWaltzConfig(Path.of("/dynawo"), false)); parameters = new DynamicSimulationParameters() - .setStartTime(1) + .setStartTime(0) .setStopTime(100); dynaWaltzParameters = new DynaWaltzParameters(); parameters.addExtension(DynaWaltzParameters.class, dynaWaltzParameters); @@ -86,15 +85,14 @@ void testIeee14() { .join(); assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus()); - assertTrue(result.isOk()); - assertTrue(result.getError().isEmpty()); + assertTrue(result.getStatusText().isEmpty()); assertEquals(41, result.getCurves().size()); DoubleTimeSeries ts1 = (DoubleTimeSeries) result.getCurve("_GEN____1_SM_generator_UStatorPu"); assertEquals("_GEN____1_SM_generator_UStatorPu", ts1.getMetadata().getName()); assertEquals(587, ts1.toArray().length); - StringTimeSeries timeLine = result.getTimeLine(); - assertEquals(1, timeLine.toArray().length); - assertNull(timeLine.toArray()[0]); // FIXME + List timeLine = result.getTimeLine(); + assertEquals(23, timeLine.size()); + checkFirstTimeLineEvent(timeLine.get(0), 0,"_GEN____8_SM", "PMIN : activation"); } @Test @@ -130,7 +128,7 @@ void testIeee14WithDump() throws IOException { DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, NO_OP) .join(); - assertTrue(result.isOk()); + assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus()); //Use exported dump as input parameters.setStartTime(30); @@ -147,8 +145,6 @@ void testIeee14WithDump() throws IOException { .join(); assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus()); - assertTrue(result.isOk()); - assertTrue(result.getError().isEmpty()); } @Test @@ -173,12 +169,11 @@ void testSvc() { .join(); assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus()); - assertTrue(result.isOk()); - assertTrue(result.getError().isEmpty()); + assertTrue(result.getStatusText().isEmpty()); assertTrue(result.getCurves().isEmpty()); - StringTimeSeries timeLine = result.getTimeLine(); - assertEquals(1, timeLine.toArray().length); - assertNull(timeLine.toArray()[0]); // FIXME + List timeLine = result.getTimeLine(); + assertEquals(1, timeLine.size()); + checkFirstTimeLineEvent(timeLine.get(0), 0, "G1", "PMIN : activation"); } @Test @@ -203,12 +198,11 @@ void testHvdc() { .join(); assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus()); - assertTrue(result.isOk()); - assertTrue(result.getError().isEmpty()); + assertTrue(result.getStatusText().isEmpty()); assertTrue(result.getCurves().isEmpty()); - StringTimeSeries timeLine = result.getTimeLine(); - assertEquals(1, timeLine.toArray().length); - assertNull(timeLine.toArray()[0]); // FIXME + List timeLine = result.getTimeLine(); + assertEquals(7, timeLine.size()); + checkFirstTimeLineEvent(timeLine.get(0), 30.0, "_BUS____5-BUS____6-1_PS", "Tap +1"); } @Test @@ -242,12 +236,10 @@ void testSmib() { .join(); assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus()); - assertTrue(result.isOk()); - assertTrue(result.getError().isEmpty()); + assertTrue(result.getStatusText().isEmpty()); assertEquals(35, result.getCurves().size()); - StringTimeSeries timeLine = result.getTimeLine(); - assertEquals(1, timeLine.toArray().length); - assertNull(timeLine.toArray()[0]); // FIXME + List timeLine = result.getTimeLine(); + assertTrue(timeLine.isEmpty()); } @Test @@ -274,9 +266,14 @@ void testSimulationError() { .join(); assertEquals(DynamicSimulationResult.Status.FAILED, result.getStatus()); - assertFalse(result.isOk()); - assertEquals("time step <= 0.1 s for more than 10 iterations ( DYNSolverCommonFixedTimeStep.cpp:419 )", result.getError()); - assertEquals(DynamicSimulationResult.emptyTimeLine(), result.getTimeLine()); + assertEquals("time step <= 0.1 s for more than 10 iterations ( DYNSolverCommonFixedTimeStep.cpp:419 )", result.getStatusText()); + assertTrue(result.getTimeLine().isEmpty()); assertTrue(result.getCurves().isEmpty()); } + + private void checkFirstTimeLineEvent(TimelineEvent event, double time, String modelName, String message) { + assertEquals(time, event.time()); + assertEquals(modelName, event.modelName()); + assertEquals(message, event.message()); + } }