From 7108eb40fd123db4aeba760a289edbaba85f539a Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Wed, 15 Nov 2023 11:30:55 +0100 Subject: [PATCH 01/10] add actual and upcoming overload : limitViolationInfos Signed-off-by: Maissa SOUISSI --- .../server/dto/LimitViolationInfos.java | 8 ++- .../entities/LimitViolationEmbeddable.java | 6 ++ .../server/service/LoadFlowWorkerService.java | 63 ++++++++++++++++++- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java index 8fedc311..9d685cf1 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java @@ -31,6 +31,10 @@ public class LimitViolationInfos { private Integer acceptableDuration; + private Integer actualOverload; + + private Integer upComingOverload; + private Double value; private String side; @@ -38,7 +42,7 @@ public class LimitViolationInfos { private LimitViolationType limitType; public LimitViolationEmbeddable toEmbeddable() { - return new LimitViolationEmbeddable(subjectId, limit, limitName, acceptableDuration, value, side, limitType); + return new LimitViolationEmbeddable(subjectId, limit, limitName, acceptableDuration, value, side, limitType, actualOverload, upComingOverload); } public static LimitViolationInfos toLimitViolationInfos(LimitViolationEmbeddable limitViolationEmbeddable) { @@ -50,6 +54,8 @@ public static LimitViolationInfos toLimitViolationInfos(LimitViolationEmbeddable .value(limitViolationEmbeddable.getValue()) .side(limitViolationEmbeddable.getSide()) .limitType(limitViolationEmbeddable.getLimitType()) + .actualOverload(limitViolationEmbeddable.getActualOverload()) + .upComingOverload(limitViolationEmbeddable.getUpComingOverload()) .build(); } } diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java b/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java index f7eee36d..11e1386b 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java @@ -45,4 +45,10 @@ public class LimitViolationEmbeddable { @Column @Enumerated(EnumType.STRING) private LimitViolationType limitType; + + @Column + private Integer actualOverload; + + @Column + private Integer upComingOverload; } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index 333f81b8..fa4f3862 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -12,8 +12,7 @@ import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; import com.powsybl.computation.local.LocalComputationManager; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.VariantManagerConstants; +import com.powsybl.iidm.network.*; import com.powsybl.loadflow.LoadFlow; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.loadflow.LoadFlowResult; @@ -38,6 +37,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; +import java.util.stream.Collectors; import static org.gridsuite.loadflow.server.service.LoadFlowRunContext.buildParameters; import static org.gridsuite.loadflow.server.service.NotificationService.FAIL_MESSAGE; @@ -50,6 +50,7 @@ public class LoadFlowWorkerService { private static final Logger LOGGER = LoggerFactory.getLogger(LoadFlowWorkerService.class); private static final String LOAD_FLOW_TYPE_REPORT = "LoadFlow"; + private static final String CURRENT = "CURRENT"; private Lock lockRunAndCancelLF = new ReentrantLock(); @@ -143,6 +144,61 @@ private void cleanLoadFlowResultsAndPublishCancel(UUID resultUuid, String receiv notificationService.publishStop(resultUuid, receiver); } + private LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo, Network network) { + + Optional currentLimits = violationInfo.getSide().equals("ONE") ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); + Double permanantLimit = currentLimits.get().getPermanentLimit(); + if (violationInfo.getValue() < permanantLimit) { + return null; + } else { + List temporaryLimits = currentLimits.get().getTemporaryLimits().stream().collect(Collectors.toList()); + Optional nextTemporaryLimit = temporaryLimits.stream() + .filter(tl -> violationInfo.getValue() < tl.getValue()) + .findFirst(); + if (nextTemporaryLimit.isPresent()) { + LoadingLimits.TemporaryLimit nextLimit = nextTemporaryLimit.get(); + return nextLimit; + } + } + return null; + } + + private Integer calculateUpcomingOverload(LimitViolationInfos limitViolationInfo) { + if (limitViolationInfo.getValue() < limitViolationInfo.getLimit()) { + return limitViolationInfo.getAcceptableDuration(); + } + return null; + } + + private Integer calculateActualOverload(LimitViolationInfos limitViolationInfo, Network network) { + if (limitViolationInfo.getValue() > limitViolationInfo.getLimit()) { + return limitViolationInfo.getAcceptableDuration(); + } else { + String equipmentId = limitViolationInfo.getSubjectId(); + Line line = network.getLine(equipmentId); + TwoWindingsTransformer twoWindingsTransformer = network.getTwoWindingsTransformer(equipmentId); + LoadingLimits.TemporaryLimit tempLimit = null; + + if (line != null) { + tempLimit = handleEquipmentLimitViolation(line, limitViolationInfo, network); + } else if (twoWindingsTransformer != null) { + tempLimit = handleEquipmentLimitViolation(twoWindingsTransformer, limitViolationInfo, network); + } + return (tempLimit != null) ? tempLimit.getAcceptableDuration() : null; + + } + } + + private List calculateOverloadLimitViolations(List limitViolationInfos, Network network) { + for (LimitViolationInfos violationInfo : limitViolationInfos) { + if (violationInfo.getLimitName() != null && violationInfo.getLimitType().name().equals(CURRENT)) { + violationInfo.setActualOverload(calculateActualOverload(violationInfo, network)); + violationInfo.setUpComingOverload(calculateUpcomingOverload(violationInfo)); + } + } + return limitViolationInfos; + } + private void cancelLoadFlowAsync(LoadFlowCancelContext cancelContext) { lockRunAndCancelLF.lock(); try { @@ -198,7 +254,8 @@ public Consumer> consumeRun() { LOGGER.info("Just run in {}s", TimeUnit.NANOSECONDS.toSeconds(nanoTime - startTime.getAndSet(nanoTime))); List limitViolationInfos = getLimitViolations(network, resultContext.getRunContext()); - resultRepository.insert(resultContext.getResultUuid(), result, LoadFlowService.computeLoadFlowStatus(result), limitViolationInfos); + List limitViolationsWithCalculatedOverload = calculateOverloadLimitViolations(limitViolationInfos, network); + resultRepository.insert(resultContext.getResultUuid(), result, LoadFlowService.computeLoadFlowStatus(result), limitViolationsWithCalculatedOverload); long finalNanoTime = System.nanoTime(); LOGGER.info("Stored in {}s", TimeUnit.NANOSECONDS.toSeconds(finalNanoTime - startTime.getAndSet(finalNanoTime))); From 7067b8b4f3b7a78a854b14ab24e59bda8e044f99 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Wed, 15 Nov 2023 11:57:13 +0100 Subject: [PATCH 02/10] add changeset Signed-off-by: Maissa SOUISSI --- .../changesets/changelog_20231115T105257Z.xml | 13 +++++++++++++ .../resources/db/changelog/db.changelog-master.yaml | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml diff --git a/src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml b/src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml new file mode 100644 index 00000000..082f1120 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index ff66c631..d0dab4cd 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -6,3 +6,6 @@ databaseChangeLog: - include: file: changesets/changelog_20231003T105819Z.xml relativeToChangelogFile: true + - include: + file: changesets/changelog_20231115T105257Z.xml + relativeToChangelogFile: true From f3ea51bdb7cd182eab0ecb66ec81dfac9ebcc654 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Wed, 15 Nov 2023 16:27:36 +0100 Subject: [PATCH 03/10] fix code smells Signed-off-by: Maissa SOUISSI --- .../loadflow/server/service/LoadFlowWorkerService.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index fa4f3862..3cbc192e 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -144,7 +144,7 @@ private void cleanLoadFlowResultsAndPublishCancel(UUID resultUuid, String receiv notificationService.publishStop(resultUuid, receiver); } - private LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo, Network network) { + private LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo) { Optional currentLimits = violationInfo.getSide().equals("ONE") ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); Double permanantLimit = currentLimits.get().getPermanentLimit(); @@ -156,8 +156,7 @@ private LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch .filter(tl -> violationInfo.getValue() < tl.getValue()) .findFirst(); if (nextTemporaryLimit.isPresent()) { - LoadingLimits.TemporaryLimit nextLimit = nextTemporaryLimit.get(); - return nextLimit; + return nextTemporaryLimit.get(); } } return null; @@ -180,9 +179,9 @@ private Integer calculateActualOverload(LimitViolationInfos limitViolationInfo, LoadingLimits.TemporaryLimit tempLimit = null; if (line != null) { - tempLimit = handleEquipmentLimitViolation(line, limitViolationInfo, network); + tempLimit = handleEquipmentLimitViolation(line, limitViolationInfo); } else if (twoWindingsTransformer != null) { - tempLimit = handleEquipmentLimitViolation(twoWindingsTransformer, limitViolationInfo, network); + tempLimit = handleEquipmentLimitViolation(twoWindingsTransformer, limitViolationInfo); } return (tempLimit != null) ? tempLimit.getAcceptableDuration() : null; From 1ff010cdf3fa1c70a7a31f35c0758248bab723e3 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Thu, 16 Nov 2023 08:36:30 +0100 Subject: [PATCH 04/10] UnitTests Signed-off-by: Maissa SOUISSI --- .../server/service/LoadFlowWorkerService.java | 6 +++--- .../loadflow/server/LoadFlowControllerTest.java | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index 3cbc192e..fef3885d 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -144,7 +144,7 @@ private void cleanLoadFlowResultsAndPublishCancel(UUID resultUuid, String receiv notificationService.publishStop(resultUuid, receiver); } - private LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo) { + private static LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo) { Optional currentLimits = violationInfo.getSide().equals("ONE") ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); Double permanantLimit = currentLimits.get().getPermanentLimit(); @@ -162,14 +162,14 @@ private LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch return null; } - private Integer calculateUpcomingOverload(LimitViolationInfos limitViolationInfo) { + public static Integer calculateUpcomingOverload(LimitViolationInfos limitViolationInfo) { if (limitViolationInfo.getValue() < limitViolationInfo.getLimit()) { return limitViolationInfo.getAcceptableDuration(); } return null; } - private Integer calculateActualOverload(LimitViolationInfos limitViolationInfo, Network network) { + public static Integer calculateActualOverload(LimitViolationInfos limitViolationInfo, Network network) { if (limitViolationInfo.getValue() > limitViolationInfo.getLimit()) { return limitViolationInfo.getAcceptableDuration(); } else { diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index 16e55d21..c674a783 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -100,9 +100,8 @@ private static final class LoadFlowResultMock { } private static final class LimitViolationsMock { - static List limitViolations = List.of(new LimitViolation("lineId1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 200, 0.7F, 150, Branch.Side.ONE), - new LimitViolation("lineId2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.TWO), - new LimitViolation("genId1", "genName1", LimitViolationType.HIGH_VOLTAGE, "limit3", 120, 500, 0.7F, 370, null)); + static List limitViolations = List.of(new LimitViolation("NHV1_NHV2_2", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 90, 0.7F, 150, Branch.Side.ONE), + new LimitViolation("NHV1_NHV2_1", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.TWO)); } @Autowired @@ -141,10 +140,16 @@ private static void assertResultsEquals(LoadFlowResult result, org.gridsuite.loa assertEquals(componentResultsDto.get(i).getSlackBusId(), componentResults.get(i).getSlackBusId()); assertEquals(componentResultsDto.get(i).getSlackBusActivePowerMismatch(), componentResults.get(i).getSlackBusActivePowerMismatch(), 0.01); assertEquals(componentResultsDto.get(i).getDistributedActivePower(), componentResults.get(i).getDistributedActivePower(), 0.01); - } } + private static void assertLimitViolationsCalculatedOverloadEquals(List limitViolationsDto) { + assertEquals(60, limitViolationsDto.get(0).getActualOverload(), 0.01); + assertNull(limitViolationsDto.get(0).getUpComingOverload()); + assertNull(limitViolationsDto.get(1).getActualOverload()); + assertEquals(300, limitViolationsDto.get(1).getUpComingOverload(), 0.01); + } + private static void assertLimitViolationsEquals(List limitViolations, List limitViolationsDto) { assertEquals(limitViolations.size(), limitViolationsDto.size()); @@ -164,7 +169,7 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); // network store service mocking - network = EurostagTutorialExample1Factory.createWithMoreGenerators(new NetworkFactoryImpl()); + network = EurostagTutorialExample1Factory.createWithFixedCurrentLimits(new NetworkFactoryImpl()); network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_1_ID); network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_2_ID); network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_3_ID); @@ -287,6 +292,7 @@ public void testGetLimitViolations() throws Exception { .andReturn(); List limitViolations = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference>() { }); assertLimitViolationsEquals(LimitViolationsMock.limitViolations, limitViolations); + assertLimitViolationsCalculatedOverloadEquals(limitViolations); } } From 6c146219970a36c72114d6bb91960e8b385a58cc Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Thu, 16 Nov 2023 09:18:03 +0100 Subject: [PATCH 05/10] TU Signed-off-by: Maissa SOUISSI --- .../loadflow/server/LoadFlowControllerTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index c674a783..710282e9 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -30,6 +30,7 @@ import org.gridsuite.loadflow.server.dto.LimitViolationInfos; import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos; import org.gridsuite.loadflow.server.dto.LoadFlowStatus; +import org.gridsuite.loadflow.server.service.LoadFlowWorkerService; import org.gridsuite.loadflow.server.service.NotificationService; import org.gridsuite.loadflow.server.service.ReportService; import org.gridsuite.loadflow.server.service.UuidGeneratorService; @@ -100,8 +101,12 @@ private static final class LoadFlowResultMock { } private static final class LimitViolationsMock { - static List limitViolations = List.of(new LimitViolation("NHV1_NHV2_2", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 90, 0.7F, 150, Branch.Side.ONE), - new LimitViolation("NHV1_NHV2_1", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.TWO)); + static List limitViolations = List.of(new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 400, 0.7F, 350, Branch.Side.ONE), + new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1100, 0.7F, 1250, Branch.Side.TWO), + new LimitViolation("NHV1_NHV2_2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.ONE), + new LimitViolation("NHV1_NHV2_2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.TWO), + new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1100, 0.7F, 1250, Branch.Side.TWO), + new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1000, 0.7F, 800, Branch.Side.TWO)); } @Autowired @@ -150,7 +155,7 @@ private static void assertLimitViolationsCalculatedOverloadEquals(List limitViolations, List limitViolationsDto) { + private static void assertLimitViolationsEquals(List limitViolations, List limitViolationsDto, Network network) { assertEquals(limitViolations.size(), limitViolationsDto.size()); for (int i = 0; i < limitViolationsDto.size(); i++) { @@ -161,6 +166,8 @@ private static void assertLimitViolationsEquals(List limitViolat assertEquals(limitViolationsDto.get(i).getValue(), limitViolations.get(i).getValue(), 0.01); assertEquals(limitViolationsDto.get(i).getSide(), limitViolations.get(i).getSide() != null ? limitViolations.get(i).getSide().name() : ""); assertEquals(limitViolationsDto.get(i).getLimitType(), limitViolations.get(i).getLimitType()); + assertEquals(limitViolationsDto.get(i).getActualOverload(), LoadFlowWorkerService.calculateActualOverload(LoadFlowWorkerService.toLimitViolationInfos(limitViolations.get(i)), network)); + assertEquals(limitViolationsDto.get(i).getUpComingOverload(), LoadFlowWorkerService.calculateUpcomingOverload(LoadFlowWorkerService.toLimitViolationInfos(limitViolations.get(i)))); } } @@ -291,8 +298,8 @@ public void testGetLimitViolations() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); List limitViolations = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference>() { }); - assertLimitViolationsEquals(LimitViolationsMock.limitViolations, limitViolations); - assertLimitViolationsCalculatedOverloadEquals(limitViolations); + assertLimitViolationsEquals(LimitViolationsMock.limitViolations, limitViolations, network); + //assertLimitViolationsCalculatedOverloadEquals(limitViolations); } } From 868e8df7dbcc80022b5ee286fdb3f10d73047461 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Thu, 16 Nov 2023 10:04:48 +0100 Subject: [PATCH 06/10] TU coverage Signed-off-by: Maissa SOUISSI --- .../loadflow/server/LoadFlowControllerTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index 710282e9..187e44f5 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -101,12 +101,11 @@ private static final class LoadFlowResultMock { } private static final class LimitViolationsMock { - static List limitViolations = List.of(new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 400, 0.7F, 350, Branch.Side.ONE), - new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1100, 0.7F, 1250, Branch.Side.TWO), - new LimitViolation("NHV1_NHV2_2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.ONE), - new LimitViolation("NHV1_NHV2_2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 100, 0.7F, 80, Branch.Side.TWO), - new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1100, 0.7F, 1250, Branch.Side.TWO), - new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1000, 0.7F, 800, Branch.Side.TWO)); + static List limitViolations = List.of( + new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1500, 0.7F, 1300, Branch.Side.TWO), + new LimitViolation("NHV1_NHV2_1", "lineName1", LimitViolationType.CURRENT, "limit1", 60, 1500, 0.7F, 1000, Branch.Side.TWO), + new LimitViolation("NHV1_NHV2_2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 900, 0.7F, 1000, Branch.Side.ONE), + new LimitViolation("NHV1_NHV2_2", "lineName2", LimitViolationType.CURRENT, "limit2", 300, 900, 0.7F, 1000, Branch.Side.TWO)); } @Autowired From d125883c5e48b2fbec611ef7dd7ecce12f7f8a52 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Thu, 16 Nov 2023 10:45:44 +0100 Subject: [PATCH 07/10] fixes Signed-off-by: Maissa SOUISSI --- .../loadflow/server/service/LoadFlowWorkerService.java | 3 +-- .../gridsuite/loadflow/server/LoadFlowControllerTest.java | 8 -------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index fef3885d..cf37b701 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -147,8 +147,7 @@ private void cleanLoadFlowResultsAndPublishCancel(UUID resultUuid, String receiv private static LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo) { Optional currentLimits = violationInfo.getSide().equals("ONE") ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); - Double permanantLimit = currentLimits.get().getPermanentLimit(); - if (violationInfo.getValue() < permanantLimit) { + if (violationInfo.getValue() < currentLimits.get().getPermanentLimit()) { return null; } else { List temporaryLimits = currentLimits.get().getTemporaryLimits().stream().collect(Collectors.toList()); diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index 187e44f5..2344cbc0 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -147,13 +147,6 @@ private static void assertResultsEquals(LoadFlowResult result, org.gridsuite.loa } } - private static void assertLimitViolationsCalculatedOverloadEquals(List limitViolationsDto) { - assertEquals(60, limitViolationsDto.get(0).getActualOverload(), 0.01); - assertNull(limitViolationsDto.get(0).getUpComingOverload()); - assertNull(limitViolationsDto.get(1).getActualOverload()); - assertEquals(300, limitViolationsDto.get(1).getUpComingOverload(), 0.01); - } - private static void assertLimitViolationsEquals(List limitViolations, List limitViolationsDto, Network network) { assertEquals(limitViolations.size(), limitViolationsDto.size()); @@ -298,7 +291,6 @@ public void testGetLimitViolations() throws Exception { .andReturn(); List limitViolations = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference>() { }); assertLimitViolationsEquals(LimitViolationsMock.limitViolations, limitViolations, network); - //assertLimitViolationsCalculatedOverloadEquals(limitViolations); } } From 8f15370a83bfea036c12bd5d9a8a98b3ccfda128 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Thu, 16 Nov 2023 16:27:46 +0100 Subject: [PATCH 08/10] replace field acceptable_duration by actual_overload and add up_coming_overload field Signed-off-by: Maissa SOUISSI --- .../server/dto/LimitViolationInfos.java | 7 +++---- .../entities/LimitViolationEmbeddable.java | 10 ++++------ .../server/service/LoadFlowWorkerService.java | 18 ++++++++++-------- ...5257Z.xml => changelog_20231115T10528Z.xml} | 9 +++++---- .../db/changelog/db.changelog-master.yaml | 2 +- .../server/LoadFlowControllerTest.java | 1 - 6 files changed, 23 insertions(+), 24 deletions(-) rename src/main/resources/db/changelog/changesets/{changelog_20231115T105257Z.xml => changelog_20231115T10528Z.xml} (78%) diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java index 9d685cf1..9e7897a0 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java @@ -29,8 +29,6 @@ public class LimitViolationInfos { private String limitName; - private Integer acceptableDuration; - private Integer actualOverload; private Integer upComingOverload; @@ -42,7 +40,7 @@ public class LimitViolationInfos { private LimitViolationType limitType; public LimitViolationEmbeddable toEmbeddable() { - return new LimitViolationEmbeddable(subjectId, limit, limitName, acceptableDuration, value, side, limitType, actualOverload, upComingOverload); + return new LimitViolationEmbeddable(subjectId, limit, limitName, actualOverload, upComingOverload, value, side, limitType); } public static LimitViolationInfos toLimitViolationInfos(LimitViolationEmbeddable limitViolationEmbeddable) { @@ -50,7 +48,8 @@ public static LimitViolationInfos toLimitViolationInfos(LimitViolationEmbeddable .subjectId(limitViolationEmbeddable.getSubjectId()) .limit(limitViolationEmbeddable.getLimit()) .limitName(limitViolationEmbeddable.getLimitName()) - .acceptableDuration(limitViolationEmbeddable.getAcceptableDuration()) + .actualOverload(limitViolationEmbeddable.getActualOverload()) + .upComingOverload(limitViolationEmbeddable.getUpComingOverload()) .value(limitViolationEmbeddable.getValue()) .side(limitViolationEmbeddable.getSide()) .limitType(limitViolationEmbeddable.getLimitType()) diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java b/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java index 11e1386b..9b2973c0 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/LimitViolationEmbeddable.java @@ -34,7 +34,10 @@ public class LimitViolationEmbeddable { private String limitName; @Column - private Integer acceptableDuration; + private Integer actualOverload; + + @Column + private Integer upComingOverload; @Column(name = "value_") private Double value; @@ -46,9 +49,4 @@ public class LimitViolationEmbeddable { @Enumerated(EnumType.STRING) private LimitViolationType limitType; - @Column - private Integer actualOverload; - - @Column - private Integer upComingOverload; } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index cf37b701..73df5d5b 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -163,27 +163,28 @@ private static LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch public static Integer calculateUpcomingOverload(LimitViolationInfos limitViolationInfo) { if (limitViolationInfo.getValue() < limitViolationInfo.getLimit()) { - return limitViolationInfo.getAcceptableDuration(); + return limitViolationInfo.getUpComingOverload(); } return null; } public static Integer calculateActualOverload(LimitViolationInfos limitViolationInfo, Network network) { if (limitViolationInfo.getValue() > limitViolationInfo.getLimit()) { - return limitViolationInfo.getAcceptableDuration(); + return limitViolationInfo.getActualOverload(); } else { String equipmentId = limitViolationInfo.getSubjectId(); - Line line = network.getLine(equipmentId); - TwoWindingsTransformer twoWindingsTransformer = network.getTwoWindingsTransformer(equipmentId); LoadingLimits.TemporaryLimit tempLimit = null; + Line line = network.getLine(equipmentId); if (line != null) { tempLimit = handleEquipmentLimitViolation(line, limitViolationInfo); - } else if (twoWindingsTransformer != null) { - tempLimit = handleEquipmentLimitViolation(twoWindingsTransformer, limitViolationInfo); + } else { + TwoWindingsTransformer twoWindingsTransformer = network.getTwoWindingsTransformer(equipmentId); + if (twoWindingsTransformer != null) { + tempLimit = handleEquipmentLimitViolation(twoWindingsTransformer, limitViolationInfo); + } } return (tempLimit != null) ? tempLimit.getAcceptableDuration() : null; - } } @@ -216,7 +217,8 @@ private void cancelLoadFlowAsync(LoadFlowCancelContext cancelContext) { public static LimitViolationInfos toLimitViolationInfos(LimitViolation violation) { return LimitViolationInfos.builder() .subjectId(violation.getSubjectId()) - .acceptableDuration(violation.getAcceptableDuration()) + .actualOverload(violation.getAcceptableDuration()) + .upComingOverload(violation.getAcceptableDuration()) .limit(violation.getLimit()) .limitName(violation.getLimitName()) .value(violation.getValue()) diff --git a/src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml b/src/main/resources/db/changelog/changesets/changelog_20231115T10528Z.xml similarity index 78% rename from src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml rename to src/main/resources/db/changelog/changesets/changelog_20231115T10528Z.xml index 082f1120..d5e8f206 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20231115T105257Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20231115T10528Z.xml @@ -1,9 +1,10 @@ - - - - + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index d0dab4cd..2fab3fa4 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -7,5 +7,5 @@ databaseChangeLog: file: changesets/changelog_20231003T105819Z.xml relativeToChangelogFile: true - include: - file: changesets/changelog_20231115T105257Z.xml + file: changesets/changelog_20231115T10528Z.xml relativeToChangelogFile: true diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index 2344cbc0..f3a4f767 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -154,7 +154,6 @@ private static void assertLimitViolationsEquals(List limitViolat assertEquals(limitViolationsDto.get(i).getSubjectId(), limitViolations.get(i).getSubjectId()); assertEquals(limitViolationsDto.get(i).getLimit(), limitViolations.get(i).getLimit(), 0.01); assertEquals(limitViolationsDto.get(i).getLimitName(), limitViolations.get(i).getLimitName()); - assertEquals(Optional.ofNullable(limitViolationsDto.get(i).getAcceptableDuration()), Optional.ofNullable(limitViolations.get(i).getAcceptableDuration())); assertEquals(limitViolationsDto.get(i).getValue(), limitViolations.get(i).getValue(), 0.01); assertEquals(limitViolationsDto.get(i).getSide(), limitViolations.get(i).getSide() != null ? limitViolations.get(i).getSide().name() : ""); assertEquals(limitViolationsDto.get(i).getLimitType(), limitViolations.get(i).getLimitType()); From 0dc13d21b75cc99f2aff0a407c59bd22a019d655 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Mon, 20 Nov 2023 14:17:38 +0100 Subject: [PATCH 09/10] requested values Signed-off-by: Maissa SOUISSI --- .../server/dto/LimitViolationInfos.java | 12 +++--- .../server/service/LoadFlowWorkerService.java | 41 +++++++++---------- .../server/LoadFlowControllerTest.java | 4 +- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java index 9e7897a0..a75baea9 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/LimitViolationInfos.java @@ -29,9 +29,9 @@ public class LimitViolationInfos { private String limitName; - private Integer actualOverload; + private Integer actualOverloadDuration; - private Integer upComingOverload; + private Integer upComingOverloadDuration; private Double value; @@ -40,7 +40,7 @@ public class LimitViolationInfos { private LimitViolationType limitType; public LimitViolationEmbeddable toEmbeddable() { - return new LimitViolationEmbeddable(subjectId, limit, limitName, actualOverload, upComingOverload, value, side, limitType); + return new LimitViolationEmbeddable(subjectId, limit, limitName, actualOverloadDuration, upComingOverloadDuration, value, side, limitType); } public static LimitViolationInfos toLimitViolationInfos(LimitViolationEmbeddable limitViolationEmbeddable) { @@ -48,13 +48,11 @@ public static LimitViolationInfos toLimitViolationInfos(LimitViolationEmbeddable .subjectId(limitViolationEmbeddable.getSubjectId()) .limit(limitViolationEmbeddable.getLimit()) .limitName(limitViolationEmbeddable.getLimitName()) - .actualOverload(limitViolationEmbeddable.getActualOverload()) - .upComingOverload(limitViolationEmbeddable.getUpComingOverload()) + .actualOverloadDuration(limitViolationEmbeddable.getActualOverload()) + .upComingOverloadDuration(limitViolationEmbeddable.getUpComingOverload()) .value(limitViolationEmbeddable.getValue()) .side(limitViolationEmbeddable.getSide()) .limitType(limitViolationEmbeddable.getLimitType()) - .actualOverload(limitViolationEmbeddable.getActualOverload()) - .upComingOverload(limitViolationEmbeddable.getUpComingOverload()) .build(); } } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index 73df5d5b..9c9987b4 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -19,6 +19,7 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.security.LimitViolation; +import com.powsybl.security.LimitViolationType; import com.powsybl.security.Security; import org.apache.commons.lang3.StringUtils; import org.gridsuite.loadflow.server.dto.LimitViolationInfos; @@ -37,7 +38,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; -import java.util.stream.Collectors; import static org.gridsuite.loadflow.server.service.LoadFlowRunContext.buildParameters; import static org.gridsuite.loadflow.server.service.NotificationService.FAIL_MESSAGE; @@ -50,8 +50,6 @@ public class LoadFlowWorkerService { private static final Logger LOGGER = LoggerFactory.getLogger(LoadFlowWorkerService.class); private static final String LOAD_FLOW_TYPE_REPORT = "LoadFlow"; - private static final String CURRENT = "CURRENT"; - private Lock lockRunAndCancelLF = new ReentrantLock(); private ObjectMapper objectMapper; @@ -144,16 +142,15 @@ private void cleanLoadFlowResultsAndPublishCancel(UUID resultUuid, String receiv notificationService.publishStop(resultUuid, receiver); } - private static LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch branch, LimitViolationInfos violationInfo) { - - Optional currentLimits = violationInfo.getSide().equals("ONE") ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); - if (violationInfo.getValue() < currentLimits.get().getPermanentLimit()) { + private static LoadingLimits.TemporaryLimit getBranchLowerLimitViolation(Branch branch, LimitViolationInfos violationInfo) { + // limits are returned from the store by DESC duration / ASC value + Optional currentLimits = violationInfo.getSide().equals(Branch.Side.ONE.name()) ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); + if (!currentLimits.isPresent() || violationInfo.getValue() < currentLimits.get().getPermanentLimit()) { return null; } else { - List temporaryLimits = currentLimits.get().getTemporaryLimits().stream().collect(Collectors.toList()); - Optional nextTemporaryLimit = temporaryLimits.stream() - .filter(tl -> violationInfo.getValue() < tl.getValue()) - .findFirst(); + Optional nextTemporaryLimit = currentLimits.get().getTemporaryLimits().stream() + .filter(tl -> violationInfo.getValue() < tl.getValue()) + .findFirst(); if (nextTemporaryLimit.isPresent()) { return nextTemporaryLimit.get(); } @@ -161,27 +158,27 @@ private static LoadingLimits.TemporaryLimit handleEquipmentLimitViolation(Branch return null; } - public static Integer calculateUpcomingOverload(LimitViolationInfos limitViolationInfo) { + public static Integer calculateUpcomingOverloadDuration(LimitViolationInfos limitViolationInfo) { if (limitViolationInfo.getValue() < limitViolationInfo.getLimit()) { - return limitViolationInfo.getUpComingOverload(); + return limitViolationInfo.getUpComingOverloadDuration(); } return null; } - public static Integer calculateActualOverload(LimitViolationInfos limitViolationInfo, Network network) { + public static Integer calculateActualOverloadDuration(LimitViolationInfos limitViolationInfo, Network network) { if (limitViolationInfo.getValue() > limitViolationInfo.getLimit()) { - return limitViolationInfo.getActualOverload(); + return limitViolationInfo.getActualOverloadDuration(); } else { String equipmentId = limitViolationInfo.getSubjectId(); LoadingLimits.TemporaryLimit tempLimit = null; Line line = network.getLine(equipmentId); if (line != null) { - tempLimit = handleEquipmentLimitViolation(line, limitViolationInfo); + tempLimit = getBranchLowerLimitViolation(line, limitViolationInfo); } else { TwoWindingsTransformer twoWindingsTransformer = network.getTwoWindingsTransformer(equipmentId); if (twoWindingsTransformer != null) { - tempLimit = handleEquipmentLimitViolation(twoWindingsTransformer, limitViolationInfo); + tempLimit = getBranchLowerLimitViolation(twoWindingsTransformer, limitViolationInfo); } } return (tempLimit != null) ? tempLimit.getAcceptableDuration() : null; @@ -190,9 +187,9 @@ public static Integer calculateActualOverload(LimitViolationInfos limitViolation private List calculateOverloadLimitViolations(List limitViolationInfos, Network network) { for (LimitViolationInfos violationInfo : limitViolationInfos) { - if (violationInfo.getLimitName() != null && violationInfo.getLimitType().name().equals(CURRENT)) { - violationInfo.setActualOverload(calculateActualOverload(violationInfo, network)); - violationInfo.setUpComingOverload(calculateUpcomingOverload(violationInfo)); + if (violationInfo.getLimitName() != null && violationInfo.getLimitType() == LimitViolationType.CURRENT) { + violationInfo.setActualOverloadDuration(calculateActualOverloadDuration(violationInfo, network)); + violationInfo.setUpComingOverloadDuration(calculateUpcomingOverloadDuration(violationInfo)); } } return limitViolationInfos; @@ -217,8 +214,8 @@ private void cancelLoadFlowAsync(LoadFlowCancelContext cancelContext) { public static LimitViolationInfos toLimitViolationInfos(LimitViolation violation) { return LimitViolationInfos.builder() .subjectId(violation.getSubjectId()) - .actualOverload(violation.getAcceptableDuration()) - .upComingOverload(violation.getAcceptableDuration()) + .actualOverloadDuration(violation.getAcceptableDuration()) + .upComingOverloadDuration(violation.getAcceptableDuration()) .limit(violation.getLimit()) .limitName(violation.getLimitName()) .value(violation.getValue()) diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index f3a4f767..6e044589 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -157,8 +157,8 @@ private static void assertLimitViolationsEquals(List limitViolat assertEquals(limitViolationsDto.get(i).getValue(), limitViolations.get(i).getValue(), 0.01); assertEquals(limitViolationsDto.get(i).getSide(), limitViolations.get(i).getSide() != null ? limitViolations.get(i).getSide().name() : ""); assertEquals(limitViolationsDto.get(i).getLimitType(), limitViolations.get(i).getLimitType()); - assertEquals(limitViolationsDto.get(i).getActualOverload(), LoadFlowWorkerService.calculateActualOverload(LoadFlowWorkerService.toLimitViolationInfos(limitViolations.get(i)), network)); - assertEquals(limitViolationsDto.get(i).getUpComingOverload(), LoadFlowWorkerService.calculateUpcomingOverload(LoadFlowWorkerService.toLimitViolationInfos(limitViolations.get(i)))); + assertEquals(limitViolationsDto.get(i).getActualOverloadDuration(), LoadFlowWorkerService.calculateActualOverloadDuration(LoadFlowWorkerService.toLimitViolationInfos(limitViolations.get(i)), network)); + assertEquals(limitViolationsDto.get(i).getUpComingOverloadDuration(), LoadFlowWorkerService.calculateUpcomingOverloadDuration(LoadFlowWorkerService.toLimitViolationInfos(limitViolations.get(i)))); } } From 12fdb4124cd5ec4b7893dc240e62687e41728f93 Mon Sep 17 00:00:00 2001 From: Maissa SOUISSI Date: Mon, 20 Nov 2023 16:55:14 +0100 Subject: [PATCH 10/10] rename method Signed-off-by: Maissa SOUISSI --- .../loadflow/server/service/LoadFlowWorkerService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java index 9c9987b4..0714c35e 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowWorkerService.java @@ -142,7 +142,7 @@ private void cleanLoadFlowResultsAndPublishCancel(UUID resultUuid, String receiv notificationService.publishStop(resultUuid, receiver); } - private static LoadingLimits.TemporaryLimit getBranchLowerLimitViolation(Branch branch, LimitViolationInfos violationInfo) { + private static LoadingLimits.TemporaryLimit getBranchLimitViolationAboveCurrentValue(Branch branch, LimitViolationInfos violationInfo) { // limits are returned from the store by DESC duration / ASC value Optional currentLimits = violationInfo.getSide().equals(Branch.Side.ONE.name()) ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); if (!currentLimits.isPresent() || violationInfo.getValue() < currentLimits.get().getPermanentLimit()) { @@ -174,11 +174,11 @@ public static Integer calculateActualOverloadDuration(LimitViolationInfos limitV Line line = network.getLine(equipmentId); if (line != null) { - tempLimit = getBranchLowerLimitViolation(line, limitViolationInfo); + tempLimit = getBranchLimitViolationAboveCurrentValue(line, limitViolationInfo); } else { TwoWindingsTransformer twoWindingsTransformer = network.getTwoWindingsTransformer(equipmentId); if (twoWindingsTransformer != null) { - tempLimit = getBranchLowerLimitViolation(twoWindingsTransformer, limitViolationInfo); + tempLimit = getBranchLimitViolationAboveCurrentValue(twoWindingsTransformer, limitViolationInfo); } } return (tempLimit != null) ? tempLimit.getAcceptableDuration() : null;