Skip to content

Commit

Permalink
added property CSV_DATA_WRITER_PRECISION to set float precision
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Nov 19, 2023
1 parent 703c5c0 commit eb23d68
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

public class CsvDataWriter implements IDataListener {
final List<String> filter;
static final String CSV_DATA_WRITER_PRECISION = "CSV_DATA_WRITER_PRECISION";

static final String floatFormatter = System.getProperty(CSV_DATA_WRITER_PRECISION) != null ? ("%." + System.getProperty(
CSV_DATA_WRITER_PRECISION) + "f") : null;
private final DataFileRotater dataFileRotater;
HashMap<UUID, CsvDataWriterInstance> instances = new HashMap<>();

Expand Down Expand Up @@ -51,14 +55,18 @@ public void writeHeader(UUID uuid, List<String> headers) {
@Override
public void writeDataPoint(UUID uuid, double time, List<Value> dataPoint) {
List<String> data = new Vector<>();
data.add(Double.toString(time));
data.add(floatFormatter == null ? Double.toString(time) : String.format(Locale.US, floatFormatter, time));

for (Integer i : instances.get(uuid).indicesOfInterest) {
Value d = dataPoint.get(i).deref();

Object value = null;
if (d.isNumericDecimal()) {
value = ((NumericValue) d).doubleValue();
if (floatFormatter == null)
value = ((NumericValue) d).doubleValue();
else {
value = String.format(Locale.US, floatFormatter, ((NumericValue) d).doubleValue());
}
} else if (d.isNumeric()) {
value = ((NumericValue) d).intValue();
} else if (d instanceof BooleanValue) {
Expand Down

0 comments on commit eb23d68

Please sign in to comment.