From 5308ad312d8f8cd9ae2e586c2439dd3b8d6953fb Mon Sep 17 00:00:00 2001 From: KAHYA Amira Date: Tue, 3 Dec 2024 11:41:00 +0100 Subject: [PATCH] Adaptation to 96TS in NTC2 --- .../cse/import_runner/app/util/Ntc2Util.java | 17 +- .../app/services/FileImporterTest.java | 31 +- .../NTC2_20210624_2D5_AT-IT1-test-96.xml | 410 ++++++++++++++++++ ...0624_2D5_AT-IT1-test-missing-intervals.xml | 54 +++ .../NTC2_20210624_2D5_AT-IT1-test.xml | 85 +++- .../NTC2_20210624_2D5_CH-IT1-test-96.xml | 410 ++++++++++++++++++ ...0624_2D5_CH-IT1-test-missing-intervals.xml | 103 +++++ .../NTC2_20210624_2D5_CH-IT1-test.xml | 85 +++- .../NTC2_20210624_2D5_FR-IT1-test-96.xml | 410 ++++++++++++++++++ ...0624_2D5_FR-IT1-test-missing-intervals.xml | 103 +++++ .../NTC2_20210624_2D5_FR-IT1-test.xml | 85 +++- .../NTC2_20210624_2D5_SI-IT1-test-96.xml | 410 ++++++++++++++++++ ...0624_2D5_SI-IT1-test-missing-intervals.xml | 98 +++++ .../NTC2_20210624_2D5_SI-IT1-test.xml | 85 +++- 14 files changed, 2373 insertions(+), 13 deletions(-) create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-96.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-missing-intervals.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-96.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-missing-intervals.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-96.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-missing-intervals.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-96.xml create mode 100755 cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-missing-intervals.xml diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/Ntc2Util.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/Ntc2Util.java index 6e629de4..827dd38e 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/Ntc2Util.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/Ntc2Util.java @@ -10,6 +10,7 @@ import java.io.InputStream; import java.time.OffsetDateTime; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,7 +34,7 @@ public static Double getD2ExchangeByOffsetDateTime(InputStream ntc2InputStream, Map qtyByPositionMap = new HashMap<>(); CapacityDocument capacityDocument = DataUtil.unmarshalFromInputStream(ntc2InputStream, CapacityDocument.class); checkTimeInterval(capacityDocument, targetDateTime); - int position = targetDateTime.atZoneSameInstant(ZoneId.of("CET")).getHour() + 1; + capacityDocument.getCapacityTimeSeries() .stream() .filter(ts -> IT_AREA_CODE.equalsIgnoreCase(ts.getInArea().getV()) && !ts.getPeriod().isEmpty()) @@ -46,9 +47,17 @@ public static Double getD2ExchangeByOffsetDateTime(InputStream ntc2InputStream, final int index = interval.getPos().getV(); qtyByPositionMap.put(index, interval.getQty().getV().doubleValue()); }); - return Optional.ofNullable(qtyByPositionMap.get(position)) - .orElseThrow(() -> new CseDataException( - String.format("Impossible to retrieve NTC2 position %d. It does not exist", position))); + int position; + ZonedDateTime targetDateInCETZone = targetDateTime.atZoneSameInstant(ZoneId.of("CET")); + if (qtyByPositionMap.size() == 96) { + position = 1 + (4 * targetDateInCETZone.getHour()) + (targetDateInCETZone.getMinute() / 15); + } else if (qtyByPositionMap.size() == 24) { + position = targetDateInCETZone.getHour() + 1; + } else { + throw new CseDataException(String.format("CapacityTimeSeries contains %s intervals which is different to 24 or 96", qtyByPositionMap.size())); + } + + return qtyByPositionMap.get(position); } private static void checkTimeInterval(CapacityDocument capacityDocument, OffsetDateTime targetDateTime) { diff --git a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/FileImporterTest.java b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/FileImporterTest.java index aedbebfa..9aae30ea 100644 --- a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/FileImporterTest.java +++ b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/FileImporterTest.java @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; /** + * @author Amira Kahya {@literal } * @author Joris Mancini {@literal } */ @SpringBootTest @@ -137,6 +138,26 @@ void testImportNtc2AllPresent() { assertEquals(8192, ntc2.getExchanges().get("10YSI-ELES-----O")); } + @Test + void testImportNtc296TSAllPresent() { + Ntc2 ntc2 = fileImporter.importNtc2(OffsetDateTime.parse("2021-06-24T00:30Z"), // 02:30 in CET zone + getClass().getResource("NTC2_20210624_2D5_AT-IT1-test-96.xml").toString(), + getClass().getResource("NTC2_20210624_2D5_CH-IT1-test-96.xml").toString(), + getClass().getResource("NTC2_20210624_2D5_FR-IT1-test-96.xml").toString(), + getClass().getResource("NTC2_20210624_2D5_SI-IT1-test-96.xml").toString()); + assertNotNull(ntc2); + assertNotNull(ntc2.getExchanges()); + assertEquals(4, ntc2.getExchanges().size()); + assertNotNull(ntc2.getExchanges().get("10YAT-APG------L")); + assertEquals(990, ntc2.getExchanges().get("10YAT-APG------L")); + assertNotNull(ntc2.getExchanges().get("10YCH-SWISSGRIDZ")); + assertEquals(150, ntc2.getExchanges().get("10YCH-SWISSGRIDZ")); + assertNotNull(ntc2.getExchanges().get("10YFR-RTE------C")); + assertEquals(1199, ntc2.getExchanges().get("10YFR-RTE------C")); + assertNotNull(ntc2.getExchanges().get("10YSI-ELES-----O")); + assertEquals(15, ntc2.getExchanges().get("10YSI-ELES-----O")); + } + @Test void assertThrowsWhenDataIsMissing() { OffsetDateTime time = OffsetDateTime.parse("2021-06-23T22:00Z"); @@ -170,14 +191,14 @@ void assertThrowsWhenTargetDateTimeOutOfBound() { @Test void testImportFailsWithMissingPositions() { OffsetDateTime time = OffsetDateTime.parse("2021-06-24T15:00Z"); - String atFileUrl = getClass().getResource("NTC2_20210624_2D5_AT-IT1-test.xml").toString(); - String chFileUrl = getClass().getResource("NTC2_20210624_2D5_CH-IT1-test.xml").toString(); - String frFileUrl = getClass().getResource("NTC2_20210624_2D5_FR-IT1-test.xml").toString(); - String siFileUrl = getClass().getResource("NTC2_20210624_2D5_SI-IT1-test.xml").toString(); + String atFileUrl = getClass().getResource("NTC2_20210624_2D5_AT-IT1-test-missing-intervals.xml").toString(); + String chFileUrl = getClass().getResource("NTC2_20210624_2D5_CH-IT1-test-missing-intervals.xml").toString(); + String frFileUrl = getClass().getResource("NTC2_20210624_2D5_FR-IT1-test-missing-intervals.xml").toString(); + String siFileUrl = getClass().getResource("NTC2_20210624_2D5_SI-IT1-test-missing-intervals.xml").toString(); Throwable e = assertThrows(CseDataException.class, () -> fileImporter.importNtc2(time, atFileUrl, chFileUrl, frFileUrl, siFileUrl)); assertEquals("Impossible to import NTC2 file for area: 10YAT-APG------L", e.getMessage()); Throwable nestedE = e.getCause(); - assertEquals("Impossible to retrieve NTC2 position 18. It does not exist", nestedE.getMessage()); + assertEquals("CapacityTimeSeries contains 7 intervals which is different to 24 or 96", nestedE.getMessage()); } @Test diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-96.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-96.xml new file mode 100755 index 00000000..ecca6543 --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-96.xml @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-missing-intervals.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-missing-intervals.xml new file mode 100755 index 00000000..cda12626 --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test-missing-intervals.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test.xml index 0bde8a8e..6dbdb719 100755 --- a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test.xml +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_AT-IT1-test.xml @@ -33,7 +33,90 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-96.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-96.xml new file mode 100755 index 00000000..2a5e6c83 --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-96.xml @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-missing-intervals.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-missing-intervals.xml new file mode 100755 index 00000000..ae018386 --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test-missing-intervals.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test.xml index 8165e5f3..6e7d9321 100755 --- a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test.xml +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_CH-IT1-test.xml @@ -33,7 +33,90 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-96.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-96.xml new file mode 100755 index 00000000..f2f96f2a --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-96.xml @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-missing-intervals.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-missing-intervals.xml new file mode 100755 index 00000000..82393132 --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test-missing-intervals.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test.xml index 7f56d474..09a0c41d 100755 --- a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test.xml +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_FR-IT1-test.xml @@ -33,7 +33,90 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-96.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-96.xml new file mode 100755 index 00000000..529fa5ab --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-96.xml @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-missing-intervals.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-missing-intervals.xml new file mode 100755 index 00000000..51e8eb8f --- /dev/null +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test-missing-intervals.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test.xml b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test.xml index dc18808f..7481fdb8 100755 --- a/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test.xml +++ b/cse-cc-import-runner-app/src/test/resources/com/farao_community/farao/cse/import_runner/app/services/NTC2_20210624_2D5_SI-IT1-test.xml @@ -33,7 +33,90 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file