From 807207c10e62ee9de2ea6ea9e41127edb798290d Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 17 Nov 2023 10:25:19 +0100 Subject: [PATCH] Dynamic Simulation - Curve Configuration - Add some expert filter's criteria for Load and Generator --- .../utils/expertfilter/ExpertFilterUtils.java | 25 ++++++++++++------- .../server/utils/expertfilter/FieldType.java | 3 ++- .../filter/server/ExpertFilterUtilsTest.java | 14 ++++++++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/server/utils/expertfilter/ExpertFilterUtils.java b/src/main/java/org/gridsuite/filter/server/utils/expertfilter/ExpertFilterUtils.java index bed023e4..e5c39915 100644 --- a/src/main/java/org/gridsuite/filter/server/utils/expertfilter/ExpertFilterUtils.java +++ b/src/main/java/org/gridsuite/filter/server/utils/expertfilter/ExpertFilterUtils.java @@ -25,22 +25,28 @@ public static > String getFieldValue(FieldType field, }; } + private static String getInjectionFieldValue(FieldType field, Injection injection) { + return switch (field) { + case ID -> injection.getId(); + case NAME -> injection.getNameOrId(); + case COUNTRY -> { + Optional country = injection.getTerminal().getVoltageLevel().getSubstation().flatMap(Substation::getCountry); + yield country.isPresent() ? String.valueOf(country.get()) : ""; + } + case NOMINAL_VOLTAGE -> String.valueOf(injection.getTerminal().getVoltageLevel().getNominalV()); + case VOLTAGE_LEVEL_ID -> injection.getTerminal().getVoltageLevel().getId(); + default -> throw new PowsyblException("Field " + field + " with " + injection.getType() + " injection type is not implemented with expert filter"); + }; + } + private static String getLoadFieldValue(FieldType field, Load load) { return switch (field) { - case ID -> load.getId(); - default -> throw new PowsyblException("Field " + field + " with " + load.getType() + " injection type is not implemented with expert filter"); + default -> getInjectionFieldValue(field, load); }; } private static String getGeneratorFieldValue(FieldType field, Generator generator) { return switch (field) { - case ID -> generator.getId(); - case NAME -> generator.getNameOrId(); - case NOMINAL_VOLTAGE -> String.valueOf(generator.getTerminal().getVoltageLevel().getNominalV()); - case COUNTRY -> { - Optional country = generator.getTerminal().getVoltageLevel().getSubstation().flatMap(Substation::getCountry); - yield country.isPresent() ? String.valueOf(country.get()) : ""; - } case ENERGY_SOURCE -> String.valueOf(generator.getEnergySource()); case MIN_P -> String.valueOf(generator.getMinP()); case MAX_P -> String.valueOf(generator.getMaxP()); @@ -48,6 +54,7 @@ private static String getGeneratorFieldValue(FieldType field, Generator generato case TARGET_P -> String.valueOf(generator.getTargetP()); case TARGET_Q -> String.valueOf(generator.getTargetQ()); case VOLTAGE_REGULATOR_ON -> String.valueOf(generator.isVoltageRegulatorOn()); + default -> getInjectionFieldValue(field, generator); }; } } diff --git a/src/main/java/org/gridsuite/filter/server/utils/expertfilter/FieldType.java b/src/main/java/org/gridsuite/filter/server/utils/expertfilter/FieldType.java index b61f466f..88206081 100644 --- a/src/main/java/org/gridsuite/filter/server/utils/expertfilter/FieldType.java +++ b/src/main/java/org/gridsuite/filter/server/utils/expertfilter/FieldType.java @@ -20,5 +20,6 @@ public enum FieldType { TARGET_Q, ENERGY_SOURCE, COUNTRY, - VOLTAGE_REGULATOR_ON + VOLTAGE_REGULATOR_ON, + VOLTAGE_LEVEL_ID } diff --git a/src/test/java/org/gridsuite/filter/server/ExpertFilterUtilsTest.java b/src/test/java/org/gridsuite/filter/server/ExpertFilterUtilsTest.java index 22f5915d..889426cc 100644 --- a/src/test/java/org/gridsuite/filter/server/ExpertFilterUtilsTest.java +++ b/src/test/java/org/gridsuite/filter/server/ExpertFilterUtilsTest.java @@ -6,9 +6,7 @@ */ package org.gridsuite.filter.server; -import com.powsybl.iidm.network.EnergySource; -import com.powsybl.iidm.network.Generator; -import com.powsybl.iidm.network.IdentifiableType; +import com.powsybl.iidm.network.*; import org.gridsuite.filter.server.dto.expertfilter.expertrule.*; import org.gridsuite.filter.server.utils.expertfilter.CombinatorType; import org.gridsuite.filter.server.utils.expertfilter.FieldType; @@ -29,6 +27,12 @@ public class ExpertFilterUtilsTest { @Before public void setUp() { + VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class); + Mockito.when(voltageLevel.getId()).thenReturn("GEN_01"); + + Terminal terminal = Mockito.mock(Terminal.class); + Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel); + gen = Mockito.mock(Generator.class); Mockito.when(gen.getType()).thenReturn(IdentifiableType.GENERATOR); Mockito.when(gen.getMinP()).thenReturn(-500.0); @@ -38,6 +42,7 @@ public void setUp() { Mockito.when(gen.getNameOrId()).thenReturn("NAME"); Mockito.when(gen.getEnergySource()).thenReturn(EnergySource.HYDRO); Mockito.when(gen.isVoltageRegulatorOn()).thenReturn(true); + Mockito.when(gen.getTerminal()).thenReturn(terminal); } @Test @@ -74,6 +79,9 @@ public void testEvaluateExpertFilterWithANDCombination() { BooleanExpertRule booleanRule7 = BooleanExpertRule.builder().value(false) .field(FieldType.VOLTAGE_REGULATOR_ON).operator(OperatorType.NOT_EQUALS).build(); andRules2.add(booleanRule7); + StringExpertRule stringRule8 = StringExpertRule.builder().value("GEN_01") + .field(FieldType.VOLTAGE_LEVEL_ID).operator(OperatorType.IS).build(); + andRules2.add(stringRule8); CombinatorExpertRule andFilter = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(andRules2).build();