Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Transformers have only one substation #62

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ private static String getTwoWindingsTransformerFieldValue(FieldType field, Strin
case HAS_PHASE_TAP_CHANGER -> String.valueOf(twoWindingsTransformer.hasPhaseTapChanger());
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);
case SUBSTATION_PROPERTIES -> twoWindingsTransformer.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 All @@ -383,6 +382,7 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str
return switch (field) {
case COUNTRY -> threeWindingsTransformer.getSubstation().flatMap(Substation::getCountry).map(String::valueOf).orElse(null);
case RATED_VOLTAGE_0 -> String.valueOf(threeWindingsTransformer.getRatedU0());
case SUBSTATION_PROPERTIES -> threeWindingsTransformer.getNullableSubstation().getProperty(propertyName);
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
case CONNECTED_1,
NOMINAL_VOLTAGE_1,
RATED_VOLTAGE_1,
Expand All @@ -399,7 +399,6 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str
HAS_PHASE_TAP_CHANGER_1,
PHASE_REGULATION_MODE_1,
PHASE_REGULATION_VALUE_1,
SUBSTATION_PROPERTIES_1,
VOLTAGE_LEVEL_PROPERTIES_1 -> getThreeWindingsTransformerLegFieldValue(field, propertyName, threeWindingsTransformer.getLeg1());
case CONNECTED_2,
NOMINAL_VOLTAGE_2,
Expand All @@ -417,7 +416,6 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str
HAS_PHASE_TAP_CHANGER_2,
PHASE_REGULATION_MODE_2,
PHASE_REGULATION_VALUE_2,
SUBSTATION_PROPERTIES_2,
VOLTAGE_LEVEL_PROPERTIES_2 -> getThreeWindingsTransformerLegFieldValue(field, propertyName, threeWindingsTransformer.getLeg2());
case CONNECTED_3,
NOMINAL_VOLTAGE_3,
Expand All @@ -435,7 +433,6 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str
HAS_PHASE_TAP_CHANGER_3,
PHASE_REGULATION_MODE_3,
PHASE_REGULATION_VALUE_3,
SUBSTATION_PROPERTIES_3,
VOLTAGE_LEVEL_PROPERTIES_3 -> getThreeWindingsTransformerLegFieldValue(field, propertyName, threeWindingsTransformer.getLeg3());
default ->
throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + threeWindingsTransformer.getType() + "]");
Expand Down Expand Up @@ -492,9 +489,6 @@ private static String getThreeWindingsTransformerLegFieldValue(FieldType field,
PHASE_REGULATION_VALUE_2,
PHASE_REGULATION_MODE_3,
PHASE_REGULATION_VALUE_3 -> getPhaseTapChangerFieldValue(field, leg.getPhaseTapChanger());
case SUBSTATION_PROPERTIES_1,
SUBSTATION_PROPERTIES_2,
SUBSTATION_PROPERTIES_3 -> leg.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES_1,
VOLTAGE_LEVEL_PROPERTIES_2,
VOLTAGE_LEVEL_PROPERTIES_3 -> leg.getTerminal().getVoltageLevel().getProperty(propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public enum FieldType {
SUBSTATION_PROPERTIES,
SUBSTATION_PROPERTIES_1,
SUBSTATION_PROPERTIES_2,
basseche marked this conversation as resolved.
Show resolved Hide resolved
SUBSTATION_PROPERTIES_3,
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved
VOLTAGE_LEVEL_PROPERTIES,
VOLTAGE_LEVEL_PROPERTIES_1,
VOLTAGE_LEVEL_PROPERTIES_2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private static Stream<Arguments> provideArgumentsForTestWithException() {
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, line, "region", List.of("east"), PowsyblException.class),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, battery, "region", List.of("east"), PowsyblException.class),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, svar, "region", List.of("east"), PowsyblException.class),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_3, twoWindingsTransformer, "region", List.of("east"), PowsyblException.class),
Arguments.of(IN, FieldType.SERIE_REACTANCE, threeWindingsTransformer, "region", List.of("east"), PowsyblException.class),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, hvdcLine, "region", List.of("east"), PowsyblException.class),

Expand Down Expand Up @@ -279,21 +278,16 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
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");
Substation substation = Mockito.mock(Substation.class);
Mockito.when(twoWindingsTransformer.getNullableSubstation()).thenReturn(substation);
Mockito.when(substation.getProperty("regionCSV")).thenReturn("LILLE");

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("propertyValueTWT2"), 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.SUBSTATION_PROPERTIES, "regionCSV", List.of("Lille"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Paris"), 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),
Expand Down Expand Up @@ -359,27 +353,17 @@ private static Stream<Arguments> provideArgumentsForThreeWindingTransformerTest(
Mockito.when(voltageLevel3.getProperty("CodeOI")).thenReturn("44");
Mockito.when(terminal3.getVoltageLevel()).thenReturn(voltageLevel3);

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

return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT"), threeWindingsTransformer, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT2"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT3"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Lille"), threeWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Paris"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Paris"), threeWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Lille"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_3, "regionCSV", List.of("Marseille"), threeWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_3, "regionCSV", List.of("Lille"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Lille"), threeWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Paris"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("22"), threeWindingsTransformer, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("33"), threeWindingsTransformer, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("33"), threeWindingsTransformer, true),
Expand Down
Loading