Skip to content

Commit

Permalink
Adaptation to 96TS in NTC2
Browse files Browse the repository at this point in the history
  • Loading branch information
kahyami committed Dec 3, 2024
1 parent 1183af8 commit 5308ad3
Show file tree
Hide file tree
Showing 14 changed files with 2,373 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +34,7 @@ public static Double getD2ExchangeByOffsetDateTime(InputStream ntc2InputStream,
Map<Integer, Double> 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())
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* @author Amira Kahya {@literal <amira.kahya at rte-france.com>}
* @author Joris Mancini {@literal <joris.mancini at rte-france.com>}
*/
@SpringBootTest
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5308ad3

Please sign in to comment.