Search in sources :

Example 6 with CsvWriterSettings

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();
}
Also used : CsvWriter(com.univocity.parsers.csv.CsvWriter) DecimalFormat(java.text.DecimalFormat) CsvWriterSettings(com.univocity.parsers.csv.CsvWriterSettings) BenchmarkResult(org.openjdk.jmh.results.BenchmarkResult) IterationResult(org.openjdk.jmh.results.IterationResult) RunResult(org.openjdk.jmh.results.RunResult) BenchmarkParams(org.openjdk.jmh.infra.BenchmarkParams)

Example 7 with CsvWriterSettings

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();
}
Also used : StringWriter(java.io.StringWriter) CsvWriter(com.univocity.parsers.csv.CsvWriter) PolicyStats(com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats) CsvWriterSettings(com.univocity.parsers.csv.CsvWriterSettings)

Example 8 with CsvWriterSettings

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;
}
Also used : LEGACY_TEXT(com.powsybl.psse.model.io.FileFormat.LEGACY_TEXT) BeanWriterProcessor(com.univocity.parsers.common.processor.BeanWriterProcessor) CsvWriterSettings(com.univocity.parsers.csv.CsvWriterSettings)

Example 9 with CsvWriterSettings

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();
}
Also used : CsvWriter(com.univocity.parsers.csv.CsvWriter) CsvWriterSettings(com.univocity.parsers.csv.CsvWriterSettings)

Example 10 with CsvWriterSettings

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());
}
Also used : CsvWriterSettings(com.univocity.parsers.csv.CsvWriterSettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

CsvWriterSettings (com.univocity.parsers.csv.CsvWriterSettings)16 CsvWriter (com.univocity.parsers.csv.CsvWriter)7 CsvFormat (com.univocity.parsers.csv.CsvFormat)5 CsvParserSettings (com.univocity.parsers.csv.CsvParserSettings)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 Writer (java.io.Writer)2 PolicyStats (com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats)1 LEGACY_TEXT (com.powsybl.psse.model.io.FileFormat.LEGACY_TEXT)1 BeanWriterProcessor (com.univocity.parsers.common.processor.BeanWriterProcessor)1 CsvParser (com.univocity.parsers.csv.CsvParser)1 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 StandardCharsets (java.nio.charset.StandardCharsets)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 List (java.util.List)1