use of com.univocity.parsers.csv.CsvWriterSettings in project deephaven-core by deephaven.
the class CsvResultWriter method recordResults.
public static void recordResults(final Collection<RunResult> results, final File file) {
if (results.isEmpty()) {
return;
}
final CsvWriter writer = new CsvWriter(file, new CsvWriterSettings());
final Set<String> headers = new LinkedHashSet<>();
headers.add("Benchmark");
headers.add("Run");
headers.add("Iteration");
headers.add("Score");
for (final RunResult runResult : results) {
final BenchmarkParams runParams = runResult.getParams();
headers.addAll(runParams.getParamsKeys());
}
writer.writeHeaders(headers);
final DecimalFormat decimalFormat = new DecimalFormat("#0.000");
int runNo = 0;
for (final RunResult runResult : results) {
final BenchmarkParams runParams = runResult.getParams();
for (final BenchmarkResult benchResult : runResult.getBenchmarkResults()) {
runNo++;
int itNo = 0;
for (final IterationResult itResult : benchResult.getIterationResults()) {
itNo++;
final Map<String, String> values = new HashMap<>();
values.put("Benchmark", runParams.getBenchmark());
for (String key : runParams.getParamsKeys()) {
values.put(key, runParams.getParam(key));
}
values.put("Score", decimalFormat.format(itResult.getPrimaryResult().getScore()));
values.put("Run", Integer.toString(runNo));
values.put("Iteration", Integer.toString(itNo));
writer.writeRow(headers.stream().map(values::get).collect(Collectors.toList()));
}
}
}
writer.close();
}
use of com.univocity.parsers.csv.CsvWriterSettings in project caffeine by ben-manes.
the class CsvReporter method assemble.
@Override
protected String assemble(List<PolicyStats> results) {
StringWriter output = new StringWriter();
CsvWriter writer = new CsvWriter(output, new CsvWriterSettings());
writer.writeHeaders(headers());
for (PolicyStats policyStats : results) {
Object[] data = new Object[] { policyStats.name(), String.format("%.2f", 100 * policyStats.hitRate()), policyStats.hitCount(), policyStats.missCount(), policyStats.requestCount(), policyStats.evictionCount(), String.format("%.2f", 100 * policyStats.admissionRate()), (policyStats.operationCount() == 0) ? null : policyStats.operationCount(), policyStats.stopwatch().elapsed(TimeUnit.MILLISECONDS) };
writer.writeRow(data);
}
writer.close();
return output.toString();
}
use of com.univocity.parsers.csv.CsvWriterSettings in project powsybl-core by powsybl.
the class AbstractRecordGroup method settingsForCsvWriter.
CsvWriterSettings settingsForCsvWriter(String[] headers, String[] quotedFields, Context context) {
BeanWriterProcessor<T> processor = new BeanWriterProcessor<>(psseTypeClass());
CsvWriterSettings settings = new CsvWriterSettings();
settings.quoteFields(quotedFields);
settings.setHeaders(headers);
settings.getFormat().setQuote(context.getFileFormat().getQuote());
settings.getFormat().setDelimiter(context.getDelimiter());
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setRowWriterProcessor(processor);
return settings;
}
use of com.univocity.parsers.csv.CsvWriterSettings in project powsybl-core by powsybl.
the class RecordGroupIOLegacyText method write.
protected void write(List<T> objects, String[] headers, String[] quotedFields, Context context, OutputStream outputStream) {
CsvWriterSettings settings = recordGroup.settingsForCsvWriter(headers, quotedFields, context);
CsvWriter writer = new CsvWriter(outputStream, settings);
writer.processRecords(objects);
writer.flush();
}
use of com.univocity.parsers.csv.CsvWriterSettings in project tablesaw by jtablesaw.
the class CsvWriteOptionsTest method testSettingsPropagation.
@Test
public void testSettingsPropagation() {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriteOptions options = CsvWriteOptions.builder(stream).escapeChar('~').header(true).lineEnd("\r\n").quoteChar('"').separator('.').quoteAllFields(true).ignoreLeadingWhitespaces(true).ignoreTrailingWhitespaces(true).build();
assertEquals('~', options.escapeChar());
assertTrue(options.header());
assertEquals('"', options.quoteChar());
assertEquals('.', options.separator());
assertTrue(options.ignoreLeadingWhitespaces());
assertTrue(options.ignoreTrailingWhitespaces());
assertTrue(options.quoteAllFields());
CsvWriterSettings settings = CsvWriter.createSettings(options);
assertTrue(settings.getQuoteAllFields());
assertEquals('~', settings.getFormat().getQuoteEscape());
assertEquals("\r\n", settings.getFormat().getLineSeparatorString());
assertEquals('"', settings.getFormat().getQuote());
assertEquals('.', settings.getFormat().getDelimiter());
assertEquals(options.ignoreLeadingWhitespaces(), settings.getIgnoreLeadingWhitespaces());
assertEquals(options.ignoreTrailingWhitespaces(), settings.getIgnoreTrailingWhitespaces());
}
Aggregations