From 844954fc9c6dbce6ec40171b041b947ab239c387 Mon Sep 17 00:00:00 2001 From: lisrte Date: Fri, 29 Nov 2024 13:16:38 +0100 Subject: [PATCH] Remove duplicate from Curves timeSeries Use LinkedHashMap for curves and fsv Signed-off-by: lisrte --- .../dynawo/it/DynawoSimulationTest.java | 2 +- .../dynawo/DynawoSimulationHandler.java | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSimulationTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSimulationTest.java index 2e5a30996..a060086d1 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSimulationTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSimulationTest.java @@ -72,7 +72,7 @@ void testIeee14() { assertEquals(27, result.getCurves().size()); DoubleTimeSeries ts1 = result.getCurve("_GEN____1_SM_generator_UStatorPu"); assertEquals("_GEN____1_SM_generator_UStatorPu", ts1.getMetadata().getName()); - assertEquals(585, ts1.toArray().length); + assertEquals(192, ts1.toArray().length); assertEquals(14, result.getFinalStateValues().size()); assertEquals(1.046227, result.getFinalStateValues().get("NETWORK__BUS___10_TN_Upu_value")); List timeLine = result.getTimeLine(); diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationHandler.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationHandler.java index 0f2f7f6ec..60e434673 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationHandler.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationHandler.java @@ -32,10 +32,7 @@ import com.powsybl.dynawo.commons.timeline.XmlTimeLineParser; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.serde.NetworkSerDe; -import com.powsybl.timeseries.DoubleTimeSeries; -import com.powsybl.timeseries.TimeSeries; -import com.powsybl.timeseries.TimeSeriesConstants; -import com.powsybl.timeseries.TimeSeriesCsvConfig; +import com.powsybl.timeseries.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,8 +64,8 @@ public final class DynawoSimulationHandler extends AbstractExecutionHandler timeline = new ArrayList<>(); - private final Map curves = new HashMap<>(); - private final Map fsv = new HashMap<>(); + private final Map curves = new LinkedHashMap<>(); + private final Map fsv = new LinkedHashMap<>(); private DynamicSimulationResult.Status status = DynamicSimulationResult.Status.SUCCESS; private String statusText = ""; @@ -190,7 +187,7 @@ private void setCurves(Path workingDir) { Path curvesPath = workingDir.resolve(CURVES_OUTPUT_PATH).resolve(CURVES_FILENAME); if (Files.exists(curvesPath)) { TimeSeries.parseCsv(curvesPath, new TimeSeriesCsvConfig(TimeSeriesConstants.DEFAULT_SEPARATOR, false, TimeSeries.TimeFormat.FRACTIONS_OF_SECOND)) - .values().forEach(l -> l.forEach(curve -> curves.put(curve.getMetadata().getName(), (DoubleTimeSeries) curve))); + .values().forEach(l -> l.forEach(curve -> curves.put(curve.getMetadata().getName(), sanitizeDoubleTimeSeries((DoubleTimeSeries) curve)))); } else { LOGGER.warn("Curves folder not found"); status = DynamicSimulationResult.Status.FAILURE; @@ -198,6 +195,14 @@ private void setCurves(Path workingDir) { } } + private DoubleTimeSeries sanitizeDoubleTimeSeries(DoubleTimeSeries series) { + Set times = new LinkedHashSet<>(); + double[] values = series.stream().filter(dp -> times.add(dp.getTime())).mapToDouble(DoublePoint::getValue).toArray(); + return TimeSeries.createDouble(series.getMetadata().getName(), + new IrregularTimeSeriesIndex(times.stream().mapToLong(l -> l).toArray()), + values); + } + private void setFinalStateValues(Path workingDir) { Path fsvPath = workingDir.resolve(FSV_OUTPUT_PATH).resolve(FSV_OUTPUT_FILENAME); if (Files.exists(fsvPath)) {