Skip to content

Commit

Permalink
Merge pull request #27 from itesla/online_dev
Browse files Browse the repository at this point in the history
adds voltage level column (printing wf violations itools command); fi…
  • Loading branch information
mathbagu committed Jul 6, 2016
2 parents c7822d8 + 17f4984 commit a8af22f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LimitViolation>();
}
} 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LimitViolation> violations) {
private synchronized void storePCViolationsMetadata(String workflowId, String stateId, String contingencyId, List<LimitViolation> violations) {
try {
MVStore wfMVStore = getStore(workflowId);

Expand All @@ -1396,7 +1396,14 @@ private void storePCViolationsMetadata(String workflowId, String stateId, String
storedStatesMap.putIfAbsent(stateId, "1");
// save info about stored contingencies per state
MVMap<String, String> 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) {
Expand All @@ -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);

Expand All @@ -1422,7 +1429,14 @@ private void storePSLoadflowConvergence(String workflowId, String stateId, Strin
storedStatesMap.putIfAbsent(stateId, "1");
// save info about stored contingencies per state
MVMap<String, String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void run(CommandLine line) throws Exception {
String contingencyId = line.getOptionValue("contingency");
List<LimitViolation> 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);
Expand All @@ -110,7 +110,7 @@ public void run(CommandLine line) throws Exception {
Integer stateId = Integer.parseInt(line.getOptionValue("state"));
Map<String, List<LimitViolation>> 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);
Expand All @@ -131,7 +131,7 @@ public void run(CommandLine line) throws Exception {
String contingencyId = line.getOptionValue("contingency");
Map<Integer, List<LimitViolation>> 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);
Expand All @@ -151,7 +151,7 @@ public void run(CommandLine line) throws Exception {
} else {
Map<Integer, Map<String, List<LimitViolation>>> 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);
Expand Down Expand Up @@ -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";
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void run(CommandLine line) throws Exception {
OnlineStep step = OnlineStep.valueOf(line.getOptionValue("step"));
List<LimitViolation> 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);
Expand All @@ -109,7 +109,7 @@ public void run(CommandLine line) throws Exception {
Integer stateId = Integer.parseInt(line.getOptionValue("state"));
Map<OnlineStep, List<LimitViolation>> 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);
Expand All @@ -130,7 +130,7 @@ public void run(CommandLine line) throws Exception {
OnlineStep step = OnlineStep.valueOf(line.getOptionValue("step"));
Map<Integer, List<LimitViolation>> 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);
Expand All @@ -150,7 +150,7 @@ public void run(CommandLine line) throws Exception {
} else {
Map<Integer, Map<OnlineStep, List<LimitViolation>>> 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);
Expand Down Expand Up @@ -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";
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit a8af22f

Please sign in to comment.