Skip to content

Commit 4125399

Browse files
authored
Add location id to the SA result (#158)
Signed-off-by: AAJELLAL <[email protected]>
1 parent e2cd896 commit 4125399

26 files changed

+244
-164
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@
258258
<scope>test</scope>
259259
</dependency>
260260
</dependencies>
261-
</project>
261+
</project>

src/main/java/org/gridsuite/securityanalysis/server/dto/LimitViolationDTO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class LimitViolationDTO {
2626
private double limitReduction;
2727
private double value;
2828
private Double loading;
29+
private String locationId;
2930

3031
public static LimitViolationDTO toDto(AbstractLimitViolationEntity limitViolation) {
3132
return LimitViolationDTO.builder()
@@ -37,11 +38,13 @@ public static LimitViolationDTO toDto(AbstractLimitViolationEntity limitViolatio
3738
.limitReduction(limitViolation.getLimitReduction())
3839
.value(limitViolation.getValue())
3940
.loading(limitViolation.getLoading())
41+
.locationId(limitViolation.getLocationId())
4042
.build();
4143
}
4244

4345
public List<String> toCsvRow(Map<String, String> translations) {
4446
List<String> csvRow = new ArrayList<>();
47+
csvRow.add(this.getLocationId());
4548
csvRow.add(this.getLimitType() != null ? CsvExportUtils.translate(this.getLimitType().name(), translations) : "");
4649
csvRow.add(CsvExportUtils.replaceNullWithEmptyString(CsvExportUtils.translate(this.getLimitName(), translations)));
4750
csvRow.add(Double.toString(this.getLimit()));

src/main/java/org/gridsuite/securityanalysis/server/dto/PreContingencyLimitViolationResultDTO.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lombok.Builder;
1212
import lombok.Getter;
1313
import lombok.NoArgsConstructor;
14+
import lombok.experimental.FieldNameConstants;
1415
import org.gridsuite.securityanalysis.server.entities.PreContingencyLimitViolationEntity;
1516

1617
import java.util.List;
@@ -21,6 +22,7 @@
2122
@AllArgsConstructor
2223
@NoArgsConstructor
2324
@Builder
25+
@FieldNameConstants
2426
public class PreContingencyLimitViolationResultDTO {
2527

2628
private String subjectId;
@@ -31,7 +33,6 @@ public static PreContingencyLimitViolationResultDTO toDto(PreContingencyLimitVio
3133
String subjectId = preContingencyLimitViolation.getSubjectLimitViolation() != null
3234
? preContingencyLimitViolation.getSubjectLimitViolation().getSubjectId()
3335
: null;
34-
3536
return PreContingencyLimitViolationResultDTO.builder()
3637
.subjectId(subjectId)
3738
.status(preContingencyLimitViolation.getResult().getPreContingencyStatus())
@@ -40,7 +41,7 @@ public static PreContingencyLimitViolationResultDTO toDto(PreContingencyLimitVio
4041
}
4142

4243
public List<String> toCsvRow(Map<String, String> translations) {
43-
List<String> csvRow = List.of(this.getSubjectId());
44+
List<String> csvRow = List.of();
4445

4546
if (this.getLimitViolation() != null) {
4647
return Stream.concat(csvRow.stream(), this.getLimitViolation().toCsvRow(translations).stream()).toList();

src/main/java/org/gridsuite/securityanalysis/server/dto/SubjectLimitViolationDTO.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
@Builder
2222
public class SubjectLimitViolationDTO {
2323
private String subjectId;
24-
2524
private LimitViolationDTO limitViolation;
2625

2726
public static SubjectLimitViolationDTO toDto(ContingencyLimitViolationEntity limitViolation) {
2827
String subjectId = limitViolation.getSubjectLimitViolation() != null
2928
? limitViolation.getSubjectLimitViolation().getSubjectId()
3029
: null;
31-
3230
return SubjectLimitViolationDTO.builder()
3331
.subjectId(subjectId)
3432
.limitViolation(LimitViolationDTO.toDto(limitViolation))

src/main/java/org/gridsuite/securityanalysis/server/dto/SubjectLimitViolationResultDTO.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@NoArgsConstructor
2828
public class SubjectLimitViolationResultDTO {
2929
private String subjectId;
30-
3130
private List<ContingencyLimitViolationDTO> contingencies;
3231

3332
public static SubjectLimitViolationResultDTO toDto(SubjectLimitViolationEntity subjectLimitViolation) {

src/main/java/org/gridsuite/securityanalysis/server/entities/AbstractLimitViolationEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public abstract class AbstractLimitViolationEntity {
5858
@Column(name = "loading")
5959
private Double loading;
6060

61+
@Column
62+
private String locationId;
63+
6164
public static Double computeLoading(LimitViolation limitViolation) {
6265
return LimitViolationType.CURRENT.equals(limitViolation.getLimitType())
6366
? 100 * limitViolation.getValue() / limitViolation.getLimit()

src/main/java/org/gridsuite/securityanalysis/server/entities/ContingencyEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.gridsuite.securityanalysis.server.entities;
88

9+
import com.powsybl.iidm.network.Network;
910
import com.powsybl.security.results.PostContingencyResult;
1011
import jakarta.persistence.*;
1112
import lombok.Getter;
@@ -41,7 +42,6 @@ public ContingencyEntity(String contingencyId, String status, List<ContingencyEl
4142
private UUID uuid;
4243

4344
private String contingencyId;
44-
4545
@Setter
4646
@ManyToOne(fetch = FetchType.LAZY)
4747
private SecurityAnalysisResultEntity result;
@@ -64,11 +64,11 @@ private void setContingencyLimitViolations(List<ContingencyLimitViolationEntity>
6464
}
6565
}
6666

67-
public static ContingencyEntity toEntity(PostContingencyResult postContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
67+
public static ContingencyEntity toEntity(Network network, PostContingencyResult postContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
6868
List<ContingencyElementEmbeddable> contingencyElements = postContingencyResult.getContingency().getElements().stream().map(contingencyElement -> ContingencyElementEmbeddable.toEntity(contingencyElement)).collect(Collectors.toList());
6969

7070
List<ContingencyLimitViolationEntity> contingencyLimitViolations = postContingencyResult.getLimitViolationsResult().getLimitViolations().stream()
71-
.map(limitViolation -> ContingencyLimitViolationEntity.toEntity(limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId())))
71+
.map(limitViolation -> ContingencyLimitViolationEntity.toEntity(network, limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId())))
7272
.collect(Collectors.toList());
7373
return new ContingencyEntity(postContingencyResult.getContingency().getId(), postContingencyResult.getStatus().name(), contingencyElements, contingencyLimitViolations);
7474
}

src/main/java/org/gridsuite/securityanalysis/server/entities/ContingencyLimitViolationEntity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77
package org.gridsuite.securityanalysis.server.entities;
88

9+
import com.powsybl.iidm.network.Network;
910
import com.powsybl.security.LimitViolation;
11+
import com.powsybl.ws.commons.computation.utils.ComputationResultUtils;
1012
import jakarta.persistence.*;
1113
import lombok.*;
1214
import lombok.experimental.FieldNameConstants;
@@ -30,7 +32,7 @@ public class ContingencyLimitViolationEntity extends AbstractLimitViolationEntit
3032
@Setter
3133
private ContingencyEntity contingency;
3234

33-
public static ContingencyLimitViolationEntity toEntity(LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
35+
public static ContingencyLimitViolationEntity toEntity(Network network, LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
3436
ContingencyLimitViolationEntity contingencyLimitViolationEntity = ContingencyLimitViolationEntity.builder()
3537
.limit(limitViolation.getLimit())
3638
.limitName(limitViolation.getLimitName())
@@ -40,6 +42,7 @@ public static ContingencyLimitViolationEntity toEntity(LimitViolation limitViola
4042
.value(limitViolation.getValue())
4143
.side(limitViolation.getSide())
4244
.loading(computeLoading(limitViolation))
45+
.locationId(ComputationResultUtils.getViolationLocationId(limitViolation, network))
4346
.subjectLimitViolation(subjectLimitViolation)
4447
.build();
4548

src/main/java/org/gridsuite/securityanalysis/server/entities/PreContingencyLimitViolationEntity.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
*/
77
package org.gridsuite.securityanalysis.server.entities;
88

9+
import com.powsybl.iidm.network.Network;
910
import com.powsybl.security.LimitViolation;
1011
import com.powsybl.security.results.PreContingencyResult;
11-
import jakarta.persistence.Entity;
12-
import jakarta.persistence.FetchType;
13-
import jakarta.persistence.ManyToOne;
14-
import jakarta.persistence.Table;
12+
import com.powsybl.ws.commons.computation.utils.ComputationResultUtils;
13+
import jakarta.persistence.*;
1514
import lombok.Data;
1615
import lombok.Getter;
1716
import lombok.NoArgsConstructor;
@@ -35,16 +34,15 @@
3534
@FieldNameConstants
3635
@Table(name = "pre_contingency_limit_violation")
3736
public class PreContingencyLimitViolationEntity extends AbstractLimitViolationEntity {
38-
3937
@ManyToOne(fetch = FetchType.LAZY)
4038
@Setter
4139
SecurityAnalysisResultEntity result;
4240

43-
public static List<PreContingencyLimitViolationEntity> toEntityList(PreContingencyResult preContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
44-
return preContingencyResult.getLimitViolationsResult().getLimitViolations().stream().map(limitViolation -> toEntity(limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId()))).collect(Collectors.toList());
41+
public static List<PreContingencyLimitViolationEntity> toEntityList(Network network, PreContingencyResult preContingencyResult, Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId) {
42+
return preContingencyResult.getLimitViolationsResult().getLimitViolations().stream().map(limitViolation -> toEntity(network, limitViolation, subjectLimitViolationsBySubjectId.get(limitViolation.getSubjectId()))).collect(Collectors.toList());
4543
}
4644

47-
public static PreContingencyLimitViolationEntity toEntity(LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
45+
public static PreContingencyLimitViolationEntity toEntity(Network network, LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolation) {
4846
return PreContingencyLimitViolationEntity.builder()
4947
.subjectLimitViolation(subjectLimitViolation)
5048
.limit(limitViolation.getLimit())
@@ -55,6 +53,7 @@ public static PreContingencyLimitViolationEntity toEntity(LimitViolation limitVi
5553
.value(limitViolation.getValue())
5654
.side(limitViolation.getSide())
5755
.loading(computeLoading(limitViolation))
56+
.locationId(ComputationResultUtils.getViolationLocationId(limitViolation, network))
5857
.build();
5958
}
6059
}

src/main/java/org/gridsuite/securityanalysis/server/entities/SecurityAnalysisResultEntity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.gridsuite.securityanalysis.server.entities;
88

9+
import com.powsybl.iidm.network.Network;
910
import com.powsybl.security.SecurityAnalysisResult;
1011
import jakarta.persistence.*;
1112
import lombok.*;
@@ -52,17 +53,17 @@ public SecurityAnalysisResultEntity(UUID id) {
5253
this.id = id;
5354
}
5455

55-
public static SecurityAnalysisResultEntity toEntity(UUID resultUuid, SecurityAnalysisResult securityAnalysisResult, SecurityAnalysisStatus securityAnalysisStatus) {
56+
public static SecurityAnalysisResultEntity toEntity(Network network, UUID resultUuid, SecurityAnalysisResult securityAnalysisResult, SecurityAnalysisStatus securityAnalysisStatus) {
5657
Map<String, SubjectLimitViolationEntity> subjectLimitViolationsBySubjectId = getUniqueSubjectLimitViolationsFromResult(securityAnalysisResult)
5758
.stream().collect(Collectors.toMap(
5859
SubjectLimitViolationEntity::getSubjectId,
5960
subjectLimitViolation -> subjectLimitViolation)
6061
);
6162

6263
List<ContingencyEntity> contingencies = securityAnalysisResult.getPostContingencyResults().stream()
63-
.map(postContingencyResult -> ContingencyEntity.toEntity(postContingencyResult, subjectLimitViolationsBySubjectId)).collect(Collectors.toList());
64+
.map(postContingencyResult -> ContingencyEntity.toEntity(network, postContingencyResult, subjectLimitViolationsBySubjectId)).collect(Collectors.toList());
6465

65-
List<PreContingencyLimitViolationEntity> preContingencyLimitViolations = PreContingencyLimitViolationEntity.toEntityList(securityAnalysisResult.getPreContingencyResult(), subjectLimitViolationsBySubjectId);
66+
List<PreContingencyLimitViolationEntity> preContingencyLimitViolations = PreContingencyLimitViolationEntity.toEntityList(network, securityAnalysisResult.getPreContingencyResult(), subjectLimitViolationsBySubjectId);
6667

6768
List<SubjectLimitViolationEntity> subjectLimitViolations = Stream.concat(
6869
contingencies.stream().flatMap(c -> c.getContingencyLimitViolations().stream()),

0 commit comments

Comments
 (0)