From e16d0e83a3b4305315b1790811e376e024477937 Mon Sep 17 00:00:00 2001 From: lisrte Date: Mon, 22 Jul 2024 15:01:00 +0200 Subject: [PATCH 1/2] Add generator filter on P absolute Signed-off-by: lisrte --- .../utils/expertfilter/ExpertFilterUtils.java | 4 +- .../filter/utils/expertfilter/FieldType.java | 1 + .../expertfilter/NumberExpertRuleTest.java | 37 +++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java index 8f13862..8503571 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java @@ -180,7 +180,8 @@ private static String getGeneratorFieldValue(FieldType field, String propertyNam case COUNTRY, NOMINAL_VOLTAGE, VOLTAGE_LEVEL_ID -> getVoltageLevelFieldValue(field, null, generator.getTerminal().getVoltageLevel()); - case CONNECTED -> getTerminalFieldValue(field, generator.getTerminal()); + case CONNECTED, + P_ABSOLUTE-> getTerminalFieldValue(field, generator.getTerminal()); case SUBSTATION_PROPERTIES -> generator.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName); case VOLTAGE_LEVEL_PROPERTIES -> generator.getTerminal().getVoltageLevel().getProperty(propertyName); default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + generator.getType() + "]"); @@ -236,6 +237,7 @@ private static String getTerminalFieldValue(FieldType field, @Nullable Terminal case REGULATING_TERMINAL_CONNECTABLE_ID -> terminal.getConnectable() != null ? terminal.getConnectable().getId() : null; + case P_ABSOLUTE -> String.valueOf(Math.abs(terminal.getP())); default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + ",terminal]"); }; } diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java index 53764df..6ae7288 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java @@ -30,6 +30,7 @@ public enum FieldType { FORCED_OUTAGE_RATE, P0, Q0, + P_ABSOLUTE, LOW_VOLTAGE_LIMIT, HIGH_VOLTAGE_LIMIT, SECTION_COUNT, diff --git a/src/test/java/org/gridsuite/filter/expertfilter/NumberExpertRuleTest.java b/src/test/java/org/gridsuite/filter/expertfilter/NumberExpertRuleTest.java index 059c337..617c1b5 100644 --- a/src/test/java/org/gridsuite/filter/expertfilter/NumberExpertRuleTest.java +++ b/src/test/java/org/gridsuite/filter/expertfilter/NumberExpertRuleTest.java @@ -128,11 +128,13 @@ private static Stream provideArgumentsForGeneratorTest() { Mockito.when(genStartup.getPlannedOutageRate()).thenReturn(50.0); Mockito.when(genStartup.getForcedOutageRate()).thenReturn(50.0); Mockito.when(gen.getExtension(any())).thenReturn(genStartup); + // Terminal fields + Terminal terminal = Mockito.mock(Terminal.class); + Mockito.when(gen.getTerminal()).thenReturn(terminal); + Mockito.when(terminal.getP()).thenReturn(-100.0); // VoltageLevel fields VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class); - Terminal terminal = Mockito.mock(Terminal.class); Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel); - Mockito.when(gen.getTerminal()).thenReturn(terminal); Mockito.when(voltageLevel.getNominalV()).thenReturn(13.0); // for testing none EXISTS @@ -152,11 +154,13 @@ private static Stream provideArgumentsForGeneratorTest() { Mockito.when(genStartup1.getPlannedOutageRate()).thenReturn(Double.NaN); Mockito.when(genStartup1.getForcedOutageRate()).thenReturn(Double.NaN); Mockito.when(gen1.getExtension(any())).thenReturn(genStartup1); + // Terminal fields + Terminal terminal1 = Mockito.mock(Terminal.class); + Mockito.when(gen1.getTerminal()).thenReturn(terminal1); + Mockito.when(terminal1.getP()).thenReturn(Double.NaN); // VoltageLevel fields VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class); - Terminal terminal1 = Mockito.mock(Terminal.class); Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1); - Mockito.when(gen1.getTerminal()).thenReturn(terminal1); Mockito.when(voltageLevel1.getNominalV()).thenReturn(Double.NaN); return Stream.of( @@ -174,6 +178,8 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(EQUALS, FieldType.TARGET_Q, 30.0, null, gen, false), Arguments.of(EQUALS, FieldType.RATED_S, 60.0, null, gen, true), Arguments.of(EQUALS, FieldType.RATED_S, 50.0, null, gen, false), + Arguments.of(EQUALS, FieldType.P_ABSOLUTE, 100.0, null, gen, true), + Arguments.of(EQUALS, FieldType.P_ABSOLUTE, 50.0, null, gen, false), // GeneratorStartup extension fields Arguments.of(EQUALS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 50.0, null, gen, true), Arguments.of(EQUALS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 40.0, null, gen, false), @@ -207,6 +213,9 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(GREATER_OR_EQUALS, FieldType.RATED_S, 50.0, null, gen, true), Arguments.of(GREATER_OR_EQUALS, FieldType.RATED_S, 60.0, null, gen, true), Arguments.of(GREATER_OR_EQUALS, FieldType.RATED_S, 70.0, null, gen, false), + Arguments.of(GREATER_OR_EQUALS, FieldType.P_ABSOLUTE, 90.0, null, gen, true), + Arguments.of(GREATER_OR_EQUALS, FieldType.P_ABSOLUTE, 100.0, null, gen, true), + Arguments.of(GREATER_OR_EQUALS, FieldType.P_ABSOLUTE, 110.0, null, gen, false), // GeneratorStartup extension fields Arguments.of(GREATER_OR_EQUALS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 40.0, null, gen, true), Arguments.of(GREATER_OR_EQUALS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 50.0, null, gen, true), @@ -245,6 +254,10 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(GREATER, FieldType.RATED_S, 50.0, null, gen, true), Arguments.of(GREATER, FieldType.RATED_S, 60.0, null, gen, false), Arguments.of(GREATER, FieldType.RATED_S, 70.0, null, gen, false), + Arguments.of(GREATER, FieldType.P_ABSOLUTE, 90.0, null, gen, true), + Arguments.of(GREATER, FieldType.P_ABSOLUTE, 100.0, null, gen, false), + Arguments.of(GREATER, FieldType.P_ABSOLUTE, 110.0, null, gen, false), + // GeneratorStartup extension fields Arguments.of(GREATER, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 40.0, null, gen, true), Arguments.of(GREATER, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 50.0, null, gen, false), @@ -283,6 +296,9 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(LOWER_OR_EQUALS, FieldType.RATED_S, 70.0, null, gen, true), Arguments.of(LOWER_OR_EQUALS, FieldType.RATED_S, 60.0, null, gen, true), Arguments.of(LOWER_OR_EQUALS, FieldType.RATED_S, 50.0, null, gen, false), + Arguments.of(LOWER_OR_EQUALS, FieldType.P_ABSOLUTE, 110.0, null, gen, true), + Arguments.of(LOWER_OR_EQUALS, FieldType.P_ABSOLUTE, 100.0, null, gen, true), + Arguments.of(LOWER_OR_EQUALS, FieldType.P_ABSOLUTE, 90.0, null, gen, false), // GeneratorStartup extension fields Arguments.of(LOWER_OR_EQUALS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 60.0, null, gen, true), Arguments.of(LOWER_OR_EQUALS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 50.0, null, gen, true), @@ -321,6 +337,9 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(LOWER, FieldType.RATED_S, 70.0, null, gen, true), Arguments.of(LOWER, FieldType.RATED_S, 60.0, null, gen, false), Arguments.of(LOWER, FieldType.RATED_S, 50.0, null, gen, false), + Arguments.of(LOWER, FieldType.P_ABSOLUTE, 110.0, null, gen, true), + Arguments.of(LOWER, FieldType.P_ABSOLUTE, 100.0, null, gen, false), + Arguments.of(LOWER, FieldType.P_ABSOLUTE, 90.0, null, gen, false), // GeneratorStartup extension fields Arguments.of(LOWER, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 60.0, null, gen, true), Arguments.of(LOWER, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, 50.0, null, gen, false), @@ -353,6 +372,8 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(BETWEEN, FieldType.TARGET_Q, null, Set.of(45.0, 50.0), gen, false), Arguments.of(BETWEEN, FieldType.RATED_S, null, Set.of(50.0, 70.0), gen, true), Arguments.of(BETWEEN, FieldType.RATED_S, null, Set.of(65.0, 70.0), gen, false), + Arguments.of(BETWEEN, FieldType.P_ABSOLUTE, null, Set.of(90.0, 110.0), gen, true), + Arguments.of(BETWEEN, FieldType.P_ABSOLUTE, null, Set.of(80.0, 90.0), gen, false), // GeneratorStartup extension fields Arguments.of(BETWEEN, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, Set.of(40.0, 60.0), gen, true), Arguments.of(BETWEEN, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, Set.of(55.0, 60.0), gen, false), @@ -380,6 +401,8 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(EXISTS, FieldType.TARGET_Q, null, null, gen1, false), Arguments.of(EXISTS, FieldType.RATED_S, null, null, gen, true), Arguments.of(EXISTS, FieldType.RATED_S, null, null, gen1, false), + Arguments.of(EXISTS, FieldType.P_ABSOLUTE, null, null, gen, true), + Arguments.of(EXISTS, FieldType.P_ABSOLUTE, null, null, gen1, false), // GeneratorStartup extension fields Arguments.of(EXISTS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, null, gen, true), Arguments.of(EXISTS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, null, gen1, false), @@ -407,6 +430,8 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(NOT_EXISTS, FieldType.TARGET_Q, null, null, gen1, true), Arguments.of(NOT_EXISTS, FieldType.RATED_S, null, null, gen, false), Arguments.of(NOT_EXISTS, FieldType.RATED_S, null, null, gen1, true), + Arguments.of(NOT_EXISTS, FieldType.P_ABSOLUTE, null, null, gen, false), + Arguments.of(NOT_EXISTS, FieldType.P_ABSOLUTE, null, null, gen1, true), // GeneratorStartup extension fields Arguments.of(NOT_EXISTS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, null, gen, false), Arguments.of(NOT_EXISTS, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, null, gen1, true), @@ -434,6 +459,8 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(IN, FieldType.TARGET_Q, null, Set.of(30.0, 50.0), gen, false), Arguments.of(IN, FieldType.RATED_S, null, Set.of(50.0, 60.0, 70.0), gen, true), Arguments.of(IN, FieldType.RATED_S, null, Set.of(50.0, 70.0), gen, false), + Arguments.of(IN, FieldType.P_ABSOLUTE, null, Set.of(90.0, 100.0, 110.0), gen, true), + Arguments.of(IN, FieldType.P_ABSOLUTE, null, Set.of(90.0, 110.0), gen, false), // GeneratorStartup extension fields Arguments.of(IN, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, Set.of(40.0, 50.0, 60.0), gen, true), Arguments.of(IN, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, Set.of(40.0, 60.0), gen, false), @@ -461,6 +488,8 @@ private static Stream provideArgumentsForGeneratorTest() { Arguments.of(NOT_IN, FieldType.TARGET_Q, null, Set.of(30.0, 40.0, 50.0), gen, false), Arguments.of(NOT_IN, FieldType.RATED_S, null, Set.of(50.0, 70.0), gen, true), Arguments.of(NOT_IN, FieldType.RATED_S, null, Set.of(50.0, 60.0, 70.0), gen, false), + Arguments.of(NOT_IN, FieldType.P_ABSOLUTE, null, Set.of(90.0, 110.0), gen, true), + Arguments.of(NOT_IN, FieldType.P_ABSOLUTE, null, Set.of(90.0, 100.0, 110.0), gen, false), // GeneratorStartup extension fields Arguments.of(NOT_IN, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, Set.of(40.0, 60.0), gen, true), Arguments.of(NOT_IN, FieldType.PLANNED_ACTIVE_POWER_SET_POINT, null, Set.of(40.0, 50.0, 60.0), gen, false), From 86475c4818eed1ea3c4ae3428368520c16993e26 Mon Sep 17 00:00:00 2001 From: lisrte Date: Tue, 23 Jul 2024 17:44:35 +0200 Subject: [PATCH 2/2] Fix checkstyle Signed-off-by: lisrte --- .../gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java index 8503571..583d8f8 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java @@ -181,7 +181,7 @@ private static String getGeneratorFieldValue(FieldType field, String propertyNam NOMINAL_VOLTAGE, VOLTAGE_LEVEL_ID -> getVoltageLevelFieldValue(field, null, generator.getTerminal().getVoltageLevel()); case CONNECTED, - P_ABSOLUTE-> getTerminalFieldValue(field, generator.getTerminal()); + P_ABSOLUTE -> getTerminalFieldValue(field, generator.getTerminal()); case SUBSTATION_PROPERTIES -> generator.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName); case VOLTAGE_LEVEL_PROPERTIES -> generator.getTerminal().getVoltageLevel().getProperty(propertyName); default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + generator.getType() + "]");