@Override public void close() throws IOException { formatter.close(); }
public WCAReportImpl(Network basecase) { this(basecase, TableFormatterConfig.load()); }
private Column[] getColumns() { return new Column[] { new Column("Contingency"), new Column("Status" + RESULT + "1"), new Column("Status" + RESULT + "2"), new Column("Equipment"), new Column("End"), new Column("ViolationType"), new Column("ViolationName" + RESULT + "1"), new Column("Value" + RESULT + "1"), new Column("Limit" + RESULT + "1"), new Column("ViolationName" + RESULT + "2"), new Column("Value" + RESULT + "2"), new Column("Limit" + RESULT + "2"), new Column("Actions" + RESULT + "1"), new Column("Actions" + RESULT + "2"), new Column("Comparison") }; }
@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); } }); } } }
@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); } }
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 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 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(Writer writer) { Objects.requireNonNull(writer); formatter = new CsvTableFormatterFactory().create(writer, "Security Analysis Results Comparison", TableFormatterConfig.load(), getColumns()); }
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)); } }
@Test public void testPositiveColspan() { Column column = new Column("column"); assertEquals(1, column.getColspan()); column.setColspan(2); assertEquals(2, column.getColspan()); }
private void printResult(LoadFlowResult result, ToolRunningContext context) { Writer writer = new OutputStreamWriter(context.getOutputStream()); AsciiTableFormatterFactory asciiTableFormatterFactory = new AsciiTableFormatterFactory(); printLoadFlowResult(result, writer, asciiTableFormatterFactory, TableFormatterConfig.load()); }
@Test public void testNegativeColspan() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("colspan must be greater than 0"); new Column("column").setColspan(-5); }
private void exportResult(LoadFlowResult result, ToolRunningContext context, Path outputFile, Format format) { context.getOutputStream().println("Writing results to '" + outputFile + "'"); switch (format) { case CSV: CsvTableFormatterFactory csvTableFormatterFactory = new CsvTableFormatterFactory(); printLoadFlowResult(result, outputFile, csvTableFormatterFactory, TableFormatterConfig.load()); break; case JSON: LoadFlowResultSerializer.write(result, outputFile); break; } } }
private void testConfig(TableFormatterConfig config, Locale locale, char separator, String invalidString, boolean printHeader, boolean printTitle) { assertEquals(locale, config.getLocale()); assertEquals(separator, config.getCsvSeparator()); assertEquals(invalidString, config.getInvalidString()); assertEquals(printHeader, config.getPrintHeader()); assertEquals(printTitle, config.getPrintTitle()); }
@Override protected void writeHeader() throws IOException { writer.append("#").append(title).append(System.lineSeparator()) .append("#"); for (int i = 0; i < columns.length; i++) { writer.append("\"").append(columns[i].getName()).append("\""); if (i < columns.length - 1) { writer.append(config.getCsvSeparator()); } } writer.append(System.lineSeparator()); }
public static void printPreContingencyViolations(SecurityAnalysisResult result, Network network, Writer writer, TableFormatterFactory formatterFactory, LimitViolationFilter limitViolationFilter) { printPreContingencyViolations(result, network, writer, formatterFactory, TableFormatterConfig.load(), limitViolationFilter); }
public static void printPostContingencyViolations(SecurityAnalysisResult result, Network network, Writer writer, TableFormatterFactory formatterFactory, LimitViolationFilter limitViolationFilter, boolean filterPreContingencyViolations) { printPostContingencyViolations(result, network, writer, formatterFactory, TableFormatterConfig.load(), limitViolationFilter, filterPreContingencyViolations); }
public static String printLimitsViolations(List<LimitViolation> violations, Network network, LimitViolationFilter filter) { return printLimitsViolations(violations, network, filter, TableFormatterConfig.load()); }