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 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 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 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 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 static Consumer<? super LimitViolation> writeLineLimitsViolations(Network network, TableFormatter formatter, boolean writeName) { return violation -> { try { formatter.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 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 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(); }
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; }
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 void printLoadFlowResult(LoadFlowResult result, Writer writer, TableFormatterFactory formatterFactory, TableFormatterConfig formatterConfig) { try (TableFormatter formatter = formatterFactory.create(writer, "loadflow results", formatterConfig, new Column("Result"), new Column("Metrics"))) { formatter.writeCell(result.isOk()); formatter.writeCell(result.getMetrics().toString()); } 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)); } }
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; }
@Override public void run(CommandLine line, ToolRunningContext context) throws Exception { Collection<PluginInfo> pluginInfos = Plugins.getPluginInfos(); Writer writer = new OutputStreamWriter(context.getOutputStream()); AsciiTableFormatterFactory asciiTableFormatterFactory = new AsciiTableFormatterFactory(); try (TableFormatter formatter = asciiTableFormatterFactory.create(writer, "Plugins", new TableFormatterConfig(), new Column("Plugin type name"), new Column("Available plugin IDs"))) { pluginInfos.forEach(p -> { try { formatter.writeCell(p.getPluginName()); formatter.writeCell(String.join(", ", Plugins.getPluginImplementationsIds(p))); } catch (IOException e) { throw new UncheckedIOException(e); } }); } } }
private void writeTrustIntervals(Uncertainties uncertainties, DataSource dataSource) throws IOException { try (Writer writer = new OutputStreamWriter(dataSource.newOutputStream(TRUST_INTERVAL_FILE_SUFFIX, TXT_EXT, false), StandardCharsets.UTF_8); AmplDatTableFormatter formatter = new AmplDatTableFormatter( writer, "Trust intervals", INVALID_FLOAT_VALUE, true, LOCALE, new Column("var. num"), new Column("min"), new Column("max"))) { for (int varNum = 0; varNum < uncertainties.min.length; varNum++) { formatter.writeCell(varNum + 1) .writeCell(uncertainties.min[varNum]) .writeCell(uncertainties.max[varNum]); } } }
private void writeMeans(Uncertainties uncertainties, DataSource dataSource, StringToIntMapper<AmplSubset> mapper) throws IOException { try (Writer writer = new OutputStreamWriter(dataSource.newOutputStream(MEANS_FILE_SUFFIX, TXT_EXT, false), StandardCharsets.UTF_8); AmplDatTableFormatter formatter = new AmplDatTableFormatter( writer, "Means", INVALID_FLOAT_VALUE, true, LOCALE, new Column("inj. type"), new Column("inj. num"), new Column("mean"))) { for (int i = 0; i < uncertainties.means.length; i++) { StochasticInjection inj = uncertainties.injections.get(i); formatter.writeCell(inj.getType().toChar()) .writeCell(getNum(inj, mapper)) .writeCell(uncertainties.means[i]); } } }
@Test public void testAsciiTableFormatter2() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8); try (AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config, new Column("column1").setColspan(4).setHorizontalAlignment(HorizontalAlignment.CENTER).setTitleHorizontalAlignment(HorizontalAlignment.CENTER), new Column("column2").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER).setTitleHorizontalAlignment(HorizontalAlignment.CENTER))) { formatter.writeCell("Line:1 Cell:1", 1) .writeCell("Line:1 Cell:2", 1) .writeCell("Line:1 Cell:3", 1) .writeCell("Line:1 Cell:4", 1) .writeCell("Line:1 Cell:5", 1) .writeCell("Line:1 Cell:6", 1); } assertEquals("+---------------------------------------------------------------+-------------------------------+\n" + "| column1 | column2 |\n" + "+---------------------------------------------------------------+-------------------------------+\n" + "| Line:1 Cell:1 | Line:1 Cell:2 | Line:1 Cell:3 | Line:1 Cell:4 | Line:1 Cell:5 | Line:1 Cell:6 |\n" + "+---------------+---------------+---------------+---------------+---------------+---------------+" + System.lineSeparator(), new String(bos.toByteArray(), StandardCharsets.UTF_8)); writer.close(); }
@Test public void testUnauthorizedColspan() throws IOException { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("You have exceded the authorized colspan"); 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).setHorizontalAlignment(HorizontalAlignment.CENTER), new Column("column2").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER))) { formatter.writeCell("Line:1 Cell:1", 1) .writeCell("Line:1 Cell:2", 1) .writeCell("Line:1 Cell:3", 1) .writeCell("Line:1 Cell:4", 2) .writeCell("Line:1 Cell:5", 1); } }
@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)); } }