This commit is contained in:
2020-09-28 10:01:20 +00:00
32 changed files with 1436 additions and 2043 deletions

View File

@@ -82,7 +82,7 @@ public class BarChartAggregator implements CustomAggregator, IndexedAggregator,
@Override
public String renderLabels(final GnuplotAxis xAxis) {
return String.format("set label at %s %f, %d '%s' center front offset 0,0.3", // front
return String.format(Locale.US, "set label at %s %f, %d '%s' center front offset 0,0.3", // front
xAxis == GnuplotAxis.X1 ? "first" : "second", //
getIndex() + 0.5, //
getCount(), //

View File

@@ -8,6 +8,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import org.lucares.recommind.logs.GnuplotAxis;
import org.lucares.recommind.logs.GnuplotSettings;
public class BarChartAggregatorForIntervals implements CustomAggregator, IndexedAggregator, BarChart {
@@ -24,8 +25,11 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
private int count;
public BarChartAggregatorForIntervals(final Interval interval) {
this.interval = interval;
private final PlotSettings settings;
public BarChartAggregatorForIntervals(final PlotSettings settings) {
this.settings = settings;
this.interval = settings.getInterval().get();
buckets = interval.getBuckets();
}
@@ -72,20 +76,35 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
final StringBuilder csv = new StringBuilder();
final boolean isMiddleSeries = getIndex() == numberOfDataSeries / 2;
int i = 0;
int offset = 0;
for (final String bucketId : bucketIds()) {
final long count = buckets.get(bucketId).get();
csv.append(String.format(Locale.US, "%f", offset + getIndex() * SPACE_BETWEEN_BARS + 0.5));
csv.append(",");
csv.append(renderLabels && isMiddleSeries ? bucketId : "");
csv.append(renderLabels && isMiddleSeries && showLabel(i, buckets.size()) ? bucketId : "");
csv.append(",");
csv.append(count);
csv.append("\n");
offset += numberOfDataSeries;
i++;
}
return csv.toString();
}
private boolean showLabel(final int index, final int numberOfBuckets) {
final int width = settings.getWidth();
final int widthInPx = width - GnuplotSettings.GNUPLOT_LEFT_RIGHT_MARGIN;
final long maxLabels = Math.max(1, widthInPx / (GnuplotSettings.TICKS_FONT_SIZE * 8));
if (maxLabels >= numberOfBuckets) {
return true;
} else {
return index % (int) Math.ceil(numberOfBuckets / (double) maxLabels) == 0;
}
}
private SortedSet<String> bucketIds() {
return new TreeSet<>(buckets.keySet());

View File

@@ -56,7 +56,7 @@ public class BarChartHandler extends AggregateHandler {
appendln(result, barAggregator.asCsv(settings.isRenderLabels()));
appendln(result, "EOD");
if (settings.isRenderLabels()) {
if (settings.isRenderLabels() && settings.isRenderBarChartTickLabels()) {
appendfln(result, barAggregator.renderLabels(getxAxis()));
}
@@ -82,7 +82,7 @@ public class BarChartHandler extends AggregateHandler {
CustomAggregator createCustomAggregator(final Path tmpDir, final PlotSettings plotSettings,
final long fromEpochMilli, final long toEpochMilli) {
if (plotSettings.getInterval().isPresent()) {
return new BarChartAggregatorForIntervals(plotSettings.getInterval().get());
return new BarChartAggregatorForIntervals(plotSettings);
} else {
return new BarChartAggregator();
}

View File

@@ -1,6 +1,5 @@
package org.lucares.pdb.plot.api;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -10,38 +9,6 @@ import org.lucares.pdb.api.DateTimeRange;
import org.lucares.utils.LongToDateBucket;
public class Interval {
public enum IntervalTimeUnit {
MINUTE, HOUR, DAY, WEEK, MONTH, YEAR;
public static boolean isValid(final String value) {
for (final IntervalTimeUnit e : values()) {
if (e.name().equals(value)) {
return true;
}
}
return false;
}
public ChronoUnit toChronoUnit() {
switch (this) {
case MINUTE:
return ChronoUnit.MINUTES;
case HOUR:
return ChronoUnit.HOURS;
case DAY:
return ChronoUnit.DAYS;
case WEEK:
return ChronoUnit.WEEKS;
case MONTH:
return ChronoUnit.MONTHS;
case YEAR:
return ChronoUnit.YEARS;
default:
throw new IllegalArgumentException("Unexpected value: " + this);
}
}
}
private final IntervalTimeUnit intervalTimeUnit;
private final int value;
@@ -61,10 +28,12 @@ public class Interval {
private String toDateFormatForBucketer(final IntervalTimeUnit intervalTimeUnit) {
switch (intervalTimeUnit) {
case SECOND:
return "yyyy-MM-dd'\\n'HH:mm:ss";
case MINUTE:
return "yyyy-MM-dd HH:mm";
return "yyyy-MM-dd'\\n'HH:mm";
case HOUR:
return "yyyy-MM-dd HH";
return "yyyy-MM-dd'\\n'HH:00";
case DAY:
return "yyyy-MM-dd";
case WEEK:

View File

@@ -0,0 +1,37 @@
package org.lucares.pdb.plot.api;
import org.lucares.utils.DateBucketUnit;
public enum IntervalTimeUnit {
SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR;
public static boolean isValid(final String value) {
for (final IntervalTimeUnit e : values()) {
if (e.name().equals(value)) {
return true;
}
}
return false;
}
public DateBucketUnit toChronoUnit() {
switch (this) {
case SECOND:
return DateBucketUnit.SECOND;
case MINUTE:
return DateBucketUnit.MINUTE;
case HOUR:
return DateBucketUnit.HOUR;
case DAY:
return DateBucketUnit.DAY;
case WEEK:
return DateBucketUnit.WEEK;
case MONTH:
return DateBucketUnit.MONTH;
case YEAR:
return DateBucketUnit.YEAR;
default:
throw new IllegalArgumentException("Unexpected value: " + this);
}
}
}

View File

@@ -45,6 +45,8 @@ public class PlotSettings {
private Interval interval;
private boolean renderBarChartTickLabels;
public String getQuery() {
return query;
}
@@ -197,4 +199,12 @@ public class PlotSettings {
this.interval = interval;
}
public boolean isRenderBarChartTickLabels() {
return renderBarChartTickLabels;
}
public void setRenderBarChartTickLabels(final boolean renderBarChartTickLabels) {
this.renderBarChartTickLabels = renderBarChartTickLabels;
}
}

View File

@@ -35,6 +35,7 @@ public class GnuplotSettings {
private AxisSettings xAxisSettings = new AxisSettings();
private boolean renderLabels = true;
private DateTimeRange dateTimeRange;
private boolean renderBarChartTickLabels;
public GnuplotSettings(final Path output) {
this.output = output;
@@ -151,6 +152,14 @@ public class GnuplotSettings {
}
}
public boolean isRenderBarChartTickLabels() {
return renderBarChartTickLabels;
}
public void setRenderBarChartTickLabels(final boolean renderBarChartTickLabels) {
this.renderBarChartTickLabels = renderBarChartTickLabels;
}
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
}

View File

@@ -113,6 +113,7 @@ public class Plotter {
gnuplotSettings.setAggregates(plotSettings.getAggregates());
gnuplotSettings.setKeyOutside(plotSettings.isKeyOutside());
gnuplotSettings.setRenderBarChartTickLabels(plotSettings.isRenderBarChartTickLabels());
gnuplot.plot(gnuplotSettings, dataSeries);
}