add method that returns a string representation of the tags in Tags
This commit is contained in:
@@ -225,4 +225,22 @@ public class Tags {
|
|||||||
return new Tags(filename);
|
return new Tags(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String asString() {
|
||||||
|
|
||||||
|
final StringBuilder result = new StringBuilder();
|
||||||
|
final SortedSet<Tag> tags = toTags();
|
||||||
|
|
||||||
|
for (final Tag tag : tags) {
|
||||||
|
if (result.length() > 0) {
|
||||||
|
result.append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
result.append(tag.getKey());
|
||||||
|
result.append(":");
|
||||||
|
result.append(tag.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ScatterPlot.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ScatterPlot.class);
|
||||||
private static final Logger METRICS_LOGGER = LoggerFactory.getLogger("org.lucares.metrics.plotter.scatter");
|
private static final Logger METRICS_LOGGER = LoggerFactory.getLogger("org.lucares.metrics.plotter.scatter");
|
||||||
|
|
||||||
|
|
||||||
private final PerformanceDb db;
|
private final PerformanceDb db;
|
||||||
private final Path tmpBaseDir;
|
private final Path tmpBaseDir;
|
||||||
private final Path outputDir;
|
private final Path outputDir;
|
||||||
@@ -64,7 +63,6 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
|
|
||||||
LOGGER.trace("start plot: {}", plotSettings);
|
LOGGER.trace("start plot: {}", plotSettings);
|
||||||
|
|
||||||
|
|
||||||
final String tmpSubDir = ConcretePlotter.uniqueDirectoryName();
|
final String tmpSubDir = ConcretePlotter.uniqueDirectoryName();
|
||||||
final Path tmpDir = tmpBaseDir.resolve(tmpSubDir);
|
final Path tmpDir = tmpBaseDir.resolve(tmpSubDir);
|
||||||
try {
|
try {
|
||||||
@@ -88,23 +86,23 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
|
|
||||||
final int id = idCounter.incrementAndGet();
|
final int id = idCounter.incrementAndGet();
|
||||||
final String title = ConcretePlotter.title(groupResult.getGroupedBy(), csvSummary.getValues());
|
final String title = ConcretePlotter.title(groupResult.getGroupedBy(), csvSummary.getValues());
|
||||||
final DataSeries dataSerie = new FileBackedDataSeries(id, title, csvSummary, GnuplotLineType.Points);
|
final DataSeries dataSerie = new FileBackedDataSeries(id, title, csvSummary,
|
||||||
|
GnuplotLineType.Points);
|
||||||
if (dataSerie.getValues() > 0) {
|
if (dataSerie.getValues() > 0) {
|
||||||
dataSeries.add(dataSerie);
|
dataSeries.add(dataSerie);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (final Exception e) {
|
||||||
throw new IllegalStateException(e); // TODO handle
|
throw new IllegalStateException(e); // TODO handle
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
METRICS_LOGGER.debug("csv generation took: " + (System.nanoTime() - start) / 1_000_000.0
|
METRICS_LOGGER.debug("csv generation took: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||||
+ "ms");
|
|
||||||
|
|
||||||
if (dataSeries.isEmpty()) {
|
if (dataSeries.isEmpty()) {
|
||||||
throw new NoDataPointsException();
|
throw new NoDataPointsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Limit limitBy = plotSettings.getLimitBy();
|
final Limit limitBy = plotSettings.getLimitBy();
|
||||||
int limit = plotSettings.getLimit();
|
final int limit = plotSettings.getLimit();
|
||||||
DataSeries.sortAndLimit(dataSeries, limitBy, limit);
|
DataSeries.sortAndLimit(dataSeries, limitBy, limit);
|
||||||
DataSeries.setColors(dataSeries);
|
DataSeries.setColors(dataSeries);
|
||||||
|
|
||||||
@@ -158,12 +156,8 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
gnuplotSettings.getxAxisSettings().setTo(formattedMaxDate);
|
gnuplotSettings.getxAxisSettings().setTo(formattedMaxDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static CsvSummary toCsv(final GroupResult groupResult, final Path tmpDir, final OffsetDateTime dateFrom,
|
private static CsvSummary toCsv(final GroupResult groupResult, final Path tmpDir, final OffsetDateTime dateFrom,
|
||||||
final OffsetDateTime dateTo, PlotSettings plotSettings) throws IOException {
|
final OffsetDateTime dateTo, final PlotSettings plotSettings) throws IOException {
|
||||||
|
|
||||||
final File dataFile = File.createTempFile("data", ".dat", tmpDir.toFile());
|
final File dataFile = File.createTempFile("data", ".dat", tmpDir.toFile());
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
@@ -179,17 +173,18 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
final int separator = ',';
|
final int separator = ',';
|
||||||
final int newline = '\n';
|
final int newline = '\n';
|
||||||
final StringBuilder formattedDateBuilder = new StringBuilder();
|
final StringBuilder formattedDateBuilder = new StringBuilder();
|
||||||
try (final Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII));
|
try (final Writer output = new BufferedWriter(
|
||||||
|
new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII));
|
||||||
final Formatter formatter = new Formatter(formattedDateBuilder);) {
|
final Formatter formatter = new Formatter(formattedDateBuilder);) {
|
||||||
|
|
||||||
final Iterator<Entry> it = entries.iterator();
|
final Iterator<Entry> it = entries.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
final Entry entry = it.next();
|
final Entry entry = it.next();
|
||||||
|
|
||||||
long epochMilli = entry.getEpochMilli();
|
final long epochMilli = entry.getEpochMilli();
|
||||||
if (fromEpochMilli <= epochMilli && epochMilli <= toEpochMilli) {
|
if (fromEpochMilli <= epochMilli && epochMilli <= toEpochMilli) {
|
||||||
|
|
||||||
long value = entry.getValue();
|
final long value = entry.getValue();
|
||||||
final String stringValue = LongUtils.longToString(value);
|
final String stringValue = LongUtils.longToString(value);
|
||||||
final String formattedDate;
|
final String formattedDate;
|
||||||
|
|
||||||
@@ -216,7 +211,9 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
METRICS_LOGGER.debug("wrote {} values to csv in: {}ms (ignored {} values) use millis: {}, grouping={}, file={}", count, (System.nanoTime() - start) / 1_000_000.0, ignoredValues, Boolean.toString(useMillis), groupResult.getGroupedBy(),dataFile);
|
METRICS_LOGGER.debug("wrote {} values to csv in: {}ms (ignored {} values) use millis: {}, grouping={}, file={}",
|
||||||
|
count, (System.nanoTime() - start) / 1_000_000.0, ignoredValues, Boolean.toString(useMillis),
|
||||||
|
groupResult.getGroupedBy().asString(), dataFile);
|
||||||
return new CsvSummary(dataFile, count, maxValue, aggregator.getAggregatedData());
|
return new CsvSummary(dataFile, count, maxValue, aggregator.getAggregatedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user