Skip to content
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

Add collection impact #356

Merged
merged 46 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
54b0b69
feat(): Add collection impact
sBouzols Oct 24, 2023
78094aa
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Oct 24, 2023
ae9d0a7
feat(): Replace collection factor by collection threshold to avoid ge…
sBouzols Oct 26, 2023
ca791c3
docs(): add author infos
sBouzols Nov 10, 2023
59c6748
Merge remote-tracking branch 'origin/main' into feat_add_collection_i…
sBouzols Jan 18, 2024
882c5d5
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Feb 7, 2024
6ac8d31
doc(): comment fix
sBouzols Feb 7, 2024
c223c9c
test(): fix simple TU without spring initialization with @Value
sBouzols Feb 7, 2024
e4602b4
test(): improve testElementImpacts to check collection impacted equip…
sBouzols Feb 7, 2024
85a8ab6
code smell fix
sBouzols Feb 7, 2024
eaf9180
tests(): Add assertResultImpacts for some TUs
sBouzols Feb 9, 2024
e1fa819
docs(): Add comment over a strange test case
sBouzols Feb 9, 2024
2d86915
Feat(): Add collection impact for substations
sBouzols Feb 9, 2024
c092cea
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Feb 13, 2024
b68c10e
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Feb 13, 2024
74cd686
fix() from review
sBouzols Feb 14, 2024
9751dcb
doc(): don't change license year for now
sBouzols Feb 15, 2024
3c2d6c0
refactor(): lombok annotations
sBouzols Feb 15, 2024
9d9870a
refactor(): getImpactedSubstationsIds
sBouzols Feb 15, 2024
d1ced7d
refactor(): remove collection-threshold from powsybl-ws scope
sBouzols Feb 15, 2024
84d2939
refactor(): rename networkSimpleElementImpacts to networkSimpleImpacts
sBouzols Feb 15, 2024
79c6278
refactor(): assertThat containsAll
sBouzols Feb 15, 2024
e91c685
remove breaking line
sBouzols Feb 15, 2024
5bb4253
remove order for assertResultImpacts
sBouzols Feb 15, 2024
2a0ca72
remove order in assert for formula modif
sBouzols Feb 15, 2024
b737b34
fix(): from review
sBouzols Feb 20, 2024
5e80d08
refactor(): for loop instead of Collection.forEach from review
sBouzols Feb 20, 2024
74aee50
Merge remote-tracking branch 'origin/main' into feat_add_collection_i…
sBouzols Feb 20, 2024
9e18860
checkstyle
sBouzols Feb 20, 2024
986ec7d
refactor(): from review
sBouzols Feb 27, 2024
b58f584
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Feb 28, 2024
b3bec94
fix(): fro review
sBouzols Feb 28, 2024
b5e46eb
Merge branch 'feat_add_collection_impact_2' of https://github.com/gri…
sBouzols Feb 28, 2024
64b4803
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Mar 1, 2024
a76e475
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Mar 1, 2024
d2d333f
revert changes over appclication-default
sBouzols Mar 1, 2024
62bf00b
typo
sBouzols Mar 1, 2024
ae536d2
refactor(): rename collectionImpactElementTypes to elementTypes
sBouzols Mar 1, 2024
467d5aa
fix from review
sBouzols Mar 1, 2024
35a2f88
Merge branch 'main' into feat_add_collection_impact_2
sBouzols Mar 4, 2024
9fb737d
fix from review
sBouzols Mar 4, 2024
dd661dd
Add TU for coverage
sBouzols Mar 4, 2024
7b93a6e
fix TU
sBouzols Mar 4, 2024
21c9d52
Fix 'collectionThreshold' not injected
Mar 4, 2024
a9624ab
Merge branch 'feat_add_collection_impact_2' of https://github.com/gri…
Mar 4, 2024
bd21570
Fix assertResultImpacts
Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import org.gridsuite.modification.server.impacts.AbstractBaseImpact;
import org.gridsuite.modification.server.impacts.AbstractBaseImpact.ImpactType;
import org.gridsuite.modification.server.impacts.SimpleElementImpact;

