Skip to content

Commit

Permalink
Add voltage level properties support for expert filters (#27)
Browse files Browse the repository at this point in the history
Also fix and complete already existing property tests

Signed-off-by: Florent MILLOT <[email protected]>
  • Loading branch information
flomillot authored May 24, 2024
1 parent f3fa552 commit e214ca3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private static String getLineFieldValue(FieldType field, String propertyName, Li
case SHUNT_SUSCEPTANCE_2 -> String.valueOf(line.getB2());
case SUBSTATION_PROPERTIES_1 -> line.getTerminal1().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case SUBSTATION_PROPERTIES_2 -> line.getTerminal2().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES_1 -> line.getTerminal1().getVoltageLevel().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES_2 -> line.getTerminal2().getVoltageLevel().getProperty(propertyName);
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + line.getType() + "]");
};
}
Expand All @@ -107,6 +109,7 @@ private static String getLoadFieldValue(FieldType field, String propertyName, Lo
case CONNECTED -> getTerminalFieldValue(field, load.getTerminal());
case LOAD_TYPE -> load.getLoadType().name();
case SUBSTATION_PROPERTIES -> load.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES -> load.getTerminal().getVoltageLevel().getProperty(propertyName);
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + load.getType() + "]");
};
}
Expand All @@ -125,6 +128,7 @@ private static String getShuntCompensatorFieldValue(FieldType field, String prop
SWITCHED_ON_SUSCEPTANCE -> getSectionBasedFieldValue(field, shuntCompensator);
case CONNECTED -> getTerminalFieldValue(field, shuntCompensator.getTerminal());
case SUBSTATION_PROPERTIES -> shuntCompensator.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES -> shuntCompensator.getTerminal().getVoltageLevel().getProperty(propertyName);
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + shuntCompensator.getType() + "]");
};
}
Expand All @@ -149,6 +153,7 @@ private static String getGeneratorFieldValue(FieldType field, String propertyNam
VOLTAGE_LEVEL_ID -> getVoltageLevelFieldValue(field, null, generator.getTerminal().getVoltageLevel());
case CONNECTED -> 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() + "]");
};
}
Expand Down Expand Up @@ -222,7 +227,7 @@ private static String getBatteryFieldValue(FieldType field, String propertyName,
case TARGET_P -> String.valueOf(battery.getTargetP());
case TARGET_Q -> String.valueOf(battery.getTargetQ());
case SUBSTATION_PROPERTIES -> battery.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName);

case VOLTAGE_LEVEL_PROPERTIES -> battery.getTerminal().getVoltageLevel().getProperty(propertyName);
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + battery.getType() + "]");

};
Expand Down Expand Up @@ -288,6 +293,8 @@ private static String getTwoWindingsTransformerFieldValue(FieldType field, Strin
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);
case VOLTAGE_LEVEL_PROPERTIES_1 -> twoWindingsTransformer.getTerminal1().getVoltageLevel().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES_2 -> twoWindingsTransformer.getTerminal2().getVoltageLevel().getProperty(propertyName);
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + twoWindingsTransformer.getType() + "]");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ public enum FieldType {
SUBSTATION_PROPERTIES,
SUBSTATION_PROPERTIES_1,
SUBSTATION_PROPERTIES_2,
VOLTAGE_LEVEL_PROPERTIES,
VOLTAGE_LEVEL_PROPERTIES_1,
VOLTAGE_LEVEL_PROPERTIES_2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ static Stream<Arguments> provideArgumentsForTestWithException() {

Line line = Mockito.mock(Line.class);
Mockito.when(line.getType()).thenReturn(IdentifiableType.LINE);
Terminal terminal1 = Mockito.mock(Terminal.class);
Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel);

Generator generator = Mockito.mock(Generator.class);
Mockito.when(generator.getType()).thenReturn(IdentifiableType.GENERATOR);
Mockito.when(generator.getId()).thenReturn("GEN");
Mockito.when(generator.getProperty("codeOI")).thenReturn("33");
Mockito.when(generator.getProperty("north")).thenReturn("north");
Mockito.when(generator.getTerminal()).thenReturn(terminal);
Mockito.when(generator.getTerminal().getVoltageLevel().getNullableSubstation().getProperty("cvgRegion")).thenReturn("LILLE");

Load load = Mockito.mock(Load.class);
Mockito.when(load.getType()).thenReturn(IdentifiableType.LOAD);
Expand Down Expand Up @@ -94,6 +91,8 @@ private static Stream<Arguments> provideArgumentsForGeneratorTest() {

Generator generator = Mockito.mock(Generator.class);
Mockito.when(generator.getType()).thenReturn(IdentifiableType.GENERATOR);
Mockito.when(generator.getProperty("CodeOI")).thenReturn("11");

Terminal terminal = Mockito.mock(Terminal.class);

Mockito.when(generator.getTerminal()).thenReturn(terminal);
Expand All @@ -107,13 +106,15 @@ private static Stream<Arguments> provideArgumentsForGeneratorTest() {
Mockito.when(voltageLevel.getNullableSubstation()).thenReturn(substation);

Mockito.when(substation.getProperty("regionCSV")).thenReturn("LILLE");
Mockito.when(generator.getTerminal().getVoltageLevel().getNullableSubstation().getProperty("cvgRegion")).thenReturn("LILLE");

return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "CodeOI", List.of("22"), voltageLevel, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("LILLE"), voltageLevel, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("PARIS"), voltageLevel, false)
Arguments.of(IN, FieldType.FREE_PROPERTIES, "CodeOI", List.of("11"), generator, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "CodeOI", List.of("22"), generator, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("LILLE"), generator, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("PARIS"), generator, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES, "CodeOI", List.of("22"), generator, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES, "CodeOI", List.of("11"), generator, false)
);
}

