public static TableFormatter createFormatter(TableFormatterConfig config, String outputFormatName, Path outputFilePath, String tableTitle, Column... columns) throws IOException { Writer writer; TableFormatterFactory formatterFactory; if (isTableFactoryAvailable(outputFormatName)) { formatterFactory = tableFactoryByFormatName(outputFormatName); } else { throw new RuntimeException("output format not supported: " + outputFormatName); } if (outputFilePath != null) { writer = Files.newBufferedWriter(outputFilePath, StandardCharsets.UTF_8); } else { writer = new OutputStreamWriter(System.out) { @Override public void close() throws IOException { flush(); } }; } return formatterFactory.create(writer, tableTitle, config, columns); } }
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); } }
try (TableFormatter formatter = formatterFactory.create(writer, "Post-contingency limit violations", writeConfig.getFormatterConfig(),
NumberFormat percentageFormat = getFormatter(printConfig.getFormatterConfig().getLocale(), 2, 2); try (TableFormatter formatter = formatterFactory.create(writer, "", printConfig.getFormatterConfig(),
: result.getPreContingencyResult().getLimitViolations(); try (TableFormatter formatter = formatterFactory.create(writer, "Pre-contingency violations", printConfig.getFormatterConfig(),
private void printSensitivityComputationResult(SensitivityComputationResults result, Writer writer, TableFormatterFactory formatterFactory, TableFormatterConfig formatterConfig) { try (TableFormatter formatter = formatterFactory.create(writer, "sensitivity computation results", formatterConfig, new Column("VariableId"), new Column("VariableName"), new Column("FunctionId"), new Column("FunctionName"), new Column("VariableRefValue"), new Column("FunctionRefValue"), new Column("SensitivityValue"))) { result.getSensitivityValues().forEach(sensitivityValue -> { try { formatter.writeCell(sensitivityValue.getFactor().getVariable().getId()); formatter.writeCell(sensitivityValue.getFactor().getVariable().getName()); formatter.writeCell(sensitivityValue.getFactor().getFunction().getId()); formatter.writeCell(sensitivityValue.getFactor().getFunction().getName()); formatter.writeCell(sensitivityValue.getVariableReference()); formatter.writeCell(sensitivityValue.getFunctionReference()); formatter.writeCell(sensitivityValue.getValue()); } catch (IOException e) { throw new UncheckedIOException(e); } }); } catch (IOException e) { throw new UncheckedIOException(e); } } }