Skip to content

Commit

Permalink
create fromVoltageLevel in UcteCountryCode
Browse files Browse the repository at this point in the history
Signed-off-by: Leclerc Clement <[email protected]>
  • Loading branch information
clementleclercRTE committed Dec 3, 2024
1 parent 7c480e7 commit ed79865
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private UcteNodeCode changeOrderCode(String busId, char orderCode) {

private UcteNodeCode createNewUcteNodeId(String busId, VoltageLevel voltageLevel, char orderCode) {
String newNodeId = String.format("%05d", voltageLevelCounter);
char countryCode = getCountryCode(voltageLevel).getUcteCode();
char countryCode = UcteCountryCode.fromVoltagelevel(voltageLevel).getUcteCode();
char voltageLevelCode = UcteVoltageLevelCode.voltageLevelCodeFromVoltage(voltageLevel.getNominalV());

UcteNodeCode ucteNodeCode = new UcteNodeCode(
Expand All @@ -83,18 +83,6 @@ private UcteNodeCode createNewUcteNodeId(String busId, VoltageLevel voltageLevel
return ucteNodeCode;
}

private UcteCountryCode getCountryCode(VoltageLevel voltageLevel) {
Country country = voltageLevel.getSubstation()
.flatMap(Substation::getCountry)
.orElseThrow(() -> new UcteException(UcteConstants.NO_COUNTRY_ERROR));

try {
return UcteCountryCode.valueOf(country.name());
} catch (IllegalArgumentException e) {
throw new UcteException(String.format(UcteConstants.NO_UCTE_COUNTRY_ERROR, country.getName()));
}
}

private UcteElementId generateUcteElementId(String id, UcteNodeCode node1, UcteNodeCode node2) {
if (ucteElementIds.containsKey(id)) {
return ucteElementIds.get(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ private UcteConstants() {
public static final String ORDER_CODE = "orderCode";
public static final String POWER_PLANT_TYPE_PROPERTY_KEY = "powerPlantType";
public static final int DEFAULT_POWER_LIMIT = 9999;
public static final String NO_COUNTRY_ERROR = "No country for this substation";
public static final String NO_UCTE_CODE_ERROR = "No UCTE code found for id: ";
public static final String NO_UCTE_COUNTRY_ERROR = "No UCTE country code for ";
public static final List<Character> ORDER_CODES = List.of('1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ void testBranchElementIds() {
Branch<?> transformer1 = network.getBranch("NGEN_NHV1");
Branch<?> transformer2 = network.getBranch("NHV2_NLOAD");
Branch<?> line1 = network.getBranch("NHV1_NHV2_1");
Branch<?> line2 = network.getBranch("NHV1_NHV2_2");

UcteElementId transformerId1 = strategy.getUcteElementId(transformer1);
UcteElementId transformerId2 = strategy.getUcteElementId(transformer2);
UcteElementId lineId1 = strategy.getUcteElementId(line1);
UcteElementId lineId2 = strategy.getUcteElementId(line1);
UcteElementId lineId2 = strategy.getUcteElementId(line2);

assertAll(
() -> assertTrue(UcteElementId.isUcteElementId(transformerId1.toString())),
Expand Down
4 changes: 4 additions & 0 deletions ucte/ucte-network/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-api</artifactId>
</dependency>
</dependencies>

</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*/
package com.powsybl.ucte.network;

import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Substation;
import com.powsybl.iidm.network.VoltageLevel;

import java.util.Objects;

/**
Expand Down Expand Up @@ -121,4 +125,15 @@ public static boolean isUcteCountryCode(char character) {
}
}

public static UcteCountryCode fromVoltagelevel(VoltageLevel voltageLevel) {
Country country = voltageLevel.getSubstation()
.flatMap(Substation::getCountry)
.orElseThrow(() -> new UcteException("No UCTE country found for substation"));
try {
return UcteCountryCode.valueOf(country.name());
} catch (IllegalArgumentException e) {
throw new UcteException(String.format("No UCTE country found for " + country.name()));
}
}

}

0 comments on commit ed79865

Please sign in to comment.