Skip to content

Commit

Permalink
fix temporary limits modification (#277)
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab authored Jun 27, 2023
1 parent 60a82ed commit fa79326
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
public enum TemporaryLimitModificationType {
ADDED,
MODIFIED,
DELETED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.gridsuite.modification.server.modifications;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
Expand All @@ -16,6 +17,7 @@
import org.gridsuite.modification.server.dto.BranchModificationInfos;
import org.gridsuite.modification.server.dto.CurrentLimitsModificationInfos;
import org.gridsuite.modification.server.dto.CurrentTemporaryLimitModificationInfos;
import org.gridsuite.modification.server.dto.TemporaryLimitModificationType;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -90,10 +92,10 @@ protected void modifyCurrentLimits(CurrentLimitsModificationInfos currentLimitsI

protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimitsInfos, CurrentLimitsAdder limitsAdder,
CurrentLimits currentLimits, List<Report> limitsReports) {
// we create a mutable list of temporary limits to be able to remove the limits that are modified
List<LoadingLimits.TemporaryLimit> branchTemporaryLimits = null;
// we create a mutable list of temporary limits to be able to remove the limits that are modified in current modification
List<LoadingLimits.TemporaryLimit> branchTemporaryLimits = new ArrayList<>();
if (currentLimits != null) {
branchTemporaryLimits = new ArrayList<>(currentLimits.getTemporaryLimits());
branchTemporaryLimits.addAll(currentLimits.getTemporaryLimits());
}
List<Report> temporaryLimitsReports = new ArrayList<>();
for (CurrentTemporaryLimitModificationInfos limit : currentLimitsInfos.getTemporaryLimits()) {
Expand All @@ -104,10 +106,13 @@ protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimit
LoadingLimits.TemporaryLimit limitToModify = null;
if (currentLimits != null) {
limitToModify = currentLimits.getTemporaryLimit(limitAcceptableDuration);
// we remove the limit to modify from the list of temporary limits so we can log the remaining ones (deleted)
if (limitToModify != null && !limitToModify.getName().equals(limit.getName())) {
throw new PowsyblException("2temporary limits have the same duration " + limitAcceptableDuration);
}
// we remove the limit to modify from the list of temporary limits so we can get the list of temporary limits comming from previous modifications
branchTemporaryLimits.removeIf(temporaryLimit -> temporaryLimit.getAcceptableDuration() == limitAcceptableDuration);
}
if (limitToModify == null) {
if (limitToModify == null && limit.getModificationType() == TemporaryLimitModificationType.ADDED) {
temporaryLimitsReports.add(Report.builder().withKey("temporaryLimitAdded" + limit.getName())
.withDefaultMessage(" ${name} (${duration}) added with ${value}")
.withValue(NAME, limit.getName())
Expand All @@ -116,16 +121,33 @@ protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimit
.withSeverity(TypedValue.INFO_SEVERITY)
.build());

} else if (Double.compare(limitToModify.getValue(), limitValue) != 0) {
temporaryLimitsReports.add(Report.builder()
.withKey("temporaryLimitModified" + limit.getName())
.withDefaultMessage(" ${name} (${duration}) : ${oldValue} -> ${value}")
.withValue(NAME, limit.getName())
.withValue(DURATION, limitDurationToReport)
.withValue("value", limitValueToReport)
.withValue("oldValue", limitToModify.getValue() == Double.MAX_VALUE ? "no value" : String.valueOf(limitToModify.getValue()))
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
} else if (limitToModify != null) {
if (limit.getModificationType() == TemporaryLimitModificationType.DELETED) {
temporaryLimitsReports.add(Report.builder()
.withKey("temporaryLimitDeleted" + limit.getName())
.withDefaultMessage(" ${name} (${duration}) deleted")
.withValue(NAME, limit.getName())
.withValue(DURATION, limitDurationToReport)
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
continue;
} else if (Double.compare(limitToModify.getValue(), limitValue) != 0 && limit.getModificationType() != null) {
temporaryLimitsReports.add(Report.builder()
.withKey("temporaryLimitModified" + limit.getName())
.withDefaultMessage(" ${name} (${duration}) : ${oldValue} -> ${value}")
.withValue(NAME, limit.getName())
.withValue(DURATION, limitDurationToReport)
.withValue("value", limitValueToReport)
.withValue("oldValue",
limitToModify.getValue() == Double.MAX_VALUE ? "no value"
: String.valueOf(limitToModify.getValue()))
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
} else {
limitValue = limitToModify.getValue();
}
} else {
continue;
}
limitsAdder
.beginTemporaryLimit()
Expand All @@ -134,15 +156,15 @@ protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimit
.setAcceptableDuration(limitAcceptableDuration)
.endTemporaryLimit();
}
if (branchTemporaryLimits != null) {
// we add the temporary limits comming from previous modifications
if (!branchTemporaryLimits.isEmpty()) {
for (LoadingLimits.TemporaryLimit limit : branchTemporaryLimits) {
temporaryLimitsReports.add(Report.builder()
.withKey("temporaryLimitDeleted" + limit.getName())
.withDefaultMessage(" ${name} (${duration}) deleted")
.withValue(NAME, limit.getName())
.withValue(DURATION, limit.getAcceptableDuration() == Integer.MAX_VALUE ? " " : String.valueOf(limit.getAcceptableDuration()))
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
limitsAdder
.beginTemporaryLimit()
.setName(limit.getName())
.setValue(limit.getValue())
.setAcceptableDuration(limit.getAcceptableDuration())
.endTemporaryLimit();
}
}
if (!temporaryLimitsReports.isEmpty()) {
Expand All @@ -162,5 +184,6 @@ protected boolean characteristicsModified(BranchModificationInfos branchModifica
&& branchModificationInfos.getSeriesResistance().getValue() != null;
}

protected abstract void modifyCharacteristics(Branch<?> branch, BranchModificationInfos branchModificationInfos, Reporter subReporter);
protected abstract void modifyCharacteristics(Branch<?> branch, BranchModificationInfos branchModificationInfos,
Reporter subReporter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected ModificationInfos buildModification() {
.acceptableDuration(null)
.name("name31")
.value(null)
.modificationType(TemporaryLimitModificationType.ADDED)
.build()))
.build())
.currentLimits2(CurrentLimitsModificationInfos.builder()
Expand All @@ -56,6 +57,7 @@ protected ModificationInfos buildModification() {
.acceptableDuration(32)
.name("name32")
.value(42.0)
.modificationType(TemporaryLimitModificationType.ADDED)
.build()))
.build())
.build();
Expand Down Expand Up @@ -296,8 +298,26 @@ public void testTemporaryLimitsModification() {
.setValue(15.0)
.endTemporaryLimit()
.add();
LineModificationInfos lineModificationInfos = (LineModificationInfos) buildModification();

LineModificationInfos lineModificationInfos = LineModificationInfos.builder().equipmentId("line1")
.equipmentName(new AttributeModification<>("LineModified", OperationType.SET))
.currentLimits1(CurrentLimitsModificationInfos.builder()
.temporaryLimits(List.of(CurrentTemporaryLimitModificationInfos.builder()
.acceptableDuration(null)
.name("name31")
.value(22.0)
.modificationType(TemporaryLimitModificationType.MODIFIED)
.build()))
.build())
.currentLimits2(CurrentLimitsModificationInfos.builder()
.permanentLimit(22.0)
.temporaryLimits(List.of(CurrentTemporaryLimitModificationInfos.builder()
.acceptableDuration(33)
.name("name33")
.value(15.0)
.modificationType(TemporaryLimitModificationType.DELETED)
.build()))
.build())
.build();
String modificationToCreateJson = mapper.writeValueAsString(lineModificationInfos);

mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected ModificationInfos buildModification() {
.acceptableDuration(null)
.name("name31")
.value(null)
.modificationType(TemporaryLimitModificationType.ADDED)
.build()))
.build())
.currentLimits2(CurrentLimitsModificationInfos.builder()
Expand All @@ -63,6 +64,7 @@ protected ModificationInfos buildModification() {
.acceptableDuration(32)
.name("name32")
.value(42.0)
.modificationType(TemporaryLimitModificationType.ADDED)
.build()))
.build())
.build();
Expand Down

0 comments on commit fa79326

Please sign in to comment.