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

Add CRAC content summary in creation report #1156

Merged
merged 6 commits into from
Oct 9, 2024
Merged
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 @@ -64,6 +64,18 @@ public void info(String infoReason) {
TECHNICAL_LOGS.info(message);
}

public void addSuccessfulImportMessage(Crac crac) {
creationReport.add(
"CRAC was successfully imported with %s contingencies, %s FlowCNECs, %s AngleCNECs, %s VoltageCNECs and %s remedial actions (%s range actions and %s network actions).".formatted(
crac.getContingencies().size(),
crac.getFlowCnecs().size(),
crac.getAngleCnecs().size(),
crac.getVoltageCnecs().size(),
crac.getRemedialActions().size(),
crac.getRangeActions().size(),
crac.getNetworkActions().size()));
}

public void printCreationReport() {
creationReport.forEach(BUSINESS_LOGS::info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void setCreationFailure() {

void setCreationSuccess(Crac crac) {
this.isCreationSuccessful = true;
this.creationReport.addSuccessfulImportMessage(crac);
this.crac = crac;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void testImportContingencies() throws IOException {
assertContingencyNotImported("Co-4", "Co-4-name", ELEMENT_NOT_FOUND_IN_NETWORK);
assertContingencyNotImported("Co-5", "Co-5-name", INCOMPLETE_DATA);

assertEquals(3, cracCreationContext.getCreationReport().getReport().size()); // 2 fake contingencies, 1 altered
assertEquals(4, cracCreationContext.getCreationReport().getReport().size()); // 2 fake contingencies, 1 altered, 1 CRAC content
}

@Test
Expand Down Expand Up @@ -828,8 +828,9 @@ void testFilterOnTimeseries() throws IOException {

setUpWithTimeseriesMrids("/cracs/CIM_2_timeseries.xml", baseNetwork, OffsetDateTime.parse("2021-04-01T23:00Z"), Set.of("TimeSeries1", "TimeSeries2", "TimeSeries3"));
assertEquals(2, importedCrac.getContingencies().size());
assertEquals(1, cracCreationContext.getCreationReport().getReport().size());
assertEquals(2, cracCreationContext.getCreationReport().getReport().size());
assertEquals("[WARN] Requested TimeSeries mRID \"TimeSeries3\" in CimCracCreationParameters was not found in the CRAC file.", cracCreationContext.getCreationReport().getReport().get(0));
assertEquals("CRAC was successfully imported with 2 contingencies, 0 FlowCNECs, 0 AngleCNECs, 0 VoltageCNECs and 0 remedial actions (0 range actions and 0 network actions).", cracCreationContext.getCreationReport().getReport().get(1));

setUpWithTimeseriesMrids("/cracs/CIM_2_timeseries.xml", baseNetwork, OffsetDateTime.parse("2021-04-01T23:00Z"), Set.of("TimeSeries1"));
assertEquals(1, importedCrac.getContingencies().size());
Expand Down Expand Up @@ -889,7 +890,7 @@ AUTO_INSTANT_ID, new VoltageMonitoredContingenciesAndThresholds(Set.of("Co-2-nam
assertNotNull(importedCrac.getVoltageCnec("[VC] _d77b61ef-61aa-4b22-95f6-b56ca080788d - Co-1 - curative"));
assertNotNull(importedCrac.getVoltageCnec("[VC] _d77b61ef-61aa-4b22-95f6-b56ca080788d - Co-3 - outage"));
assertEquals(7, cracCreationContext.getVoltageCnecCreationContexts().size());
assertEquals(7, cracCreationContext.getCreationReport().getReport().size());
assertEquals(8, cracCreationContext.getCreationReport().getReport().size());
assertTrue(cracCreationContext.getCreationReport().getReport().contains("[REMOVED] VoltageCnec with network element \"_2844585c-0d35-488d-a449-685bcd57afbf\", instant \"all\" and contingency \"all\" was not imported: INCONSISTENCY_IN_DATA. Element _2844585c-0d35-488d-a449-685bcd57afbf is not a voltage level."));
assertTrue(cracCreationContext.getCreationReport().getReport().contains("[REMOVED] VoltageCnec with network element \"_a708c3bc-465d-4fe7-b6ef-6fa6408a62b0\", instant \"all\" and contingency \"all\" was not imported: INCONSISTENCY_IN_DATA. Element _a708c3bc-465d-4fe7-b6ef-6fa6408a62b0 is not a voltage level."));
assertTrue(cracCreationContext.getCreationReport().getReport().contains("[REMOVED] VoltageCnec with network element \"all\", instant \"all\" and contingency \"Co-4-name\" was not imported: OTHER. Contingency does not exist in the CRAC or could not be imported."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import com.powsybl.contingency.Contingency;
import com.powsybl.openrao.commons.logs.RaoBusinessLogs;
import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.cracapi.CracCreationReport;
import com.powsybl.openrao.data.cracapi.cnec.AngleCnec;
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec;
import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec;
import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction;
import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
Expand Down Expand Up @@ -127,4 +136,34 @@ void testPrintReport() {
assertEquals("[INFO] [WARN] message1", logsList.get(0).toString());
assertEquals("[INFO] [ERROR] message2", logsList.get(1).toString());
}

@Test
void testAddSuccessfulImportMessage() {
Crac crac = Mockito.mock(Crac.class);
Contingency contingency1 = Mockito.mock(Contingency.class);
Contingency contingency2 = Mockito.mock(Contingency.class);
Contingency contingency3 = Mockito.mock(Contingency.class);
FlowCnec flowCnec1 = Mockito.mock(FlowCnec.class);
FlowCnec flowCnec2 = Mockito.mock(FlowCnec.class);
FlowCnec flowCnec3 = Mockito.mock(FlowCnec.class);
FlowCnec flowCnec4 = Mockito.mock(FlowCnec.class);
AngleCnec angleCnec1 = Mockito.mock(AngleCnec.class);
AngleCnec angleCnec2 = Mockito.mock(AngleCnec.class);
VoltageCnec voltageCnec = Mockito.mock(VoltageCnec.class);
PstRangeAction pstRangeAction = Mockito.mock(PstRangeAction.class);
NetworkAction networkAction1 = Mockito.mock(NetworkAction.class);
NetworkAction networkAction2 = Mockito.mock(NetworkAction.class);

Mockito.when(crac.getContingencies()).thenReturn(Set.of(contingency1, contingency2, contingency3));
Mockito.when(crac.getFlowCnecs()).thenReturn(Set.of(flowCnec1, flowCnec2, flowCnec3, flowCnec4));
Mockito.when(crac.getAngleCnecs()).thenReturn(Set.of(angleCnec1, angleCnec2));
Mockito.when(crac.getVoltageCnecs()).thenReturn(Set.of(voltageCnec));
Mockito.when(crac.getRemedialActions()).thenReturn(Set.of(pstRangeAction, networkAction1, networkAction2));
Mockito.when(crac.getRangeActions()).thenReturn(Set.of(pstRangeAction));
Mockito.when(crac.getNetworkActions()).thenReturn(Set.of(networkAction1, networkAction2));

cracCreationReport.addSuccessfulImportMessage(crac);
assertEquals(1, cracCreationReport.getReport().size());
assertEquals("CRAC was successfully imported with 3 contingencies, 4 FlowCNECs, 2 AngleCNECs, 1 VoltageCNECs and 3 remedial actions (1 range actions and 2 network actions).", cracCreationReport.getReport().get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ CsaProfileCracCreationContext creationFailure() {

CsaProfileCracCreationContext creationSuccess(Crac crac) {
this.isCreationSuccessful = true;
this.creationReport.addSuccessfulImportMessage(crac);
this.crac = crac;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ CseCracCreationContext creationFailure() {

CseCracCreationContext creationSuccess(Crac crac) {
this.isCreationSuccessful = true;
this.creationReport.addSuccessfulImportMessage(crac);
this.crac = crac;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ void cracCreationContextReport() throws IOException {
setUp("/cracs/cse_crac_1.xml");
List<String> creationReport = cracCreationContext.getCreationReport().getReport();
assertFalse(creationReport.isEmpty());
assertEquals(5, creationReport.size());
assertEquals(6, creationReport.size());
}

@Test
void cracCreationContextReport2() throws IOException {
setUp("/cracs/cse_crac_2.xml");
List<String> creationReport = cracCreationContext.getCreationReport().getReport();
assertFalse(creationReport.isEmpty());
assertEquals(4, creationReport.size());
assertEquals(5, creationReport.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ FbConstraintCreationContext creationFailure() {

FbConstraintCreationContext creationSucess(Crac crac) {
this.isCreationSuccessful = true;
this.creationReport.addSuccessfulImportMessage(crac);
this.crac = crac;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void testWrongTsCreationContext() throws IOException {
creationContext = (FbConstraintCreationContext) Crac.readWithContext("wrong_ts.xml", getClass().getResourceAsStream("/merged_cb/wrong_ts.xml"), network, timestamp, parameters);
Crac crac = creationContext.getCrac();

assertEquals(2, creationContext.getCreationReport().getReport().size());
assertEquals(3, creationContext.getCreationReport().getReport().size());

assertEquals(1, crac.getCnecs().size());
assertCriticalBranchNotImported("BE_CBCO_000001", NOT_FOR_REQUESTED_TIMESTAMP);
Expand All @@ -525,7 +525,7 @@ void testDuplicatePsts() throws IOException {
creationContext = (FbConstraintCreationContext) Crac.readWithContext("complex_variants_duplicate_psts.xml", getClass().getResourceAsStream("/merged_cb/complex_variants_duplicate_psts.xml"), network, timestamp, parameters);
Crac crac = creationContext.getCrac();

assertEquals(2, creationContext.getCreationReport().getReport().size());
assertEquals(3, creationContext.getCreationReport().getReport().size());

// RA_BE_0001 is one same PST as RA_BE_0002
// RA_BE_0002 has been prioritized due to alphabetical order
Expand Down
Loading