diff --git a/online-workflow/src/main/java/eu/itesla_project/online/StateAnalyzer.java b/online-workflow/src/main/java/eu/itesla_project/online/StateAnalyzer.java index 02cf8d64..4fab037e 100644 --- a/online-workflow/src/main/java/eu/itesla_project/online/StateAnalyzer.java +++ b/online-workflow/src/main/java/eu/itesla_project/online/StateAnalyzer.java @@ -367,13 +367,13 @@ public Void call() throws Exception { logger.info("{}: computing post contingency violations for contingency {}", stateId, contingency.getId()); violations = Security.checkLimits(network, CurrentLimitType.PATL, Integer.MAX_VALUE, parameters.getLimitReduction()); if ( violations == null || violations.isEmpty() ) { - logger.info("{}: no post contingency violations for state {} and contingency {}", stateId, contingency.getId()); + logger.info("{}: no post contingency violations for contingency {}", stateId, contingency.getId()); violations = new ArrayList(); } } else { logger.info("{}: post contingency loadflow does not converge for contingency {}, skipping computing post contingency violations", stateId, contingency.getId()); } - logger.info("{}: storing post contingency violations for state {} and contingency {} in online db", stateId, contingency.getId()); + logger.info("{}: storing post contingency violations/loadflow results for contingency {} in online db", stateId, contingency.getId()); onlineDb.storePostContingencyViolations(context.getWorkflowId(), Integer.valueOf(stateId), contingency.getId(), loadflowConverge, violations); network.getStateManager().setWorkingState(stateId); // network.getStateManager().removeState(postContingencyStateId); diff --git a/online-workflow/src/main/java/eu/itesla_project/online/db/OnlineDbMVStore.java b/online-workflow/src/main/java/eu/itesla_project/online/db/OnlineDbMVStore.java index 165c1e26..9f05f4e6 100644 --- a/online-workflow/src/main/java/eu/itesla_project/online/db/OnlineDbMVStore.java +++ b/online-workflow/src/main/java/eu/itesla_project/online/db/OnlineDbMVStore.java @@ -1380,7 +1380,7 @@ public void storePostContingencyViolations(String workflowId, Integer stateId, S storePSLoadflowConvergence(workflowId, stateIdStr, contingencyId, loadflowConverge); } - private void storePCViolationsMetadata(String workflowId, String stateId, String contingencyId, List violations) { + private synchronized void storePCViolationsMetadata(String workflowId, String stateId, String contingencyId, List violations) { try { MVStore wfMVStore = getStore(workflowId); @@ -1396,7 +1396,14 @@ private void storePCViolationsMetadata(String workflowId, String stateId, String storedStatesMap.putIfAbsent(stateId, "1"); // save info about stored contingencies per state MVMap stateContingencyMap = wfMVStore.openMap(stateId + STORED_PC_VIOLATIONS_CONTINGENCIES_MAP_SUFFIX, mapBuilder); - stateContingencyMap.putIfAbsent(contingencyId, ""); + LOGGER.info("storePCViolationsMetadata: Adding contingency {} to map {} for workflow {}, state {}", + contingencyId, + stateId + STORED_PC_VIOLATIONS_CONTINGENCIES_MAP_SUFFIX, + workflowId, + stateId + ); + //stateContingencyMap.putIfAbsent(contingencyId, ""); + stateContingencyMap.put(contingencyId, ""); wfMVStore.commit(); } catch(Throwable e) { @@ -1406,7 +1413,7 @@ private void storePCViolationsMetadata(String workflowId, String stateId, String } } - private void storePSLoadflowConvergence(String workflowId, String stateId, String contingencyId, boolean loadflowConverge) { + private synchronized void storePSLoadflowConvergence(String workflowId, String stateId, String contingencyId, boolean loadflowConverge) { try { MVStore wfMVStore = getStore(workflowId); @@ -1422,7 +1429,14 @@ private void storePSLoadflowConvergence(String workflowId, String stateId, Strin storedStatesMap.putIfAbsent(stateId, "1"); // save info about stored contingencies per state MVMap stateContingencyMap = wfMVStore.openMap(stateId + STORED_PC_LOADFLOW_CONTINGENCIES_MAP_SUFFIX, mapBuilder); - stateContingencyMap.putIfAbsent(contingencyId, Boolean.toString(loadflowConverge)); + LOGGER.info("storePSLoadflowConvergence: Adding contingency {} to map {} for workflow {}, state {}", + contingencyId, + stateId + STORED_PC_LOADFLOW_CONTINGENCIES_MAP_SUFFIX, + workflowId, + stateId + ); + //stateContingencyMap.putIfAbsent(contingencyId, Boolean.toString(loadflowConverge)); + stateContingencyMap.put(contingencyId, Boolean.toString(loadflowConverge)); wfMVStore.commit(); } catch(Throwable e) { diff --git a/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowPostContingencyViolationsTool.java b/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowPostContingencyViolationsTool.java index 8e21d780..4d0cb67b 100644 --- a/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowPostContingencyViolationsTool.java +++ b/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowPostContingencyViolationsTool.java @@ -97,7 +97,7 @@ public void run(CommandLine line) throws Exception { String contingencyId = line.getOptionValue("contingency"); List violations = onlinedb.getPostContingencyViolations(workflowId, stateId, contingencyId); if ( violations != null && !violations.isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -110,7 +110,7 @@ public void run(CommandLine line) throws Exception { Integer stateId = Integer.parseInt(line.getOptionValue("state")); Map> stateViolations = onlinedb.getPostContingencyViolations(workflowId, stateId); if ( stateViolations != null && !stateViolations.keySet().isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -131,7 +131,7 @@ public void run(CommandLine line) throws Exception { String contingencyId = line.getOptionValue("contingency"); Map> contingencyViolations = onlinedb.getPostContingencyViolations(workflowId, contingencyId); if ( contingencyViolations != null && !contingencyViolations.keySet().isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -151,7 +151,7 @@ public void run(CommandLine line) throws Exception { } else { Map>> wfViolations = onlinedb.getPostContingencyViolations(workflowId); if ( wfViolations != null && !wfViolations.keySet().isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -180,7 +180,7 @@ public void run(CommandLine line) throws Exception { } private void printHeaders(Table table, CsvWriter cvsWriter) throws IOException { - String[] headers = new String[7]; + String[] headers = new String[8]; int i = 0; table.addCell("State", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "State"; @@ -196,6 +196,8 @@ private void printHeaders(Table table, CsvWriter cvsWriter) throws IOException { headers[i++] = "Limit"; table.addCell("Limit Reduction", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Limit Reduction"; + table.addCell("Voltage Level", new CellStyle(CellStyle.HorizontalAlign.center)); + headers[i++] = "Voltage Level"; cvsWriter.writeRecord(headers); } @@ -206,7 +208,7 @@ public int compare(LimitViolation o1, LimitViolation o2) { } }); for (LimitViolation violation : violations) { - String[] values = new String[7]; + String[] values = new String[8]; int i = 0; table.addCell(Integer.toString(stateId), new CellStyle(CellStyle.HorizontalAlign.right)); values[i++] = Integer.toString(stateId); @@ -222,6 +224,8 @@ public int compare(LimitViolation o1, LimitViolation o2) { values[i++] = Float.toString(violation.getLimit()); table.addCell(Float.toString(violation.getLimitReduction()), new CellStyle(CellStyle.HorizontalAlign.right)); values[i++] = Float.toString(violation.getLimitReduction()); + table.addCell(Float.toString(violation.getBaseVoltage()), new CellStyle(CellStyle.HorizontalAlign.right)); + values[i++] = Float.toString(violation.getBaseVoltage()); cvsWriter.writeRecord(values); } } diff --git a/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowViolationsTool.java b/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowViolationsTool.java index d59a4633..8edfaab6 100644 --- a/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowViolationsTool.java +++ b/online-workflow/src/main/java/eu/itesla_project/online/tools/PrintOnlineWorkflowViolationsTool.java @@ -96,7 +96,7 @@ public void run(CommandLine line) throws Exception { OnlineStep step = OnlineStep.valueOf(line.getOptionValue("step")); List violations = onlinedb.getViolations(workflowId, stateId, step); if ( violations != null && !violations.isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -109,7 +109,7 @@ public void run(CommandLine line) throws Exception { Integer stateId = Integer.parseInt(line.getOptionValue("state")); Map> stateViolations = onlinedb.getViolations(workflowId, stateId); if ( stateViolations != null && !stateViolations.keySet().isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -130,7 +130,7 @@ public void run(CommandLine line) throws Exception { OnlineStep step = OnlineStep.valueOf(line.getOptionValue("step")); Map> stepViolations = onlinedb.getViolations(workflowId, step); if ( stepViolations != null && !stepViolations.keySet().isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -150,7 +150,7 @@ public void run(CommandLine line) throws Exception { } else { Map>> wfViolations = onlinedb.getViolations(workflowId); if ( wfViolations != null && !wfViolations.keySet().isEmpty() ) { - Table table = new Table(7, BorderStyle.CLASSIC_WIDE); + Table table = new Table(8, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); printHeaders(table, cvsWriter); @@ -179,7 +179,7 @@ public void run(CommandLine line) throws Exception { } private void printHeaders(Table table, CsvWriter cvsWriter) throws IOException { - String[] headers = new String[7]; + String[] headers = new String[8]; int i = 0; table.addCell("State", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "State"; @@ -195,6 +195,8 @@ private void printHeaders(Table table, CsvWriter cvsWriter) throws IOException { headers[i++] = "Limit"; table.addCell("Limit Reduction", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Limit Reduction"; + table.addCell("Voltage Level", new CellStyle(CellStyle.HorizontalAlign.center)); + headers[i++] = "Voltage Level"; cvsWriter.writeRecord(headers); } @@ -205,7 +207,7 @@ public int compare(LimitViolation o1, LimitViolation o2) { } }); for (LimitViolation violation : violations) { - String[] values = new String[7]; + String[] values = new String[8]; int i = 0; table.addCell(Integer.toString(stateId), new CellStyle(CellStyle.HorizontalAlign.right)); values[i++] = Integer.toString(stateId); @@ -221,6 +223,8 @@ public int compare(LimitViolation o1, LimitViolation o2) { values[i++] = Float.toString(violation.getLimit()); table.addCell(Float.toString(violation.getLimitReduction()), new CellStyle(CellStyle.HorizontalAlign.right)); values[i++] = Float.toString(violation.getLimitReduction()); + table.addCell(Float.toString(violation.getBaseVoltage()), new CellStyle(CellStyle.HorizontalAlign.right)); + values[i++] = Float.toString(violation.getBaseVoltage()); cvsWriter.writeRecord(values); } }