fix parallel aggregate on non english locales

We generate CSV files with comma as separator.
When we write times with milli seconds, then
we use floating point numbers. Depending
on the locale those floating point numbers
may be written with comma instead of point.
If that happens, then the plots are messed up.
Fixed by enforcing the locale when formatting floats.
This commit is contained in:
2019-11-01 09:04:26 +01:00
parent d91481809e
commit b734894253
2 changed files with 4 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Locale;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -87,7 +88,7 @@ public class ParallelRequestsAggregator implements CustomAggregator {
} }
private void appendTimeAndValue(final StringBuilder builder, final long timeEpochMilli, final int value) { private void appendTimeAndValue(final StringBuilder builder, final long timeEpochMilli, final int value) {
builder.append(String.format("%.3f", timeEpochMilli / 1000.0)); builder.append(String.format(Locale.US, "%.3f", timeEpochMilli / 1000.0));
builder.append(SEPARATOR); builder.append(SEPARATOR);
builder.append(value); builder.append(value);
builder.append(NEWLINE); builder.append(NEWLINE);

View File

@@ -8,6 +8,7 @@ import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Formatter; import java.util.Formatter;
import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.lucares.collections.Sparse2DLongArray; import org.lucares.collections.Sparse2DLongArray;
@@ -75,7 +76,7 @@ public class ScatterAggregator implements CustomAggregator {
if (useMillis) { if (useMillis) {
formattedDateBuilder.delete(0, formattedDateBuilder.length()); formattedDateBuilder.delete(0, formattedDateBuilder.length());
formatter.format("%.3f", epochMilli / 1000.0); formatter.format(Locale.US, "%.3f", epochMilli / 1000.0);
formattedDate = formattedDateBuilder.toString(); formattedDate = formattedDateBuilder.toString();
} else { } else {
formattedDate = String.valueOf(epochMilli / 1000); formattedDate = String.valueOf(epochMilli / 1000);