import java.util.List;
Expand All @@ -18,6 +20,7 @@

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
@Builder
@Data
Expand Down Expand Up @@ -47,10 +50,12 @@ public ApplicationStatus max(ApplicationStatus other) {

@Schema(description = "Network modification impacts")
@Builder.Default
private List<SimpleElementImpact> networkImpacts = List.of();
private List<AbstractBaseImpact> networkImpacts = List.of();

public Set<String> getImpactedSubstationsIds() {
return networkImpacts.stream().flatMap(impact -> impact.getSubstationIds().stream()).collect(Collectors.toCollection(TreeSet::new));
return networkImpacts.stream()
.filter(impact -> impact.getType() == ImpactType.SIMPLE)
.flatMap(impact -> ((SimpleElementImpact) impact).getSubstationIds().stream())
.collect(Collectors.toCollection(TreeSet::new)); // using TreeSet to keep natural order
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
Copyright (c) 2024, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
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.modification.server.impacts;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.powsybl.iidm.network.IdentifiableType;

import lombok.*;
ne0ds marked this conversation as resolved.
Show resolved Hide resolved
import lombok.experimental.SuperBuilder;

/**
* This class describes a base impact
* This is the base type of all network impacts
*
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true
)
@JsonSubTypes({
@JsonSubTypes.Type(value = SimpleElementImpact.class, name = "SIMPLE"),
@JsonSubTypes.Type(value = CollectionElementImpact.class, name = "COLLECTION")
})
@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public abstract class AbstractBaseImpact {


public enum ImpactType {
sBouzols marked this conversation as resolved.
Show resolved Hide resolved
SIMPLE,
COLLECTION
}

@Setter(AccessLevel.NONE)
private ImpactType type;

private IdentifiableType elementType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
Copyright (c) 2024, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
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.modification.server.impacts;

import lombok.*;
ne0ds marked this conversation as resolved.
Show resolved Hide resolved
import lombok.experimental.SuperBuilder;

/**
* This class describes a collection type network impact
* This type of network impact describes an impact on multiple items of the same IdentifiableType
*
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
@SuperBuilder
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CollectionElementImpact extends AbstractBaseImpact {
@Override
public ImpactType getType() {
return ImpactType.COLLECTION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,41 @@
*/
package org.gridsuite.modification.server.impacts;

import com.powsybl.iidm.network.IdentifiableType;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.Set;

/**
* This class describes an element type network impact
* This type of network impact only describes an individual impacted item and the list of associated subtractions
* This type of network impact only describes an individual impacted item and the list of associated substations
*
* @author Slimane Amar <slimane.amar at rte-france.com>
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Setter
@Getter
@Builder
@SuperBuilder
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ToString
public class SimpleElementImpact {
sBouzols marked this conversation as resolved.
Show resolved Hide resolved
@EqualsAndHashCode(callSuper = true)
public class SimpleElementImpact extends AbstractBaseImpact {

public enum SimpleImpactType {
CREATION,
MODIFICATION,
DELETION
}

private SimpleImpactType impactType;
private SimpleImpactType simpleImpactType;

/** The impacted element ID */
private String elementId;

private IdentifiableType elementType;

/** The impacted substations IDs */
private Set<String> substationIds;

@Override
public ImpactType getType() {
return ImpactType.SIMPLE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import org.gridsuite.modification.server.dto.NetworkModificationResult.ApplicationStatus;
import org.gridsuite.modification.server.dto.ReportInfos;
import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService;
import org.gridsuite.modification.server.impacts.AbstractBaseImpact;
import org.gridsuite.modification.server.service.FilterService;
import org.gridsuite.modification.server.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -50,42 +52,52 @@ public class NetworkModificationApplicator {

@Getter private final FilterService filterService;

private Integer collectionThreshold;

public NetworkModificationApplicator(NetworkStoreService networkStoreService, EquipmentInfosService equipmentInfosService,
ReportService reportService, FilterService filterService) {
ReportService reportService, FilterService filterService, @Value("${impacts.collection-threshold:50}") Integer collectionThreshold) {
this.networkStoreService = networkStoreService;
this.equipmentInfosService = equipmentInfosService;
this.reportService = reportService;
this.filterService = filterService;
this.collectionThreshold = collectionThreshold;
}

public NetworkModificationResult applyModifications(List<ModificationInfos> modificationInfosList, NetworkInfos networkInfos, ReportInfos reportInfos) {
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService);
ApplicationStatus applicationStatus = apply(modificationInfosList, listener.getNetwork(), reportInfos);
listener.setApplicationStatus(applicationStatus);
listener.setLastGroupApplicationStatus(applicationStatus);
return listener.flushNetworkModifications();
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService, collectionThreshold);
ApplicationStatus groupApplicationStatus = apply(modificationInfosList, listener.getNetwork(), reportInfos);
List<AbstractBaseImpact> networkImpacts = listener.flushNetworkModifications();
return
NetworkModificationResult.builder()
.applicationStatus(groupApplicationStatus)
.lastGroupApplicationStatus(groupApplicationStatus)
.networkImpacts(networkImpacts)
.build();
}

public NetworkModificationResult applyModifications(List<Pair<String, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos, UUID reportUuid) {
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService);
List<ApplicationStatus> groupsStatuses =
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService, collectionThreshold);
List<ApplicationStatus> groupsApplicationStatuses =
modificationInfosGroups.stream()
.map(g -> apply(g.getRight(), listener.getNetwork(), new ReportInfos(reportUuid, g.getLeft())))
.toList();
listener.setApplicationStatus(groupsStatuses.stream().reduce(ApplicationStatus::max).orElse(ApplicationStatus.ALL_OK));
listener.setLastGroupApplicationStatus(Streams.findLast(groupsStatuses.stream()).orElse(ApplicationStatus.ALL_OK));
return listener.flushNetworkModifications();
List<AbstractBaseImpact> networkImpacts = listener.flushNetworkModifications();
return NetworkModificationResult.builder()
.applicationStatus(groupsApplicationStatuses.stream().reduce(ApplicationStatus::max).orElse(ApplicationStatus.ALL_OK))
.lastGroupApplicationStatus(Streams.findLast(groupsApplicationStatuses.stream()).orElse(ApplicationStatus.ALL_OK))
.networkImpacts(networkImpacts)
.build();
}

private ApplicationStatus apply(List<ModificationInfos> modificationInfosList, Network network, ReportInfos reportInfos) {
String rootReporterId = reportInfos.getReporterId() + "@" + NETWORK_MODIFICATION_TYPE_REPORT;
ReporterModel reporter = new ReporterModel(rootReporterId, rootReporterId);
ApplicationStatus applicationStatus = modificationInfosList.stream()
ApplicationStatus groupApplicationStatus = modificationInfosList.stream()
.map(m -> apply(m, network, reporter))
.reduce(ApplicationStatus::max)
.orElse(ApplicationStatus.ALL_OK);
reportService.sendReport(reportInfos.getReportUuid(), reporter);
return applicationStatus;
return groupApplicationStatus;
}

private ApplicationStatus apply(ModificationInfos modificationInfos, Network network, ReporterModel reporter) {
Expand Down
Loading
Loading