Skip to content

Commit

Permalink
Add free properties to line filter. (#10)
Browse files Browse the repository at this point in the history

Signed-off-by: AAJELLAL <[email protected]>
  • Loading branch information
AAJELLAL authored Apr 18, 2024
1 parent 003c2ab commit ebb3cb7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@AllArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public abstract class AbstractLineFilter extends AbstractEquipmentFilterForm {
private String substationName1;

Expand All @@ -43,6 +44,10 @@ public abstract class AbstractLineFilter extends AbstractEquipmentFilterForm {
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties2;

// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties;

@Override
public boolean isEmpty() {
return super.isEmpty()
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/gridsuite/filter/utils/FiltersUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private static List<Identifiable<?>> getLineList(Network network, AbstractFilter
.filter(line -> filterByVoltages(line, lineFilter.getNominalVoltage1(), lineFilter.getNominalVoltage2()))
.filter(line -> filterByCountries(line, lineFilter))
.filter(line -> filterByProperties(line, lineFilter))
.filter(line -> freePropertiesFilter(line, lineFilter.getFreeProperties()))
.filter(line -> substationNameFilter(line.getTerminal1(), lineFilter.getSubstationName1()) &&
substationNameFilter(line.getTerminal2(), lineFilter.getSubstationName2()));
return new ArrayList<>(stream.toList());
Expand All @@ -336,6 +337,7 @@ private static List<Identifiable<?>> get2WTransformerList(Network network, Abstr
Stream<TwoWindingsTransformer> stream = network.getTwoWindingsTransformerStream()
.filter(twoWindingsTransformer -> equipmentIdFilter(twoWindingsTransformer, twoWindingsTransformerFilter.getEquipmentID()))
.filter(twoWindingsTransformer -> equipmentNameFilter(twoWindingsTransformer, twoWindingsTransformerFilter.getEquipmentName()))
.filter(twoWindingsTransformer -> freePropertiesFilter(twoWindingsTransformer, twoWindingsTransformerFilter.getFreeProperties()))
.filter(twoWindingsTransformer -> filterByVoltages(twoWindingsTransformer, twoWindingsTransformerFilter.getNominalVoltage1(), twoWindingsTransformerFilter.getNominalVoltage2()))
.filter(twoWindingsTransformer -> countryFilter(twoWindingsTransformer.getTerminal1(), twoWindingsTransformerFilter.getCountries()) ||
countryFilter(twoWindingsTransformer.getTerminal2(), twoWindingsTransformerFilter.getCountries()))
Expand Down Expand Up @@ -417,6 +419,7 @@ private static List<Identifiable<?>> getVoltageLevelList(Network network, Abstra
.filter(voltageLevel -> equipmentNameFilter(voltageLevel, voltageLevelFilter.getEquipmentName()))
.filter(voltageLevel -> filterByVoltage(voltageLevel, voltageLevelFilter.getNominalVoltage()))
.filter(voltageLevel -> countryFilter(voltageLevel, voltageLevelFilter.getCountries()))
.filter(voltageLevel -> freePropertiesFilter(voltageLevel, voltageLevelFilter.getFreeProperties()))
.filter(voltageLevel -> freePropertiesFilter(voltageLevel.getNullableSubstation(), voltageLevelFilter.getSubstationFreeProperties()));
return new ArrayList<>(stream.toList());
} else if (filter instanceof IdentifierListFilter identifierListFilter) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/gridsuite/filter/FiltersUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public void setUp() {
network.getGenerator("GEN").setProperty("region", "north");
network.getGenerator("GEN2").setProperty("region", "south");
network.getLoad("LOAD").setProperty("region", "north");
network.getTwoWindingsTransformer("NGEN_NHV1").setProperty("region", "south");
network.getTwoWindingsTransformer("NHV2_NLOAD").setProperty("region", "south");
network.getLine("NHV1_NHV2_1").setProperty("region", "south");
network.getLine("NHV1_NHV2_2").setProperty("region", "south");

network2 = HvdcTestNetwork.createVsc();
network2.getSubstation("S2").setProperty("region", "north");
Expand Down Expand Up @@ -197,6 +201,7 @@ void testLineFilter() {
.countries2(new TreeSet<>(Set.of("FR")))
.freeProperties1(Map.of("region", List.of("south")))
.freeProperties2(Map.of("region", List.of("north")))
.freeProperties(Map.of("region", List.of("south")))
.nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.))
.nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75))
.build();
Expand Down

0 comments on commit ebb3cb7

Please sign in to comment.