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

Feature/upgrade powsybl core to 4.10.1 #55

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -30,7 +30,8 @@ public static MetrixConfig load() {
}

public static MetrixConfig load(PlatformConfig platformConfig) {
ModuleConfig moduleConfig = platformConfig.getModuleConfig("metrix");
ModuleConfig moduleConfig = platformConfig.getOptionalModuleConfig("metrix")
.orElseThrow(() -> new IllegalStateException("Metrix module configuration could not be found"));
Path homeDir = moduleConfig.getPathProperty("home-dir");
boolean debug = moduleConfig.getBooleanProperty("debug", DEFAULT_DEBUG);
boolean constantLossFactor = moduleConfig.getOptionalBooleanProperty("constant-loss-factor").orElse(DEFAULT_CONSTANT_LOAD_FACTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ImmutableMap;
import com.powsybl.commons.config.ModuleConfig;
import com.powsybl.commons.config.PlatformConfig;

import java.util.Objects;
Expand All @@ -26,17 +25,15 @@ public class MetrixParameters {

public static MetrixParameters load() {
MetrixParameters parameters = new MetrixParameters();
if (PlatformConfig.defaultConfig().moduleExists("metrix-default-parameters")) {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("metrix-default-parameters");
if (config != null) {
parameters.setComputationType(config.getOptionalEnumProperty("computation-type", MetrixComputationType.class)
.orElseGet(() -> config.getEnumProperty("computationType", MetrixComputationType.class, DEFAULT_COMPUTATION_TYPE)));
parameters.setLossFactor(config.getOptionalFloatProperty("loss-factor")
.orElseGet(() -> config.getFloatProperty("lossFactor", DEFAULT_LOSS_FACTOR)));
parameters.setNominalU(config.getOptionalIntProperty("nominal-u")
.orElseGet(() -> config.getIntProperty("nominalU", DEFAULT_NOMINAL_U)));
}
}
PlatformConfig.defaultConfig().getOptionalModuleConfig("metrix-default-parameters")
.ifPresent(config -> {
parameters.setComputationType(config.getOptionalEnumProperty("computation-type", MetrixComputationType.class)
.orElseGet(() -> config.getEnumProperty("computationType", MetrixComputationType.class, DEFAULT_COMPUTATION_TYPE)));
parameters.setLossFactor(config.getOptionalFloatProperty("loss-factor")
.orElseGet(() -> config.getFloatProperty("lossFactor", DEFAULT_LOSS_FACTOR)));
parameters.setNominalU(config.getOptionalIntProperty("nominal-u")
.orElseGet(() -> config.getIntProperty("nominalU", DEFAULT_NOMINAL_U)));
});
return parameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.ResourceBundle;

import static com.powsybl.metrix.integration.AbstractCompareTxt.compareStreamTxt;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -48,7 +49,8 @@ void loadContingenciesTest() throws IOException {
metrixInputAnalysis.runAnalysis();
bufferedWriter.flush();
String actual = writer.toString();
assertNotNull(compareStreamTxt(getClass().getResourceAsStream("/expected/metrixContingencyAnalysis.csv"),
String expectedFilePath = ResourceBundle.getBundle("expected.contents").getString("metrix_contingency_analysis.file");
assertNotNull(compareStreamTxt(getClass().getResourceAsStream(expectedFilePath),
new ByteArrayInputStream(actual.getBytes(StandardCharsets.UTF_8))));
}
}
Expand All @@ -69,7 +71,8 @@ void metrixDslDataContingencyAnalysisTest() throws IOException {
metrixInputAnalysis.runAnalysis();
bufferedWriter.flush();
String actual = writer.toString();
assertNotNull(compareStreamTxt(getClass().getResourceAsStream("/expected/metrixDslDataContingencyAnalysis.csv"),
String expectedFilePath = ResourceBundle.getBundle("expected.contents").getString("metrix_dsl_data_contingency_analysis.file");
assertNotNull(compareStreamTxt(getClass().getResourceAsStream(expectedFilePath),
new ByteArrayInputStream(actual.getBytes(StandardCharsets.UTF_8))));
}
}
Expand All @@ -88,7 +91,8 @@ void metrixRemedialContingencyAnalysisTest() throws IOException {
metrixInputAnalysis.runAnalysis();
bufferedWriter.flush();
String actual = writer.toString();
assertNotNull(compareStreamTxt(getClass().getResourceAsStream("/expected/metrixRemedialContingencyAnalysis.csv"),
String expectedFilePath = ResourceBundle.getBundle("expected.contents").getString("metrix_remedial_contingency_analysis.file");
assertNotNull(compareStreamTxt(getClass().getResourceAsStream(expectedFilePath),
new ByteArrayInputStream(actual.getBytes(StandardCharsets.UTF_8))));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,7 +64,8 @@ void copyDicShouldCopyFilesMetrixAnyDotDic() {
Assertions.assertThat(actual).hasSize(1);
Assertions.assertThat(actual.get(0).getName(0)).isEqualTo("METRIXb.dic");
Assertions.assertThat(results).hasSize(1);
Assertions.assertThat(results.get(0)).isEqualTo("METRIXb.dic->/testOut/METRIXb.dic");
String fSep = FileSystems.getDefault().getSeparator();
Assertions.assertThat(results.get(0)).isEqualTo("METRIXb.dic->" + fSep + "testOut" + fSep + "METRIXb.dic");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

import java.io.*;
import java.util.Collections;
import java.util.ResourceBundle;

public class MetrixRemedialAnalysisTest {

private Network network;

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("expected.contents");

@BeforeEach
public void setUp() {
network = NetworkXml.read(getClass().getResourceAsStream("/simpleNetwork.xml"));
Expand Down Expand Up @@ -67,127 +70,127 @@ void emptyRemedialFileTest() throws IOException {
void invalidRemedialHeaderCommentLineTest() throws IOException {
remedialTest(
"// comment",
"ERROR;Remedials;Remedial file will not be recognized because line 1 contains a comment"
RESOURCE_BUNDLE.getString("invalid_remedial_header_comment")
);
}

@Test
void invalidRemedialHeaderCommentTest() throws IOException {
remedialTest(
"/* comment",
"ERROR;Remedials;Remedial file will not be recognized because line 1 contains a comment"
RESOURCE_BUNDLE.getString("invalid_remedial_header_comment")
);
}

@Test
void invalidRemedialLineCommentLineTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", "// comment"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 contains a comment"
RESOURCE_BUNDLE.getString("invalid_remedial_line_comment")
);
}

@Test
void invalidRemedialLineCommentTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", "/* comment"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 contains a comment"
RESOURCE_BUNDLE.getString("invalid_remedial_line_comment")
);
}

@Test
void invalidRemedialHeaderEndLineTest() throws IOException {
remedialTest(
"line",
"ERROR;Remedials;Remedial file will not be recognized because line 1 does not end with semicolon"
RESOURCE_BUNDLE.getString("invalid_remedial_header_end_line")
);
}

@Test
void invalidRemedialLineEndLineTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", "line"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 does not end with semicolon"
RESOURCE_BUNDLE.getString("invalid_remedial_line_end_line")
);
}

@Test
void invalidRemedialHeaderNbColumnTest() throws IOException {
remedialTest(
"column1;column2;column3;",
"ERROR;Remedials;Remedial file will not be recognized because line 1 is malformed (header)"
RESOURCE_BUNDLE.getString("invalid_remedial_header_malformed")
);
}

@Test
void invalidRemedialHeaderNbColumnEmptyTest() throws IOException {
remedialTest(
";column;",
"ERROR;Remedials;Remedial file will not be recognized because line 1 is malformed (header)"
RESOURCE_BUNDLE.getString("invalid_remedial_header_malformed")
);
}

@Test
void invalidRemedialHeaderNbColumnNumberEmptyTest() throws IOException {
remedialTest(
"NB;;",
"ERROR;Remedials;Remedial file will not be recognized because line 1 is malformed (header)"
RESOURCE_BUNDLE.getString("invalid_remedial_header_malformed")
);
}

@Test
void invalidRemedialHeaderNbMissingTest() throws IOException {
remedialTest(
"notNB;column;",
"ERROR;Remedials;Remedial file will not be recognized because line 1 is malformed (header)"
RESOURCE_BUNDLE.getString("invalid_remedial_header_malformed")
);
}

@Test
void invalidRemedialHeaderNbColumnNumberMissingTest() throws IOException {
remedialTest(
"NB;column;",
"ERROR;Remedials;Remedial file will not be recognized because line 1 is malformed (header)"
RESOURCE_BUNDLE.getString("invalid_remedial_header_malformed")
);
}

@Test
void invalidRemedialHeaderNbColumnNumberWrongIntegerTest() throws IOException {
remedialTest(
"NB;-1;",
"ERROR;Remedials;Remedial file will not be recognized because line 1 is malformed (header)"
RESOURCE_BUNDLE.getString("invalid_remedial_header_malformed")
);
}

@Test
void invalidRemedialLineNbColumnTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", "column;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 is malformed"
RESOURCE_BUNDLE.getString("invalid_remedial_line_malformed")
);
}

@Test
void invalidRemedialLineNbColumnEmptyTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", ";;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 is malformed"
RESOURCE_BUNDLE.getString("invalid_remedial_line_malformed")
);
}

@Test
void invalidRemedialLineNbActionMissingTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", "ctyId;column;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 is malformed"
RESOURCE_BUNDLE.getString("invalid_remedial_line_malformed")
);
}

@Test
void invalidRemediaLineNbActionWrongIntegerTest() throws IOException {
remedialTest(
String.join(System.lineSeparator(), "NB;1;", "ctyId;-1;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 is malformed"
RESOURCE_BUNDLE.getString("invalid_remedial_line_malformed")
);
}

Expand All @@ -200,7 +203,7 @@ void invalidRemedialLineContingencyEmptyTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", ";1;FP.AND1 FVERGE1 2;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 contains an empty element"
RESOURCE_BUNDLE.getString("invalid_remedial_line_empty_element")
);
}

Expand All @@ -213,7 +216,7 @@ void invalidRemedialLineNbActionEmptyTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;;FP.AND1 FVERGE1 2;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 contains an empty element"
RESOURCE_BUNDLE.getString("invalid_remedial_line_empty_element")
);
}

Expand All @@ -226,7 +229,7 @@ void invalidRemedialLineNoActionTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;1;;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 is malformed"
RESOURCE_BUNDLE.getString("invalid_remedial_line_malformed")
);
}

Expand All @@ -239,7 +242,7 @@ void invalidRemedialLineActionEmptyTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;2;;FP.AND1 FVERGE1 2;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 contains an empty element"
RESOURCE_BUNDLE.getString("invalid_remedial_line_empty_element")
);
}

Expand All @@ -252,7 +255,7 @@ void invalidRemedialLineBranchToOpenActionTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;2;action;+FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment action does not exist in the network"
RESOURCE_BUNDLE.getString("invalid_remedial_line_action_does_not_exist")
);
}

Expand All @@ -265,7 +268,7 @@ void invalidRemedialLineBranchToCloseActionTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;2;+action;FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment action does not exist in the network"
RESOURCE_BUNDLE.getString("invalid_remedial_line_action_does_not_exist")
);
}

Expand All @@ -278,7 +281,7 @@ void invalidRemedialLineBranchToOpenTypeTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;2;FSSV.O11_G;FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment FSSV.O11_G is not a Branch or Switch type"
RESOURCE_BUNDLE.getString("invalid_remedial_line_equipment_is_not_a_branch")
);
}

Expand All @@ -291,7 +294,7 @@ void invalidRemedialLineBranchToCloseTypeTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;2;+FSSV.O11_G;FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment FSSV.O11_G is not a Branch or Switch type"
RESOURCE_BUNDLE.getString("invalid_remedial_line_equipment_is_not_a_branch")
);
}

Expand All @@ -304,7 +307,7 @@ void invalidRemedialLineConstraintTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId|equipment;1;FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment equipment does not exist in the network"
RESOURCE_BUNDLE.getString("invalid_remedial_line_constraint")
);
}

Expand All @@ -317,7 +320,7 @@ void invalidRemedialLineConstraintTypeTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId|FSSV.O11_G;1;FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment FSSV.O11_G is not a Branch type"
RESOURCE_BUNDLE.getString("invalid_remedial_line_constraint_type")
);
}

Expand All @@ -333,7 +336,7 @@ void invalidRemedialLineEmptyConstraintTest() throws IOException {
contingenciesProvider,
metrixDslData,
String.join(System.lineSeparator(), "NB;1;", "ctyId||FS.BIS1 FVALDI1 1;1;FP.AND1 FVERGE1 2;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 contains an empty element"
RESOURCE_BUNDLE.getString("invalid_remedial_line_empty_element")
);
}

Expand All @@ -346,7 +349,7 @@ void invalidRemedialLineConstraintMonitoredTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId|FS.BIS1 FVALDI1 1;1;FP.AND1 FVERGE1 2;"),
"WARNING;Remedials;The remedial at line 2 will not be taken into account because equipment FS.BIS1 FVALDI1 1 is not monitored on contingency"
RESOURCE_BUNDLE.getString("invalid_remedial_line_constraint_monitored")
);
}

Expand All @@ -358,7 +361,7 @@ void invalidNbRemedialMoreLinesTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;2;", "ctyId;1;FP.AND1 FVERGE1 2;"),
"ERROR;Remedials;Remedial file will not be recognized because line 2 because remedial number in header (NB = 2) is greater than the line number of the remedial (1)"
RESOURCE_BUNDLE.getString("invalid_remedial_more_lines")
);
}

Expand All @@ -370,7 +373,7 @@ void invalidNbRemedialLessLinesTest() throws IOException {
remedialTest(
contingenciesProvider,
String.join(System.lineSeparator(), "NB;1;", "ctyId;1;FP.AND1 FVERGE1 2;", "ctyId;1;FS.BIS1 FVALDI1 1;"),
"WARNING;Remedials;The remedial at line 3 will not be taken into account because the line number of the remedial is greater than the remedial number in header (NB = 1)"
RESOURCE_BUNDLE.getString("invalid_remedial_less_lines")
);
}

Expand Down
Loading