Skip to content

Commit

Permalink
Print actions taken in security analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
geofjamg committed Nov 8, 2016
1 parent 8b70c4c commit 27755c6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ abstract class LimitViolationsResult {

private final List<LimitViolation> limitViolations;

public LimitViolationsResult(boolean computationOk, List<LimitViolation> limitViolations) {
private final List<String> actionsTaken;

public LimitViolationsResult(boolean computationOk, List<LimitViolation> limitViolations, List<String> actionsTaken) {
this.computationOk = computationOk;
this.limitViolations = Objects.requireNonNull(limitViolations);
this.actionsTaken = Objects.requireNonNull(actionsTaken);
}

public boolean isComputationOk() {
Expand All @@ -30,4 +33,8 @@ public boolean isComputationOk() {
public List<LimitViolation> getLimitViolations() {
return limitViolations;
}

public List<String> getActionsTaken() {
return actionsTaken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import eu.itesla_project.contingency.Contingency;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand All @@ -20,7 +21,11 @@ public class PostContingencyResult extends LimitViolationsResult {
private final Contingency contingency;

public PostContingencyResult(Contingency contingency, boolean computationOk, List<LimitViolation> limitViolations) {
super(computationOk, limitViolations);
this(contingency, computationOk, limitViolations, Collections.emptyList());
}

public PostContingencyResult(Contingency contingency, boolean computationOk, List<LimitViolation> limitViolations, List<String> actionsTaken) {
super(computationOk, limitViolations, actionsTaken);
this.contingency = Objects.requireNonNull(contingency);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package eu.itesla_project.security;

import java.util.Collections;
import java.util.List;

/**
Expand All @@ -15,6 +16,10 @@
public class PreContingencyResult extends LimitViolationsResult {

public PreContingencyResult(boolean computationOk, List<LimitViolation> limitViolations) {
super(computationOk, limitViolations);
this(computationOk, limitViolations, Collections.emptyList());
}

public PreContingencyResult(boolean computationOk, List<LimitViolation> limitViolations, List<String> actionsTaken) {
super(computationOk, limitViolations, actionsTaken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,34 @@ public static void printPreContingencyViolations(SecurityAnalysisResult result,
Objects.requireNonNull(result);
Objects.requireNonNull(writer);
Objects.requireNonNull(formatterFactory);
List<LimitViolation> filteredLimitViolations = limitViolationFilter != null
? limitViolationFilter.apply(result.getPreContingencyResult().getLimitViolations())
: result.getPreContingencyResult().getLimitViolations();
try (TableFormatter formatter = formatterFactory.create(writer,
"Pre-contingency violations",
Locale.getDefault(),
new Column("Action"),
new Column("Equipment"),
new Column("Violation type"),
new Column("Violation name"),
new Column("Value"),
new Column("Limit"),
new Column("Charge %"))) {
for (String action : result.getPreContingencyResult().getActionsTaken()) {
formatter.writeCell(action)
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell();
}
List<LimitViolation> filteredLimitViolations = limitViolationFilter != null
? limitViolationFilter.apply(result.getPreContingencyResult().getLimitViolations())
: result.getPreContingencyResult().getLimitViolations();
filteredLimitViolations.stream()
.sorted((o1, o2) -> o1.getSubject().getId().compareTo(o2.getSubject().getId()))
.forEach(violation -> {
try {
formatter.writeCell(violation.getSubject().getId())
formatter.writeEmptyCell()
.writeCell(violation.getSubject().getId())
.writeCell(violation.getLimitType().name())
.writeCell(Objects.toString(violation.getLimitName(), ""))
.writeCell(violation.getValue())
Expand All @@ -229,6 +240,7 @@ public static void printPostContingencyViolations(SecurityAnalysisResult result,
Locale.getDefault(),
new Column("Contingency"),
new Column("Status"),
new Column("Action"),
new Column("Equipment"),
new Column("Violation type"),
new Column("Violation name"),
Expand All @@ -251,13 +263,27 @@ public static void printPostContingencyViolations(SecurityAnalysisResult result,
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell();

for (String action : postContingencyResult.getActionsTaken()) {
formatter.writeEmptyCell()
.writeEmptyCell()
.writeCell(action)
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell();
}

filteredLimitViolations.stream()
.sorted((o1, o2) -> o1.getSubject().getId().compareTo(o2.getSubject().getId()))
.forEach(violation -> {
try {
formatter.writeEmptyCell()
.writeEmptyCell()
.writeEmptyCell()
.writeCell(violation.getSubject().getId())
.writeCell(violation.getLimitType().name())
Expand Down

0 comments on commit 27755c6

Please sign in to comment.