-
Notifications
You must be signed in to change notification settings - Fork 0
Add the possibility to evaluate a filter and restrict the result to specified equipment types #169
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
61e0a2e
Refactored filter evaluation API: switched to POST method, added new …
flomillot bbbbc82
Handle missing equipment types gracefully by returning `null` instead…
flomillot 75968f3
Refactor filter evaluation to handle contingency lists and add utilit…
flomillot f9c2062
Refactor rule creation logic: replaced field count-based methods with…
flomillot a117c11
Add support for filtering substation equipment types and improve test…
flomillot 3291e4b
Add author annotation to unit test class
flomillot 687c7de
Simplify test method name and remove redundant blank lines in utility…
flomillot 0d2aa17
Rename `EquipmentTypesByElement` to `EquipmentTypesByFilterId` for cl…
flomillot ddb6871
Add clarification on filter limitations and reasoning in utility clas…
flomillot 4427f8d
Refactor `createFiltersForSubEquipments` to use a switch expression f…
flomillot f3d70fa
Sort filter results by type ordinal for consistent ordering
flomillot 65c84e7
Refactor `FilterLoader` initialization to avoid redundant object crea…
flomillot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/gridsuite/filter/server/dto/EquipmentTypesByFilterId.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Copyright (c) 2025, 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.filter.server.dto; | ||
|
|
||
| import com.powsybl.iidm.network.IdentifiableType; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Store a list of equipment types for a given filter ID | ||
| * | ||
| * @author Florent MILLOT <[email protected]> | ||
| */ | ||
| public record EquipmentTypesByFilterId(UUID filterId, Set<IdentifiableType> equipmentTypes) { | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/main/java/org/gridsuite/filter/server/dto/FiltersWithEquipmentTypes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * Copyright (c) 2025, 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.filter.server.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Store a list of filters and the equipment types that are associated with. | ||
| * | ||
| * @author Florent MILLOT <[email protected]> | ||
| */ | ||
| public record FiltersWithEquipmentTypes(List<FilterAttributes> filters, | ||
EtienneLt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| List<EquipmentTypesByFilterId> selectedEquipmentTypesByFilter) { | ||
| } | ||
114 changes: 114 additions & 0 deletions
114
src/main/java/org/gridsuite/filter/server/utils/FilterWithEquipmentTypesUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /** | ||
| * Copyright (c) 2025, 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.filter.server.utils; | ||
|
|
||
| import com.powsybl.iidm.network.IdentifiableType; | ||
| import org.gridsuite.filter.expertfilter.ExpertFilter; | ||
| import org.gridsuite.filter.expertfilter.expertrule.AbstractExpertRule; | ||
| import org.gridsuite.filter.expertfilter.expertrule.CombinatorExpertRule; | ||
| import org.gridsuite.filter.expertfilter.expertrule.StringExpertRule; | ||
| import org.gridsuite.filter.utils.EquipmentType; | ||
| import org.gridsuite.filter.utils.expertfilter.CombinatorType; | ||
| import org.gridsuite.filter.utils.expertfilter.FieldType; | ||
| import org.gridsuite.filter.utils.expertfilter.OperatorType; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static org.gridsuite.filter.utils.expertfilter.FieldType.*; | ||
|
|
||
| /** | ||
| * Sometimes, when we apply a filter on a substation or voltage level, | ||
| * we actually want the equipments related to these substations or voltage levels. | ||
| * This class is used to build these special filters, | ||
| * and we can specify which equipment types we are interested into. | ||
| * PS : We could have used a mix of expert filters with the operator IS_PART_OF | ||
| * but in this case we also need the notFoundIds of the original filter, | ||
| * which is not possible because it is different equipment types. | ||
| * @author Florent MILLOT <florent.millot at rte-france.com> | ||
| */ | ||
| public final class FilterWithEquipmentTypesUtils { | ||
|
|
||
| private FilterWithEquipmentTypesUtils() { | ||
| // Utility class | ||
| } | ||
|
|
||
| /** | ||
| * Create one filter for each equipment type we want to retrieve from a previous filter result. | ||
| * @param filterEquipmentType the equipment type of the original filter (substation or voltage level) | ||
| * @param filteredEquipmentIDs the filtered equipment IDs of the original filter | ||
| * @param subEquipmentTypes the equipment types we want to collect from the original filter result (so the equipments related to filteredEquipmentIDs) | ||
| * @return the list of filters | ||
| */ | ||
| public static List<ExpertFilter> createFiltersForSubEquipments(EquipmentType filterEquipmentType, Set<String> filteredEquipmentIDs, Set<IdentifiableType> subEquipmentTypes) { | ||
| return switch (filterEquipmentType) { | ||
| case SUBSTATION -> subEquipmentTypes.stream().map(identifiableType -> new ExpertFilter( | ||
| null, | ||
| null, | ||
| EquipmentType.valueOf(identifiableType.name()), | ||
| createSubstationRuleByEquipmentType(identifiableType, filteredEquipmentIDs))).toList(); | ||
| case VOLTAGE_LEVEL -> subEquipmentTypes.stream().map(identifiableType -> new ExpertFilter( | ||
| null, | ||
| null, | ||
| EquipmentType.valueOf(identifiableType.name()), | ||
| createVoltageLevelRuleByEquipmentType(identifiableType, filteredEquipmentIDs))).toList(); | ||
| default -> | ||
| throw new UnsupportedOperationException("Unsupported filter equipment type " + filterEquipmentType | ||
| + " : we can only filter sub equipments from substation and voltage level"); | ||
| }; | ||
| } | ||
|
|
||
| public static AbstractExpertRule createSubstationRuleByEquipmentType(IdentifiableType equipmentType, Set<String> substationIds) { | ||
| return switch (equipmentType) { | ||
| case LOAD, GENERATOR, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, BUSBAR_SECTION, BATTERY, | ||
| DANGLING_LINE, TWO_WINDINGS_TRANSFORMER, THREE_WINDINGS_TRANSFORMER -> createRuleWithOneField(substationIds, SUBSTATION_ID); | ||
| case LINE, HVDC_LINE -> createRuleWithTwoFields(substationIds, SUBSTATION_ID_1, SUBSTATION_ID_2); | ||
| default -> throw new UnsupportedOperationException("Unsupported equipment type " + equipmentType); | ||
| }; | ||
| } | ||
|
|
||
| public static AbstractExpertRule createVoltageLevelRuleByEquipmentType(IdentifiableType equipmentType, Set<String> voltageLevelIds) { | ||
| return switch (equipmentType) { | ||
| case LOAD, GENERATOR, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, BUSBAR_SECTION, BATTERY, | ||
| DANGLING_LINE -> createRuleWithOneField(voltageLevelIds, VOLTAGE_LEVEL_ID); | ||
| case LINE, HVDC_LINE, TWO_WINDINGS_TRANSFORMER -> createRuleWithTwoFields(voltageLevelIds, VOLTAGE_LEVEL_ID_1, VOLTAGE_LEVEL_ID_2); | ||
| case THREE_WINDINGS_TRANSFORMER -> createRuleWithThreeFields(voltageLevelIds, VOLTAGE_LEVEL_ID_1, VOLTAGE_LEVEL_ID_2, VOLTAGE_LEVEL_ID_3); | ||
| default -> throw new UnsupportedOperationException("Unsupported equipment type " + equipmentType); | ||
| }; | ||
| } | ||
|
|
||
| public static AbstractExpertRule createRuleWithOneField(Set<String> equipmentIds, FieldType field) { | ||
| return StringExpertRule.builder() | ||
| .operator(OperatorType.IN).field(field) | ||
| .values(equipmentIds).build(); | ||
| } | ||
|
|
||
| public static AbstractExpertRule createRuleWithTwoFields(Set<String> equipmentIds, FieldType field1, FieldType field2) { | ||
| StringExpertRule rule1 = StringExpertRule.builder() | ||
| .operator(OperatorType.IN).field(field1) | ||
| .values(equipmentIds).build(); | ||
| StringExpertRule rule2 = StringExpertRule.builder() | ||
| .operator(OperatorType.IN).field(field2) | ||
| .values(equipmentIds).build(); | ||
| return CombinatorExpertRule.builder().combinator(CombinatorType.OR).rules(List.of(rule1, rule2)).build(); | ||
| } | ||
|
|
||
| public static AbstractExpertRule createRuleWithThreeFields(Set<String> equipmentIds, FieldType field1, FieldType field2, FieldType field3) { | ||
| StringExpertRule rule1 = StringExpertRule.builder() | ||
| .operator(OperatorType.IN).field(field1) | ||
| .values(equipmentIds).build(); | ||
| StringExpertRule rule2 = StringExpertRule.builder() | ||
| .operator(OperatorType.IN).field(field2) | ||
| .values(equipmentIds).build(); | ||
| StringExpertRule rule3 = StringExpertRule.builder() | ||
| .operator(OperatorType.IN).field(field3) | ||
| .values(equipmentIds).build(); | ||
| return CombinatorExpertRule.builder().combinator(CombinatorType.OR).rules(List.of(rule1, rule2, rule3)).build(); | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.