-
Notifications
You must be signed in to change notification settings - Fork 0
New fields in SA results - limit violations #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
*/ | ||
package org.gridsuite.securityanalysis.server.entities; | ||
|
||
import com.powsybl.iidm.network.ThreeSides; | ||
import com.powsybl.iidm.network.*; | ||
import com.powsybl.iidm.network.util.LimitViolationUtils; | ||
import com.powsybl.security.LimitViolation; | ||
import com.powsybl.security.LimitViolationType; | ||
import jakarta.persistence.*; | ||
|
@@ -16,6 +17,8 @@ | |
import lombok.experimental.FieldNameConstants; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.util.Iterator; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
/** | ||
|
@@ -40,8 +43,12 @@ public abstract class AbstractLimitViolationEntity { | |
@Column(name = "limitValue") | ||
private double limit; | ||
|
||
private Double patlLimit; | ||
|
||
private String limitName; | ||
|
||
private String nextLimitName; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private LimitViolationType limitType; | ||
|
||
|
@@ -58,12 +65,67 @@ public abstract class AbstractLimitViolationEntity { | |
@Column(name = "loading") | ||
private Double loading; | ||
|
||
private Double patlLoading; | ||
|
||
@Column | ||
private String locationId; | ||
|
||
public static Double computeLoading(LimitViolation limitViolation) { | ||
return LimitViolationType.CURRENT.equals(limitViolation.getLimitType()) | ||
? 100 * limitViolation.getValue() / limitViolation.getLimit() | ||
protected static Double computeLoading(LimitViolation limitViolation, Double limit) { | ||
return LimitViolationType.CURRENT.equals(limitViolation.getLimitType()) && limit != null | ||
? 100 * limitViolation.getValue() / limit | ||
: null; | ||
} | ||
|
||
protected static Double getPatlLimit(LimitViolation limitViolation, Network network) { | ||
String equipmentId = limitViolation.getSubjectId(); | ||
Branch<?> branch = network.getBranch(equipmentId); | ||
ThreeSides limitViolationSide = limitViolation.getSide(); | ||
if (branch == null || limitViolationSide == null) { | ||
return null; | ||
} | ||
|
||
Optional<CurrentLimits> currentLimits = limitViolationSide.name().equals(TwoSides.ONE.name()) ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); | ||
|
||
if (currentLimits.isPresent()) { | ||
return currentLimits.get().getPermanentLimit(); | ||
} | ||
return null; | ||
} | ||
|
||
protected static String getNextLimitName(LimitViolation limitViolation, Network network) { | ||
String equipmentId = limitViolation.getSubjectId(); | ||
Branch<?> branch = network.getBranch(equipmentId); | ||
if (branch == null) { | ||
return null; | ||
} | ||
LoadingLimits.TemporaryLimit temporaryLimit = getNextTemporaryLimit(branch, limitViolation); | ||
return temporaryLimit != null ? temporaryLimit.getName() : null; | ||
} | ||
|
||
private static LoadingLimits.TemporaryLimit getNextTemporaryLimit(Branch<?> branch, LimitViolation limitViolation) { | ||
// limits are returned from the store by DESC duration / ASC value | ||
ThreeSides limitViolationSide = limitViolation.getSide(); | ||
String limitName = limitViolation.getLimitName(); | ||
if (limitViolationSide == null || limitName == null) { | ||
return null; | ||
} | ||
|
||
Optional<CurrentLimits> currentLimits = limitViolationSide.name().equals(TwoSides.ONE.name()) ? branch.getCurrentLimits1() : branch.getCurrentLimits2(); | ||
|
||
if (currentLimits.isEmpty()) { | ||
return null; | ||
} | ||
|
||
if (limitName.equals(LimitViolationUtils.PERMANENT_LIMIT_NAME)) { | ||
return currentLimits.get().getTemporaryLimits().stream().findFirst().orElse(null); | ||
|
||
} | ||
|
||
Iterator<LoadingLimits.TemporaryLimit> temporaryLimitIterator = currentLimits.get().getTemporaryLimits().iterator(); | ||
while (temporaryLimitIterator.hasNext()) { | ||
LoadingLimits.TemporaryLimit currentTemporaryLimit = temporaryLimitIterator.next(); | ||
if (currentTemporaryLimit.getName().equals(limitViolation.getLimitName())) { | ||
return temporaryLimitIterator.hasNext() ? temporaryLimitIterator.next() : null; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ public static PreContingencyLimitViolationEntity toEntity(Network network, Limit | |
.limitReduction(limitViolation.getLimitReduction()) | ||
.value(limitViolation.getValue()) | ||
.side(limitViolation.getSide()) | ||
.loading(computeLoading(limitViolation)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want the same changes for N results? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. N results will be chaged on other US |
||
.loading(computeLoading(limitViolation, limitViolation.getLimit())) | ||
.locationId(ComputationResultUtils.getViolationLocationId(limitViolation, network)) | ||
.build(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
<changeSet author="lesaulnierkev (generated)" id="1756904408172-1"> | ||
<addColumn tableName="contingency_limit_violation"> | ||
<column name="next_limit_name" type="varchar(255)"/> | ||
</addColumn> | ||
</changeSet> | ||
<changeSet author="lesaulnierkev (generated)" id="1756904408172-2"> | ||
<addColumn tableName="pre_contingency_limit_violation"> | ||
<column name="next_limit_name" type="varchar(255)"/> | ||
</addColumn> | ||
</changeSet> | ||
<changeSet author="lesaulnierkev (generated)" id="1756904408172-3"> | ||
<addColumn tableName="contingency_limit_violation"> | ||
<column name="patl_limit" type="float(53)"/> | ||
</addColumn> | ||
</changeSet> | ||
<changeSet author="lesaulnierkev (generated)" id="1756904408172-4"> | ||
<addColumn tableName="pre_contingency_limit_violation"> | ||
<column name="patl_limit" type="float(53)"/> | ||
</addColumn> | ||
</changeSet> | ||
<changeSet author="lesaulnierkev (generated)" id="1756904408172-7"> | ||
<addColumn tableName="contingency_limit_violation"> | ||
<column name="patl_loading" type="float(53)"/> | ||
</addColumn> | ||
</changeSet> | ||
<changeSet author="lesaulnierkev (generated)" id="1756904408172-8"> | ||
<addColumn tableName="pre_contingency_limit_violation"> | ||
<column name="patl_loading" type="float(53)"/> | ||
</addColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
|
||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.gridsuite.securityanalysis.server; | ||
|
||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.TwoSides; | ||
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; | ||
import com.powsybl.iidm.network.util.LimitViolationUtils; | ||
import com.powsybl.security.LimitViolation; | ||
import com.powsybl.security.LimitViolationType; | ||
import org.gridsuite.securityanalysis.server.entities.ContingencyLimitViolationEntity; | ||
import org.gridsuite.securityanalysis.server.entities.SubjectLimitViolationEntity; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Kevin Le Saulnier <kevin.lesaulnier at rte-france.com> | ||
*/ | ||
@SpringBootTest | ||
class ContingencyLimitViolationTest { | ||
|
||
@Test | ||
void testContingencyLimitViolationEntityNewFields() { | ||
testContingencyLimitViolationMapping("10'", 10 * 60, 1200, 1250, TwoSides.TWO, "1'", 1100); | ||
} | ||
|
||
@Test | ||
void testContingencyLimitViolationEntityNewFieldsWithPermanentLimitReached() { | ||
testContingencyLimitViolationMapping(LimitViolationUtils.PERMANENT_LIMIT_NAME, Integer.MAX_VALUE, 1100, 1150, TwoSides.TWO, "10'", 1100); | ||
} | ||
|
||
@Test | ||
void testContingencyLimitViolationEntityNewFieldsWithPermanentLimitReachedAndNoTemporaryLimit() { | ||
testContingencyLimitViolationMapping(LimitViolationUtils.PERMANENT_LIMIT_NAME, Integer.MAX_VALUE, 500, 1000, TwoSides.ONE, null, 500); | ||
} | ||
|
||
@Test | ||
void testContingencyLimitViolationEntityNewFieldsWithLastLimitReached() { | ||
testContingencyLimitViolationMapping("N/A", 0, 1100, 3000, TwoSides.TWO, null, 1100); | ||
} | ||
|
||
private void testContingencyLimitViolationMapping(String limitName, int acceptableDuration, double limit, double value, TwoSides side, String expectedNextLimitName, long expectedPatlLimit) { | ||
Network network = EurostagTutorialExample1Factory.createWithFixedCurrentLimits(); | ||
LimitViolation limitViolation = new LimitViolation("NHV1_NHV2_1", "NHV1_NHV2_1_name", LimitViolationType.CURRENT, limitName, acceptableDuration, limit, 1, value, side); | ||
|
||
SubjectLimitViolationEntity subjectLimitViolationEntity = new SubjectLimitViolationEntity("NHV1_NHV2_1", "NHV1_NHV2_1_name"); | ||
|
||
ContingencyLimitViolationEntity contingencyLimitViolationEntity = ContingencyLimitViolationEntity.toEntity(network, limitViolation, subjectLimitViolationEntity); | ||
|
||
assertEquals(expectedNextLimitName, contingencyLimitViolationEntity.getNextLimitName()); | ||
assertEquals(expectedPatlLimit, contingencyLimitViolationEntity.getPatlLimit()); | ||
assertEquals(100 * limitViolation.getValue() / contingencyLimitViolationEntity.getPatlLimit(), contingencyLimitViolationEntity.getPatlLoading()); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: if you're dealing with branches, you could have used TwoSides
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed