plot statistics written to the legend only count visible values
This commit is contained in:
@@ -11,22 +11,20 @@ import java.nio.file.Path;
|
|||||||
|
|
||||||
import org.lucares.collections.IntList;
|
import org.lucares.collections.IntList;
|
||||||
|
|
||||||
public class PercentileCustomAggregator implements CustomAggregator{
|
public class PercentileCustomAggregator implements CustomAggregator {
|
||||||
|
|
||||||
private final static int POINTS = 100;
|
private final static int POINTS = 500;
|
||||||
|
|
||||||
private final IntList values = new IntList(); // TODO should be a LongList
|
private final IntList values = new IntList(); // TODO should be a LongList
|
||||||
|
|
||||||
private Path tmpDir;
|
private final Path tmpDir;
|
||||||
|
|
||||||
|
public PercentileCustomAggregator(final Path tmpDir) {
|
||||||
|
|
||||||
public PercentileCustomAggregator(Path tmpDir) {
|
|
||||||
this.tmpDir = tmpDir;
|
this.tmpDir = tmpDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addValue(long epochMilli, long value) {
|
public void addValue(final long epochMilli, final long value) {
|
||||||
values.add((int) value);
|
values.add((int) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,16 +37,16 @@ public class PercentileCustomAggregator implements CustomAggregator{
|
|||||||
|
|
||||||
final IntList percentiles = new IntList(POINTS);
|
final IntList percentiles = new IntList(POINTS);
|
||||||
final File dataFile = File.createTempFile("data", ".dat", tmpDir.toFile());
|
final File dataFile = File.createTempFile("data", ".dat", tmpDir.toFile());
|
||||||
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 StringBuilder data = new StringBuilder();
|
final StringBuilder data = new StringBuilder();
|
||||||
if (values.size() > 0) {
|
if (values.size() > 0) {
|
||||||
// compute the percentiles
|
// compute the percentiles
|
||||||
for (int i = 0; i < POINTS; i++) {
|
for (int i = 0; i < POINTS; i++) {
|
||||||
data.append(i* (100/(double)POINTS));
|
data.append(i * (100 / (double) POINTS));
|
||||||
data.append(separator);
|
data.append(separator);
|
||||||
int percentile = values.get((int) Math.floor(values.size()
|
final int percentile = values.get((int) Math.floor(values.size() / ((double) POINTS) * i));
|
||||||
/ ((double)POINTS) * i));
|
|
||||||
data.append(percentile);
|
data.append(percentile);
|
||||||
data.append(newline);
|
data.append(newline);
|
||||||
|
|
||||||
@@ -64,8 +62,7 @@ public class PercentileCustomAggregator implements CustomAggregator{
|
|||||||
|
|
||||||
}
|
}
|
||||||
// TODO remove:
|
// TODO remove:
|
||||||
double average = percentiles.stream().summaryStatistics().getAverage();
|
final double average = percentiles.stream().summaryStatistics().getAverage();
|
||||||
|
|
||||||
|
|
||||||
final String title = String.format("percentiles");
|
final String title = String.format("percentiles");
|
||||||
return new AggregatedData(title, dataFile, average);
|
return new AggregatedData(title, dataFile, average);
|
||||||
|
|||||||
@@ -205,9 +205,15 @@ public class ScatterPlot {
|
|||||||
final long fromEpochMilli = dateFrom.toInstant().toEpochMilli();
|
final long fromEpochMilli = dateFrom.toInstant().toEpochMilli();
|
||||||
final long toEpochMilli = dateTo.toInstant().toEpochMilli();
|
final long toEpochMilli = dateTo.toInstant().toEpochMilli();
|
||||||
final boolean useMillis = (toEpochMilli - fromEpochMilli) < TimeUnit.MINUTES.toMillis(5);
|
final boolean useMillis = (toEpochMilli - fromEpochMilli) < TimeUnit.MINUTES.toMillis(5);
|
||||||
|
|
||||||
|
final long minValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? 0
|
||||||
|
: plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMin());
|
||||||
|
final long maxValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? Long.MAX_VALUE
|
||||||
|
: plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMax());
|
||||||
|
|
||||||
final CustomAggregator aggregator = plotSettings.getAggregate().createCustomAggregator(tmpDir);
|
final CustomAggregator aggregator = plotSettings.getAggregate().createCustomAggregator(tmpDir);
|
||||||
|
|
||||||
long maxValue = 0;
|
long statsMaxValue = 0;
|
||||||
long ignoredValues = 0;
|
long ignoredValues = 0;
|
||||||
final int separator = ',';
|
final int separator = ',';
|
||||||
final int newline = '\n';
|
final int newline = '\n';
|
||||||
@@ -221,9 +227,18 @@ public class ScatterPlot {
|
|||||||
final Entry entry = it.next();
|
final Entry entry = it.next();
|
||||||
|
|
||||||
final long epochMilli = entry.getEpochMilli();
|
final long epochMilli = entry.getEpochMilli();
|
||||||
if (fromEpochMilli <= epochMilli && epochMilli <= toEpochMilli) {
|
if (fromEpochMilli > epochMilli || epochMilli > toEpochMilli) {
|
||||||
|
ignoredValues++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
final long value = entry.getValue();
|
final long value = entry.getValue();
|
||||||
|
aggregator.addValue(epochMilli, value);
|
||||||
|
if (value < minValue || value > maxValue) {
|
||||||
|
ignoredValues++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
final String stringValue = LongUtils.longToString(value);
|
final String stringValue = LongUtils.longToString(value);
|
||||||
final String formattedDate;
|
final String formattedDate;
|
||||||
|
|
||||||
@@ -240,20 +255,16 @@ public class ScatterPlot {
|
|||||||
output.write(stringValue);
|
output.write(stringValue);
|
||||||
output.write(newline);
|
output.write(newline);
|
||||||
|
|
||||||
aggregator.addValue(epochMilli, value);
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
maxValue = Math.max(maxValue, value);
|
statsMaxValue = Math.max(statsMaxValue, value);
|
||||||
} else {
|
|
||||||
ignoredValues++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
METRICS_LOGGER.debug("wrote {} values to csv in: {}ms (ignored {} values) use millis: {}, grouping={}, file={}",
|
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),
|
count, (System.nanoTime() - start) / 1_000_000.0, ignoredValues, Boolean.toString(useMillis),
|
||||||
groupResult.getGroupedBy().asString(), dataFile);
|
groupResult.getGroupedBy().asString(), dataFile);
|
||||||
return new CsvSummary(dataFile, count, maxValue, aggregator.getAggregatedData());
|
return new CsvSummary(dataFile, count, statsMaxValue, aggregator.getAggregatedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
static String uniqueDirectoryName() {
|
static String uniqueDirectoryName() {
|
||||||
|
|||||||
Reference in New Issue
Block a user