Skip to content

Commit

Permalink
Merge branch 'main' into upgrade_to_powsybl_dependencies_2024.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckLecuyer authored Jul 17, 2024
2 parents e02dcd0 + d17420d commit 27215c6
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.gridsuite.filter.utils.expertfilter.DataType;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import static org.gridsuite.filter.utils.expertfilter.ExpertFilterUtils.getFieldValue;
Expand Down Expand Up @@ -53,7 +54,7 @@ public boolean evaluateRule(Identifiable<?> identifiable, FilterLoader filterLoa
return this.getOperator() == NOT_EXISTS;
}
boolean identifiableValue = Boolean.parseBoolean(fieldValue);
Boolean filterValue = this.getValue();
boolean filterValue = Optional.ofNullable(this.getValue()).orElse(false);
return switch (this.getOperator()) {
case EQUALS -> identifiableValue == filterValue;
case NOT_EQUALS -> identifiableValue != filterValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import org.gridsuite.filter.identifierlistfilter.FilterEquipments;
import org.gridsuite.filter.utils.expertfilter.DataType;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.gridsuite.filter.utils.expertfilter.ExpertFilterUtils.getFieldValue;

Expand Down Expand Up @@ -46,7 +49,7 @@ public boolean evaluateRule(Identifiable<?> identifiable, FilterLoader filterLoa
return false;
}
return switch (this.getOperator()) {
case IN -> this.getPropertyValues().contains(propertyValue);
case IN -> this.getPropertyValues().stream().anyMatch(propertyValue::equalsIgnoreCase);
default -> throw new PowsyblException(this.getOperator() + " operator not supported with " + this.getDataType() + " rule data type");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.gridsuite.filter.identifierlistfilter.FilterEquipments;
import org.gridsuite.filter.utils.expertfilter.DataType;

import java.util.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.gridsuite.filter.utils.expertfilter.ExpertFilterUtils.getFieldValue;
import static org.gridsuite.filter.utils.expertfilter.OperatorType.NOT_EXISTS;
Expand Down Expand Up @@ -68,8 +71,8 @@ public boolean evaluateRule(Identifiable<?> identifiable, FilterLoader filterLoa
case ENDS_WITH -> StringUtils.endsWithIgnoreCase(identifiableValue, this.getValue());
case EXISTS -> !StringUtils.isEmpty(identifiableValue);
case NOT_EXISTS -> StringUtils.isEmpty(identifiableValue);
case IN -> this.getValues().contains(identifiableValue);
case NOT_IN -> !this.getValues().contains(identifiableValue);
case IN -> this.getValues().stream().anyMatch(identifiableValue::equalsIgnoreCase);
case NOT_IN -> this.getValues().stream().noneMatch(identifiableValue::equalsIgnoreCase);
default -> throw new PowsyblException(this.getOperator() + " operator not supported with " + this.getDataType() + " rule data type");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,49 @@ private static String getSubstationFieldValue(FieldType field, Substation substa
};
}

private static String getRatioRegulationMode(RatioTapChanger ratioTapChanger) {
if (ratioTapChanger.hasLoadTapChangingCapabilities() && ratioTapChanger.isRegulating()) {
return RatioRegulationModeType.VOLTAGE_REGULATION.name();
} else if (!ratioTapChanger.isRegulating()) {
return RatioRegulationModeType.FIXED_RATIO.name();
} else {
return null;
}
}

private static String getRatioTapChangerFieldValue(FieldType field, @Nullable RatioTapChanger ratioTapChanger) {
if (ratioTapChanger == null) {
return null;
}
return switch (field) {
case RATIO_REGULATING -> String.valueOf(ratioTapChanger.isRegulating());
case RATIO_TARGET_V -> String.valueOf(ratioTapChanger.getTargetV());
case LOAD_TAP_CHANGING_CAPABILITIES -> String.valueOf(ratioTapChanger.hasLoadTapChangingCapabilities());
case RATIO_REGULATION_MODE -> ratioTapChanger.getRegulationMode() != null ? ratioTapChanger.getRegulationMode().name() : null;
case RATIO_REGULATION_MODE -> String.valueOf(getRatioRegulationMode(ratioTapChanger));
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + ",ratioTapChanger]");
};
}

private static String getPhaseRegulationMode(PhaseTapChanger phaseTapChanger) {
if (phaseTapChanger.getRegulationMode() == PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL && phaseTapChanger.isRegulating()) {
return PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL.name();
} else if (phaseTapChanger.getRegulationMode() == PhaseTapChanger.RegulationMode.CURRENT_LIMITER && phaseTapChanger.isRegulating()) {
return PhaseTapChanger.RegulationMode.CURRENT_LIMITER.name();
} else if (phaseTapChanger.getRegulationMode() == PhaseTapChanger.RegulationMode.FIXED_TAP ||
phaseTapChanger.getRegulationMode() == PhaseTapChanger.RegulationMode.CURRENT_LIMITER && !phaseTapChanger.isRegulating() ||
phaseTapChanger.getRegulationMode() == PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL && !phaseTapChanger.isRegulating()) {
return PhaseTapChanger.RegulationMode.FIXED_TAP.name();
} else {
return null;
}
}

private static String getPhaseTapChangerFieldValue(FieldType field, @Nullable PhaseTapChanger phaseTapChanger) {
if (phaseTapChanger == null) {
return null;
}
return switch (field) {
case PHASE_REGULATING -> String.valueOf(phaseTapChanger.isRegulating());
case PHASE_REGULATION_VALUE -> String.valueOf(phaseTapChanger.getRegulationValue());
case PHASE_REGULATION_MODE -> phaseTapChanger.getRegulationMode() != null ? phaseTapChanger.getRegulationMode().name() : null;
case PHASE_REGULATION_MODE -> String.valueOf(getPhaseRegulationMode(phaseTapChanger));
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + ",phaseTapChanger]");
};
}
Expand All @@ -293,13 +315,11 @@ private static String getTwoWindingsTransformerFieldValue(FieldType field, Strin
case MAGNETIZING_CONDUCTANCE -> String.valueOf(twoWindingsTransformer.getG());
case MAGNETIZING_SUSCEPTANCE -> String.valueOf(twoWindingsTransformer.getB());
case HAS_RATIO_TAP_CHANGER -> String.valueOf(twoWindingsTransformer.hasRatioTapChanger());
case RATIO_REGULATING,
RATIO_TARGET_V,
case RATIO_TARGET_V,
LOAD_TAP_CHANGING_CAPABILITIES,
RATIO_REGULATION_MODE -> getRatioTapChangerFieldValue(field, twoWindingsTransformer.getRatioTapChanger());
case HAS_PHASE_TAP_CHANGER -> String.valueOf(twoWindingsTransformer.hasPhaseTapChanger());
case PHASE_REGULATING,
PHASE_REGULATION_MODE,
case PHASE_REGULATION_MODE,
PHASE_REGULATION_VALUE -> getPhaseTapChangerFieldValue(field, twoWindingsTransformer.getPhaseTapChanger());
case SUBSTATION_PROPERTIES_1 -> twoWindingsTransformer.getTerminal1().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case SUBSTATION_PROPERTIES_2 -> twoWindingsTransformer.getTerminal2().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ public enum FieldType {
MAGNETIZING_SUSCEPTANCE,
LOAD_TYPE,
HAS_RATIO_TAP_CHANGER,
RATIO_REGULATING,
LOAD_TAP_CHANGING_CAPABILITIES,
RATIO_REGULATION_MODE,
RATIO_TARGET_V,
HAS_PHASE_TAP_CHANGER,
PHASE_REGULATING,
PHASE_REGULATION_MODE,
PHASE_REGULATION_VALUE,
FREE_PROPERTIES,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2024, 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.utils.expertfilter;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
public enum RatioRegulationModeType {
VOLTAGE_REGULATION,
FIXED_RATIO
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,11 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
Arguments.of(EQUALS, FieldType.CONNECTED_2, false, twoWindingsTransformer, false),

// RatioTapChanger fields
Arguments.of(EQUALS, FieldType.RATIO_REGULATING, true, twoWindingsTransformer, true),
Arguments.of(EQUALS, FieldType.RATIO_REGULATING, false, twoWindingsTransformer, false),
Arguments.of(EQUALS, FieldType.LOAD_TAP_CHANGING_CAPABILITIES, true, twoWindingsTransformer, true),
Arguments.of(EQUALS, FieldType.LOAD_TAP_CHANGING_CAPABILITIES, false, twoWindingsTransformer, false),
Arguments.of(EQUALS, FieldType.HAS_RATIO_TAP_CHANGER, true, twoWindingsTransformer, true),

// PhaseTapChanger fields
Arguments.of(EQUALS, FieldType.PHASE_REGULATING, false, twoWindingsTransformer, true),
Arguments.of(EQUALS, FieldType.PHASE_REGULATING, true, twoWindingsTransformer, false),
Arguments.of(EQUALS, FieldType.HAS_PHASE_TAP_CHANGER, true, twoWindingsTransformer, true),

// --- NOT_EQUALS--- //
Expand All @@ -282,23 +278,17 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
Arguments.of(NOT_EQUALS, FieldType.CONNECTED_2, true, twoWindingsTransformer, false),

// RatioTapChanger fields
Arguments.of(NOT_EQUALS, FieldType.RATIO_REGULATING, false, twoWindingsTransformer, true),
Arguments.of(NOT_EQUALS, FieldType.RATIO_REGULATING, true, twoWindingsTransformer, false),
Arguments.of(NOT_EQUALS, FieldType.LOAD_TAP_CHANGING_CAPABILITIES, false, twoWindingsTransformer, true),
Arguments.of(NOT_EQUALS, FieldType.LOAD_TAP_CHANGING_CAPABILITIES, true, twoWindingsTransformer, false),
Arguments.of(NOT_EQUALS, FieldType.HAS_RATIO_TAP_CHANGER, true, twoWindingsTransformer, false),

// null RatioTapChanger
Arguments.of(NOT_EQUALS, FieldType.RATIO_REGULATING, false, twoWindingsTransformer2, false),
Arguments.of(NOT_EQUALS, FieldType.HAS_RATIO_TAP_CHANGER, false, twoWindingsTransformer2, false),

// PhaseTapChanger fields
Arguments.of(NOT_EQUALS, FieldType.PHASE_REGULATING, true, twoWindingsTransformer, true),
Arguments.of(NOT_EQUALS, FieldType.PHASE_REGULATING, false, twoWindingsTransformer, false),
Arguments.of(NOT_EQUALS, FieldType.HAS_PHASE_TAP_CHANGER, true, twoWindingsTransformer, false),

// null PhaseTapChanger
Arguments.of(NOT_EQUALS, FieldType.PHASE_REGULATING, false, twoWindingsTransformer2, false),
Arguments.of(NOT_EQUALS, FieldType.HAS_PHASE_TAP_CHANGER, false, twoWindingsTransformer2, false)
);
}
Expand Down
Loading

0 comments on commit 27215c6

Please sign in to comment.