Expand All @@ -135,7 +136,7 @@ private static Stream<Arguments> provideArgumentsForLineTest() {

VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel2.getType()).thenReturn(IdentifiableType.VOLTAGE_LEVEL);
Mockito.when(voltageLevel2.getProperty("region")).thenReturn("east");
Mockito.when(voltageLevel2.getProperty("CodeOI")).thenReturn("33");
Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);

Substation substation1 = Mockito.mock(Substation.class);
Expand All @@ -144,14 +145,14 @@ private static Stream<Arguments> provideArgumentsForLineTest() {
Mockito.when(voltageLevel2.getNullableSubstation()).thenReturn(substation2);
Mockito.when(substation1.getProperty("regionCSV")).thenReturn("LILLE");
Mockito.when(substation2.getProperty("regionCSV")).thenReturn("PARIS");
Mockito.when(voltageLevel1.getNullableSubstation()).thenReturn(substation1);
Mockito.when(voltageLevel2.getNullableSubstation()).thenReturn(substation2);

return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "region", List.of("north"), line, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("LILLE"), line, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("PARIS"), line, true)
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("PARIS"), line, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("22"), line, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("33"), line, true)
);
}

Expand All @@ -177,6 +178,7 @@ private static Stream<Arguments> provideArgumentsForLoadTest() {

Substation substation = Mockito.mock(Substation.class);
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel.getProperty("CodeOI")).thenReturn("33");
Mockito.when(voltageLevel.getNullableSubstation()).thenReturn(substation);
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
Expand All @@ -186,7 +188,31 @@ private static Stream<Arguments> provideArgumentsForLoadTest() {
return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameLoad", List.of("propertyValueLoad"), load, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "propertyNameSubstation", List.of("propertyValueSubstation"), load, true)
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "propertyNameSubstation", List.of("propertyValueSubstation"), load, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES, "CodeOI", List.of("33"), load, true)
);
}

private static Stream<Arguments> provideArgumentsForShuntCompensatorTest() {

ShuntCompensator shuntCompensator = Mockito.mock(ShuntCompensator.class);
Mockito.when(shuntCompensator.getType()).thenReturn(IdentifiableType.SHUNT_COMPENSATOR);
Mockito.when(shuntCompensator.getProperty("propertyNameSC")).thenReturn("propertyValueSC");

Substation substation = Mockito.mock(Substation.class);
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel.getProperty("CodeOI")).thenReturn("33");
Mockito.when(voltageLevel.getNullableSubstation()).thenReturn(substation);
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
Mockito.when(shuntCompensator.getTerminal()).thenReturn(terminal);
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("propertyValueSubstation");

return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameSC", List.of("propertyValueSC"), shuntCompensator, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "propertyNameSubstation", List.of("propertyValueSubstation"), shuntCompensator, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES, "CodeOI", List.of("33"), shuntCompensator, true)
);
}

Expand All @@ -196,24 +222,40 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
Mockito.when(twoWindingsTransformer.getType()).thenReturn(IdentifiableType.TWO_WINDINGS_TRANSFORMER);
Mockito.when(twoWindingsTransformer.getProperty("propertyNameTWT")).thenReturn("propertyValueTWT");

Substation substation = Mockito.mock(Substation.class);

Terminal terminal1 = Mockito.mock(Terminal.class);
Mockito.when(twoWindingsTransformer.getTerminal1()).thenReturn(terminal1);
VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel1.getType()).thenReturn(IdentifiableType.VOLTAGE_LEVEL);
Mockito.when(voltageLevel1.getProperty("CodeOI")).thenReturn("22");
Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);

Mockito.when(voltageLevel1.getNullableSubstation()).thenReturn(substation);
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("propertyValueSubstation");
Terminal terminal2 = Mockito.mock(Terminal.class);
Mockito.when(twoWindingsTransformer.getTerminal2()).thenReturn(terminal2);
VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel2.getType()).thenReturn(IdentifiableType.VOLTAGE_LEVEL);
Mockito.when(voltageLevel2.getProperty("CodeOI")).thenReturn("33");
Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);

Substation substation1 = Mockito.mock(Substation.class);
Substation substation2 = Mockito.mock(Substation.class);
Mockito.when(voltageLevel1.getNullableSubstation()).thenReturn(substation1);
Mockito.when(voltageLevel2.getNullableSubstation()).thenReturn(substation2);
Mockito.when(substation1.getProperty("regionCSV")).thenReturn("LILLE");
Mockito.when(substation2.getProperty("regionCSV")).thenReturn("PARIS");

return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT", "propertyValueTWT"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValue"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "propertyNameSubstation", List.of("propertyValueSubstation"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "propertyNameSubstation", List.of("propertyValueSubstation1"), twoWindingsTransformer, false)
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("LILLE"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("PARIS"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("PARIS"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("LILLE"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("22"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("33"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("33"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("22"), twoWindingsTransformer, false)
);
}

Expand All @@ -223,6 +265,7 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
"provideArgumentsForGeneratorTest",
"provideArgumentsForTwoWindingTransformerTest",
"provideArgumentsForLoadTest",
"provideArgumentsForShuntCompensatorTest",
"provideArgumentsForLineTest",
})

Expand Down

0 comments on commit e214ca3

Please sign in to comment.