private void printFailures(Map<Integer, Map<String, Boolean>> loadflowConvergence, String workflowId, String basecaseId, String contingencyId, Integer stateId, TableFormatter formatter) { if (loadflowConvergence != null && !loadflowConvergence.isEmpty() && loadflowConvergence.containsKey(stateId) && !loadflowConvergence.get(stateId).isEmpty() && loadflowConvergence.get(stateId).containsKey(contingencyId)) { if (!loadflowConvergence.get(stateId).get(contingencyId)) { try { formatter.writeCell(workflowId); formatter.writeCell(basecaseId); formatter.writeCell(contingencyId); formatter.writeCell(stateId); formatter.writeCell(OnlineStep.POSTCONTINGENCY_LOAD_FLOW.name()); formatter.writeCell("Post contingency load flow does not converge"); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeEmptyCell(); } catch (IOException e) { throw new RuntimeException(e); } } } }
public SecurityAnalysisResultComparisonWriter write(Boolean computationOk1, Boolean computationOk2, boolean equivalent) { checkInput(computationOk1, computationOk2); try { formatter = contingency == null ? formatter.writeEmptyCell() : formatter.writeCell(contingency); formatter = computationOk1 == null ? formatter.writeEmptyCells(1) : formatter.writeCell(getStatus(computationOk1)); formatter = computationOk2 == null ? formatter.writeEmptyCells(1) : formatter.writeCell(getStatus(computationOk2)); formatter.writeEmptyCells(11); formatter.writeCell(getComparison(equivalent)); } catch (IOException e) { LOGGER.error("Error writing security analysis results computation status comparison: {}", e.getMessage()); } return this; }
private static void write(TableFormatter formatter) throws IOException { formatter.writeEmptyCells(8) .writeCell(2).writeCell(Double.NaN).writeCell(2.4f).writeCell(true).writeEmptyCell() .writeCell('a').writeCell("aaa").writeEmptyCells(1) .writeEmptyLines(2) .writeCell(3).writeCell(4.2).writeCell(Float.NaN).writeCell(false).writeEmptyCell() .writeCell('b').writeCell("bbb").writeEmptyLine(); }
@Test public void testEmptyLines() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8); AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config, new Column("column1").setColspan(4), new Column("column2").setColspan(2))) { formatter.writeCell("Line:1 Cell:1") .writeCell("Line:1 Cell:2") .writeCell("Line:1 Cell:3") .writeEmptyLine(); } assertEquals("+--------------------------------------------------+---------+\n" + "| column1 | column2 |\n" + "+--------------------------------------------------+---------+\n" + "| Line:1 Cell:1 | Line:1 Cell:2 | Line:1 Cell:3 | | | |\n" + "+---------------+---------------+---------------+--+--+------+" + System.lineSeparator(), new String(bos.toByteArray(), StandardCharsets.UTF_8)); } }
@Override public void close() throws IOException { formatter.close(); }
private void writeTemporaryCurrentLimits(CurrentLimits limits, TableFormatter formatter, String branchId, boolean side1, String sideId) throws IOException { int branchNum = mapper.getInt(AmplSubset.BRANCH, branchId); for (TemporaryLimit tl : limits.getTemporaryLimits()) { String limitId = branchId + "_" + sideId + "_" + tl.getAcceptableDuration(); int limitNum = mapper.getInt(AmplSubset.TEMPORARY_CURRENT_LIMIT, limitId); formatter.writeCell(variantIndex) .writeCell(limitNum) .writeCell(branchNum) .writeCell(side1 ? 1 : 2) .writeCell(tl.getValue()) .writeCell(tl.getAcceptableDuration()) .writeCell(faultNum) .writeCell(actionNum); } }
private void printViolations(String workflowId, String basecaseId, String contingencyId, Integer stateId, OnlineStep step, List<LimitViolation> violations, TableFormatter formatter) { if (violations != null && !violations.isEmpty()) { violations.stream().sorted(Comparator.comparing(LimitViolation::getLimitType)).forEach(violation -> { if (violation != null) { try { formatter.writeCell(workflowId); formatter.writeCell(basecaseId); formatter.writeCell(contingencyId); formatter.writeCell(stateId); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeCell(ViolationType.STEADY_STATE.name()); formatter.writeCell(violation.getLimitType().name()); formatter.writeCell(step.name()); formatter.writeCell(violation.getSubjectId()); formatter.writeCell(violation.getValue()); formatter.writeCell(violation.getLimit()); } catch (IOException e) { throw new RuntimeException(e); } } }); } }
public SecurityAnalysisResultComparisonWriter write(List<String> actions1, List<String> actions2, boolean equivalent) { checkInput(actions1, actions2); if (noActions(actions1, actions2)) { return this; // skip actions line in cvs file if there are no actions } try { formatter = contingency == null ? formatter.writeEmptyCell() : formatter.writeCell(contingency); formatter.writeEmptyCells(11); formatter = actions1 == null ? formatter.writeEmptyCell() : formatter.writeCell(actions1.toString()); formatter = actions2 == null ? formatter.writeEmptyCell() : formatter.writeCell(actions2.toString()); formatter.writeCell(getComparison(equivalent)); } catch (IOException e) { LOGGER.error("Error writing security analysis results actions comparison: {}", e.getMessage()); } return this; }
private void writeThreeWindingsTransformerMiddleBuses(AmplExportContext context, TableFormatter formatter) throws IOException { for (ThreeWindingsTransformer twt : network.getThreeWindingsTransformers()) { int middleCcNum = getThreeWindingsTransformerMiddleBusComponentNum(context, twt); if (connectedComponentToExport(middleCcNum)) { String middleBusId = getThreeWindingsTransformerMiddleBusId(twt); String middleVlId = getThreeWindingsTransformerMiddleVoltageLevelId(twt); context.busIdsToExport.add(middleBusId); int middleBusNum = mapper.getInt(AmplSubset.BUS, middleBusId); int middleVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, middleVlId); formatter.writeCell(variantIndex) .writeCell(middleBusNum) .writeCell(middleVlNum) .writeCell(middleCcNum) .writeCell(Float.NaN) .writeCell(Double.NaN) .writeCell(0.0) .writeCell(0.0) .writeCell(faultNum) .writeCell(actionNum) .writeCell(middleBusId); } } }
private static Consumer<? super LimitViolation> writeLimitViolation(Network network, TableFormatter formatter, boolean writeName) { return violation -> { try { formatter.writeEmptyCell() .writeEmptyCell() .writeEmptyCell() .writeCell(writeName ? violation.getSubjectName() : violation.getSubjectId()) .writeCell(LimitViolationHelper.getVoltageLevelId(violation, network, writeName)) .writeCell(LimitViolationHelper.getCountry(violation, network).name()) .writeCell((int) LimitViolationHelper.getNominalVoltage(violation, network)) .writeCell(violation.getLimitType().name()) .writeCell(getViolationName(violation)) .writeCell(violation.getValue()) .writeCell(getViolationLimit(violation)) .writeCell(getAbsValueLimit(violation)) .writeCell(getViolationRate(violation)); } catch (IOException e) { throw new UncheckedIOException(e); } }; }
private void writeViolation(LimitViolation violation) throws IOException { if (violation == null) { formatter.writeEmptyCells(3); } else { formatter = violation.getLimitName() == null ? formatter.writeEmptyCell() : formatter.writeCell(violation.getLimitName()); formatter.writeCell(violation.getValue()) .writeCell(getViolationLimit(violation)); } }
private void writeRatioTapChanger(TableFormatter formatter, String id, double zb2, double reactance, RatioTapChanger rtc) throws IOException { int num = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, id); for (int position = rtc.getLowTapPosition(); position <= rtc.getHighTapPosition(); position++) { RatioTapChangerStep step = rtc.getStep(position); double x = reactance * (1 + step.getX() / 100) / zb2; formatter.writeCell(variantIndex) .writeCell(num) .writeCell(position - rtc.getLowTapPosition() + 1) .writeCell(step.getRho()) .writeCell(x) .writeCell(0.0) .writeCell(faultNum) .writeCell(actionNum); } }
private void printSimulationResults(OnlineWorkflowResults wfResults, String workflowId, String basecaseId, String contingencyId, Integer stateId, ViolationType violationType, TableFormatter formatter) { if (wfResults != null && wfResults.getUnsafeContingencies() != null && !wfResults.getUnsafeContingencies().isEmpty() && wfResults.getUnsafeContingencies().contains(contingencyId) && wfResults.getIndexesData(contingencyId, stateId) != null && !wfResults.getIndexesData(contingencyId, stateId).isEmpty()) { for (String index : wfResults.getIndexesData(contingencyId, stateId).keySet()) { if (!wfResults.getIndexesData(contingencyId, stateId).get(index)) { try { formatter.writeCell(workflowId); formatter.writeCell(basecaseId); formatter.writeCell(contingencyId); formatter.writeCell(stateId); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeCell(violationType.name()); formatter.writeCell(index); formatter.writeCell(OnlineStep.TIME_DOMAIN_SIMULATION.name()); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeEmptyCell(); } catch (IOException e) { throw new RuntimeException(e); } } } } }
public SecurityAnalysisResultComparisonWriter write(LimitViolation violation1, LimitViolation violation2, boolean equivalent) { checkInput(violation1, violation2); try { formatter = contingency == null ? formatter.writeEmptyCell() : formatter.writeCell(contingency); formatter.writeEmptyCells(2); formatter.writeCell(getEquipment(violation1, violation2)); formatter = getEnd(violation1, violation2) == null ? formatter.writeEmptyCell() : formatter.writeCell(getEnd(violation1, violation2).name()); formatter.writeCell(getViolationType(violation1, violation2).name()); writeViolation(violation1); writeViolation(violation2); formatter.writeEmptyCells(2); formatter.writeCell(getComparison(equivalent)); } catch (IOException e) { LOGGER.error("Error writing security analysis results violations comparison: {}", e.getMessage()); } return this; }
private void writeRatioTapChanger(TableFormatter formatter, String rtcId, RatioTapChanger rtc, String tcsId) throws IOException { int rtcNum = mapper.getInt(AmplSubset.RATIO_TAP_CHANGER, rtcId); int tcsNum = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, tcsId); formatter.writeCell(variantIndex) .writeCell(rtcNum) .writeCell(rtc.getTapPosition() - rtc.getLowTapPosition() + 1) .writeCell(tcsNum) .writeCell(rtc.hasLoadTapChangingCapabilities() && rtc.isRegulating()); if (config.isExportRatioTapChangerVoltageTarget()) { formatter.writeCell(rtc.getTargetV()); } formatter.writeCell(faultNum) .writeCell(actionNum) .writeCell(rtcId); }
private static Consumer<? super LimitViolation> writeLinePreContingencyViolations(Network network, TableFormatter formatter, boolean writeName) { return violation -> { try { formatter.writeEmptyCell() .writeCell(writeName ? violation.getSubjectName() : violation.getSubjectId()) .writeCell(LimitViolationHelper.getVoltageLevelId(violation, network, writeName)) .writeCell(LimitViolationHelper.getCountry(violation, network).name()) .writeCell((int) LimitViolationHelper.getNominalVoltage(violation, network)) .writeCell(violation.getLimitType().name()) .writeCell(getViolationName(violation)) .writeCell(violation.getValue()) .writeCell(getViolationLimit(violation)) .writeCell(getAbsValueLimit(violation)) .writeCell(getViolationRate(violation)); } catch (IOException e) { throw new UncheckedIOException(e); } }; }
private void writePhaseTapChanger(TableFormatter formatter, String id, double zb2, double reactance, PhaseTapChanger ptc) throws IOException { int num = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, id); for (int position = ptc.getLowTapPosition(); position <= ptc.getHighTapPosition(); position++) { PhaseTapChangerStep step = ptc.getStep(position); double x = reactance * (1 + step.getX() / 100) / zb2; formatter.writeCell(variantIndex) .writeCell(num) .writeCell(position - ptc.getLowTapPosition() + 1) .writeCell(step.getRho()) .writeCell(x) .writeCell(Math.toRadians(step.getAlpha())) .writeCell(faultNum) .writeCell(actionNum); } }
private void printRulesResults(OnlineWorkflowRulesResults wfMclaRulesResults, String workflowId, String basecaseId, String contingencyId, Integer stateId, ViolationType violationType, TableFormatter formatter) { if (wfMclaRulesResults != null && wfMclaRulesResults.getContingenciesWithSecurityRulesResults() != null && !wfMclaRulesResults.getContingenciesWithSecurityRulesResults().isEmpty() && wfMclaRulesResults.getContingenciesWithSecurityRulesResults().contains(contingencyId) && wfMclaRulesResults.getStateResults(contingencyId, stateId) != null && !wfMclaRulesResults.getStateResults(contingencyId, stateId).isEmpty()) { for (String index : wfMclaRulesResults.getStateResults(contingencyId, stateId).keySet()) { if (!wfMclaRulesResults.getStateResults(contingencyId, stateId).get(index)) { try { formatter.writeCell(workflowId); formatter.writeCell(basecaseId); formatter.writeCell(contingencyId); formatter.writeCell(stateId); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeCell(violationType.name()); formatter.writeCell(index); formatter.writeCell(OnlineStep.MONTE_CARLO_LIKE_APPROACH.name()); formatter.writeEmptyCell(); formatter.writeEmptyCell(); formatter.writeEmptyCell(); } catch (IOException e) { throw new RuntimeException(e); } } } } }
private void writeTieLineMiddleBuses(AmplExportContext context, TableFormatter formatter) throws IOException { for (Line l : network.getLines()) { if (!l.isTieLine()) { continue; } TieLine tieLine = (TieLine) l; int xNodeCcNum = getTieLineMiddleBusComponentNum(context, tieLine); if (connectedComponentToExport(xNodeCcNum)) { String xNodeBusId = AmplUtil.getXnodeBusId(tieLine); int xNodeBusNum = mapper.getInt(AmplSubset.BUS, xNodeBusId); int xNodeVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, AmplUtil.getXnodeVoltageLevelId(tieLine)); formatter.writeCell(variantIndex) .writeCell(xNodeBusNum) .writeCell(xNodeVlNum) .writeCell(xNodeCcNum) .writeCell(Float.NaN) .writeCell(Double.NaN) .writeCell(0.0) .writeCell(0.0) .writeCell(faultNum) .writeCell(actionNum) .writeCell(xNodeBusId); } } }