diff --git a/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java b/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java index dd12c7e..6bb7c43 100644 --- a/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java +++ b/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java @@ -1,5 +1,6 @@ package org.lucares.recommind.logs; +import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -129,10 +130,12 @@ public class Plotter { if (minDate.until(maxDate, ChronoUnit.WEEKS) > 1) { formatX = "%Y-%m-%d"; rotateX = 0; - } else { - + } else if (minDate.until(maxDate, ChronoUnit.SECONDS) > 10) { formatX = "%Y-%m-%d %H:%M:%S"; rotateX = gnuplotSettings.getRotateXAxisLabel(); + } else { + formatX = "%Y-%m-%d %H:%M:%.3S"; + rotateX = gnuplotSettings.getRotateXAxisLabel(); } formattedMinDate = minDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); formattedMaxDate = maxDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); @@ -214,9 +217,11 @@ public class Plotter { final long fromEpochMilli = dateFrom.toInstant().toEpochMilli(); final long toEpochMilli = dateTo.toInstant().toEpochMilli(); long maxValue = 0; + long ignoredValues = 0; final int separator = ','; final int newline = '\n'; - try (final Writer output = new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII);) { + final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + try (final Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII));) { final Iterator it = entries.iterator(); while (it.hasNext()) { @@ -225,7 +230,7 @@ public class Plotter { if (fromEpochMilli <= entry.getEpochMilli() && entry.getEpochMilli() <= toEpochMilli) { final OffsetDateTime date = entry.getDate(); final String value = String.valueOf(entry.getValue()); - final String formattedDate = date.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); + final String formattedDate = date.format(formatter); output.write(formattedDate); output.write(separator); output.write(value); @@ -233,11 +238,13 @@ public class Plotter { count++; maxValue = Math.max(maxValue, entry.getValue()); + }else { + ignoredValues++; } } } - METRICS_LOGGER.debug("wrote {} values to csv in: {}ms", count, (System.nanoTime() - start) / 1_000_000.0); + METRICS_LOGGER.debug("wrote {} values to csv in: {}ms (ignored {} values)", count, (System.nanoTime() - start) / 1_000_000.0, ignoredValues); return new CsvSummary(count, maxValue); } }