create y-axis settings in aggregate handlers
This commit is contained in:
@@ -4,27 +4,20 @@ import java.nio.file.Path;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.lucares.recommind.logs.AxisSettings;
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
import org.lucares.recommind.logs.GnuplotSettings;
|
import org.lucares.recommind.logs.GnuplotSettings;
|
||||||
import org.lucares.recommind.logs.LineStyle;
|
import org.lucares.recommind.logs.LineStyle;
|
||||||
import org.lucares.recommind.logs.XAxisSettings;
|
|
||||||
|
|
||||||
public interface AggregateHandler {
|
public interface AggregateHandler extends Appender {
|
||||||
|
|
||||||
Aggregate getAggregateType();
|
Aggregate getAggregateType();
|
||||||
|
|
||||||
@Deprecated
|
AxisSettings createXAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries);
|
||||||
void addGnuplotDefinitions(StringBuilder result, Collection<DataSeries> dataSeries);
|
|
||||||
|
|
||||||
XAxisSettings createXAxisSettings(GnuplotSettings settings);
|
AxisSettings createYAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries);
|
||||||
|
|
||||||
default void appendln(final StringBuilder builder, final String string) {
|
|
||||||
builder.append(string + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
default void appendfln(final StringBuilder builder, final String format, final Object... args) {
|
|
||||||
builder.append(String.format(format + "\n", args));
|
|
||||||
}
|
|
||||||
|
|
||||||
default String gnuplotTitle(Optional<String> title) {
|
default String gnuplotTitle(Optional<String> title) {
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
import org.lucares.recommind.logs.GnuplotSettings;
|
import org.lucares.recommind.logs.GnuplotSettings;
|
||||||
import org.lucares.recommind.logs.XAxisSettings;
|
import org.lucares.recommind.logs.AxisSettings;
|
||||||
import org.lucares.utils.CollectionUtils;
|
import org.lucares.utils.CollectionUtils;
|
||||||
import org.lucares.utils.CollectionUtils.Compare;
|
import org.lucares.utils.CollectionUtils.Compare;
|
||||||
|
|
||||||
@@ -24,20 +24,15 @@ public class AggregateHandlerCollection {
|
|||||||
Collections.sort(aggregateHandlers, COMPARATOR);
|
Collections.sort(aggregateHandlers, COMPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGnuplotDefinitions(StringBuilder result, Collection<DataSeries> dataSeries) {
|
|
||||||
|
|
||||||
|
public List<AxisSettings> getXAxisDefinitions(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
|
List<AxisSettings> result = new ArrayList<>();
|
||||||
for (AggregateHandler handler : aggregateHandlers) {
|
for (AggregateHandler handler : aggregateHandlers) {
|
||||||
handler.addGnuplotDefinitions(result, dataSeries);
|
AxisSettings xaxis = handler.createXAxisSettings(settings, dataSeries);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
final Compare<AxisSettings> compare = Compare.compare(AxisSettings::getType, xaxis.getType())
|
||||||
public List<XAxisSettings> getXAxisDefinitions(GnuplotSettings settings) {
|
.thenCompare(AxisSettings::getLabel, xaxis.getLabel());
|
||||||
List<XAxisSettings> result = new ArrayList<>();
|
|
||||||
for (AggregateHandler handler : aggregateHandlers) {
|
|
||||||
XAxisSettings xaxis = handler.createXAxisSettings(settings);
|
|
||||||
|
|
||||||
final Compare<XAxisSettings> compare = Compare.compare(XAxisSettings::getType, xaxis.getType())
|
|
||||||
.thenCompare(XAxisSettings::getLabel, xaxis.getLabel());
|
|
||||||
|
|
||||||
if (!CollectionUtils.contains(result, compare)) {
|
if (!CollectionUtils.contains(result, compare)) {
|
||||||
result.add(xaxis);
|
result.add(xaxis);
|
||||||
@@ -46,6 +41,21 @@ public class AggregateHandlerCollection {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AxisSettings> getYAxisDefinitions(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
|
List<AxisSettings> result = new ArrayList<>();
|
||||||
|
for (AggregateHandler handler : aggregateHandlers) {
|
||||||
|
AxisSettings axis = handler.createYAxisSettings(settings, dataSeries);
|
||||||
|
|
||||||
|
final Compare<AxisSettings> compare = Compare.compare(AxisSettings::getType, axis.getType())
|
||||||
|
.thenCompare(AxisSettings::getLabel, axis.getLabel());
|
||||||
|
|
||||||
|
if (!CollectionUtils.contains(result, compare)) {
|
||||||
|
result.add(axis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public AggregatorCollection createCustomAggregator(Path tmpDir, PlotSettings plotSettings, long fromEpochMilli,
|
public AggregatorCollection createCustomAggregator(Path tmpDir, PlotSettings plotSettings, long fromEpochMilli,
|
||||||
long toEpochMilli) {
|
long toEpochMilli) {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.lucares.pdb.plot.api;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public interface Appender {
|
||||||
|
default void appendln(final StringBuilder builder, final String string) {
|
||||||
|
builder.append(string + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
default void appendfln(final StringBuilder builder, final String format, final Object... args) {
|
||||||
|
builder.append(String.format(Locale.US,format + "\n", args));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void appendf(final StringBuilder builder, final String format, final Object... args) {
|
||||||
|
builder.append(String.format(Locale.US,format, args));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,13 @@ import java.nio.file.Path;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.lucares.recommind.logs.AxisTime;
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
import org.lucares.recommind.logs.GnuplotAxis;
|
import org.lucares.recommind.logs.GnuplotAxis;
|
||||||
import org.lucares.recommind.logs.GnuplotSettings;
|
import org.lucares.recommind.logs.GnuplotSettings;
|
||||||
import org.lucares.recommind.logs.LineStyle;
|
import org.lucares.recommind.logs.LineStyle;
|
||||||
import org.lucares.recommind.logs.XAxisSettings;
|
import org.lucares.recommind.logs.AxisSettings;
|
||||||
import org.lucares.recommind.logs.XAxisSettings.Type;
|
import org.lucares.recommind.logs.AxisSettings.Type;
|
||||||
|
|
||||||
public class CumulativeDistributionHandler implements AggregateHandler {
|
public class CumulativeDistributionHandler implements AggregateHandler {
|
||||||
|
|
||||||
@@ -23,17 +24,13 @@ public class CumulativeDistributionHandler implements AggregateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGnuplotDefinitions(final StringBuilder result,
|
public AxisSettings createYAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
final Collection<DataSeries> dataSeries) {
|
return AxisTime.createYAxis(settings, dataSeries);
|
||||||
|
|
||||||
appendln(result, "set x2label \"Cumulative Distribution\"");
|
|
||||||
appendln(result, "set format x2 \"%.0f%%\"");
|
|
||||||
appendln(result, "set x2tics 5");
|
|
||||||
appendln(result, "set x2range [\"0\":\"100\"]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XAxisSettings createXAxisSettings(GnuplotSettings settings) {
|
public AxisSettings createXAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
XAxisSettings result = new XAxisSettings();
|
AxisSettings result = new AxisSettings();
|
||||||
result.setLabel("Cumulative Distribution");
|
result.setLabel("Cumulative Distribution");
|
||||||
result.setType(Type.Number);
|
result.setType(Type.Number);
|
||||||
result.setAxis(GnuplotAxis.X2); // TODO determine automatically
|
result.setAxis(GnuplotAxis.X2); // TODO determine automatically
|
||||||
@@ -48,8 +45,7 @@ public class CumulativeDistributionHandler implements AggregateHandler {
|
|||||||
int widthByFontSize = settings.getWidth() / GnuplotSettings.TICKS_FONT_SIZE;
|
int widthByFontSize = settings.getWidth() / GnuplotSettings.TICKS_FONT_SIZE;
|
||||||
if (widthByFontSize < 50) {
|
if (widthByFontSize < 50) {
|
||||||
return 20;
|
return 20;
|
||||||
}
|
} else if (widthByFontSize < 75) {
|
||||||
else if (widthByFontSize < 75) {
|
|
||||||
return 10;
|
return 10;
|
||||||
} else {
|
} else {
|
||||||
return 5;
|
return 5;
|
||||||
@@ -57,7 +53,8 @@ public class CumulativeDistributionHandler implements AggregateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlot(StringBuilder result, AggregatedData aggregatedData, LineStyle lineStyle, Optional<String> title) {
|
public void addPlot(StringBuilder result, AggregatedData aggregatedData, LineStyle lineStyle,
|
||||||
|
Optional<String> title) {
|
||||||
appendfln(result, "'%s' using 1:2 %s with lines axes x2y1 lw 2 %s, \\", //
|
appendfln(result, "'%s' using 1:2 %s with lines axes x2y1 lw 2 %s, \\", //
|
||||||
aggregatedData.getDataFile().getAbsolutePath(), //
|
aggregatedData.getDataFile().getAbsolutePath(), //
|
||||||
gnuplotTitle(title), //
|
gnuplotTitle(title), //
|
||||||
|
|||||||
@@ -5,24 +5,27 @@ import java.util.Collection;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.GnuplotAxis;
|
||||||
import org.lucares.recommind.logs.GnuplotSettings;
|
import org.lucares.recommind.logs.GnuplotSettings;
|
||||||
import org.lucares.recommind.logs.LineStyle;
|
import org.lucares.recommind.logs.LineStyle;
|
||||||
import org.lucares.recommind.logs.XAxisSettings;
|
import org.lucares.recommind.logs.AxisSettings;
|
||||||
import org.lucares.recommind.logs.XAxisTime;
|
import org.lucares.recommind.logs.AxisTime;
|
||||||
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
|
|
||||||
public class ParallelRequestsAggregate implements AggregateHandler {
|
public class ParallelRequestsAggregate implements AggregateHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGnuplotDefinitions(final StringBuilder result,
|
public AxisSettings createYAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
final Collection<DataSeries> dataSeries) {
|
final AxisSettings result = new AxisSettings();
|
||||||
appendln(result, "set y2label \"Parallel Requests\"");
|
result.setLabel("Parallel Requests");
|
||||||
appendln(result, "set y2tics");
|
result.setAxis(GnuplotAxis.Y2);
|
||||||
|
result.setTicsEnabled(true);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XAxisSettings createXAxisSettings(GnuplotSettings settings) {
|
public AxisSettings createXAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
return XAxisTime.create(settings);
|
return AxisTime.createXAxis(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,31 +4,28 @@ import java.nio.file.Path;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.lucares.recommind.logs.AxisSettings;
|
||||||
|
import org.lucares.recommind.logs.AxisTime;
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
import org.lucares.recommind.logs.GnuplotLineType;
|
import org.lucares.recommind.logs.GnuplotLineType;
|
||||||
import org.lucares.recommind.logs.GnuplotSettings;
|
import org.lucares.recommind.logs.GnuplotSettings;
|
||||||
import org.lucares.recommind.logs.LineStyle;
|
import org.lucares.recommind.logs.LineStyle;
|
||||||
import org.lucares.recommind.logs.XAxisSettings;
|
|
||||||
import org.lucares.recommind.logs.XAxisTimeTics;
|
|
||||||
import org.lucares.recommind.logs.XAxisSettings.Type;
|
|
||||||
import org.lucares.recommind.logs.XAxisTime;
|
|
||||||
|
|
||||||
public class ScatterAggregateHandler implements AggregateHandler {
|
public class ScatterAggregateHandler implements AggregateHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGnuplotDefinitions(StringBuilder result, Collection<DataSeries> dataSeries) {
|
public AxisSettings createYAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
// TODO Auto-generated method stub
|
return AxisTime.createYAxis(settings, dataSeries);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XAxisSettings createXAxisSettings(GnuplotSettings settings) {
|
|
||||||
return XAxisTime.create(settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlot(StringBuilder result, AggregatedData aggregatedData, LineStyle lineStyle, Optional<String> title) {
|
public AxisSettings createXAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
|
return AxisTime.createXAxis(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPlot(StringBuilder result, AggregatedData aggregatedData, LineStyle lineStyle,
|
||||||
|
Optional<String> title) {
|
||||||
|
|
||||||
appendfln(result, "'%s' using 1:2 %s with %s %s, \\", //
|
appendfln(result, "'%s' using 1:2 %s with %s %s, \\", //
|
||||||
aggregatedData.getDataFile(), //
|
aggregatedData.getDataFile(), //
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package org.lucares.recommind.logs;
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.lucares.pdb.api.DateTimeRange;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
public class AxisSettings {
|
||||||
public class XAxisSettings {
|
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
Number, Time
|
Number, Time
|
||||||
@@ -22,7 +22,7 @@ public class XAxisSettings {
|
|||||||
private String from;
|
private String from;
|
||||||
private String to;
|
private String to;
|
||||||
|
|
||||||
private Type type = Type.Time;
|
private Type type = Type.Number;
|
||||||
|
|
||||||
private GnuplotAxis axis = GnuplotAxis.X1;
|
private GnuplotAxis axis = GnuplotAxis.X1;
|
||||||
|
|
||||||
@@ -30,6 +30,9 @@ public class XAxisSettings {
|
|||||||
|
|
||||||
private boolean ticsEnabled;
|
private boolean ticsEnabled;
|
||||||
|
|
||||||
|
private boolean logscale;
|
||||||
|
|
||||||
|
private List<String> ticsLabels;
|
||||||
|
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
@@ -95,7 +98,6 @@ public class XAxisSettings {
|
|||||||
return ticIncrement;
|
return ticIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setTicsEnabled(boolean ticsEnabled) {
|
public void setTicsEnabled(boolean ticsEnabled) {
|
||||||
this.ticsEnabled = ticsEnabled;
|
this.ticsEnabled = ticsEnabled;
|
||||||
}
|
}
|
||||||
@@ -104,32 +106,62 @@ public class XAxisSettings {
|
|||||||
return ticsEnabled;
|
return ticsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLogscale(boolean logscale) {
|
||||||
|
this.logscale = logscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLogscale() {
|
||||||
|
return logscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTics(List<String> ticsLabels) {
|
||||||
|
this.ticsLabels = ticsLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTics() {
|
||||||
|
return ticsLabels;
|
||||||
|
}
|
||||||
|
|
||||||
public String toGnuplotDefinition(boolean renderLabels) {
|
public String toGnuplotDefinition(boolean renderLabels) {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
if (type == Type.Time) {
|
if (type == Type.Time) {
|
||||||
appendfln(result, "set %sdata time", axis);
|
appendfln(result, "set %sdata time", axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (renderLabels) {
|
||||||
|
|
||||||
if (ticIncrement != 0) {
|
if (ticIncrement != 0) {
|
||||||
appendfln(result, "set %stics %f", axis, ticIncrement);
|
appendfln(result, "set %stics %f nomirror", axis, ticIncrement);
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(format) && renderLabels) {
|
else if (ticsLabels != null && ticsLabels.size() > 0) {
|
||||||
|
appendfln(result,"set %stics(%s) nomirror", axis, String.join(", ", ticsLabels));
|
||||||
|
}else if(ticsEnabled) {
|
||||||
|
appendfln(result, "set %stics nomirror", axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(format)) {
|
||||||
appendfln(result, "set format %s \"%s\"", axis, format);
|
appendfln(result, "set format %s \"%s\"", axis, format);
|
||||||
}else {
|
|
||||||
appendfln(result, "set format %s \"\"", axis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rotateLabel != 0) {
|
if (rotateLabel != 0) {
|
||||||
appendfln(result, "set %stics nomirror rotate by %d", axis, rotateLabel);
|
appendfln(result, "set %stics nomirror rotate by %d", axis, rotateLabel);
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(label) && renderLabels) {
|
if (StringUtils.isNotBlank(label)) {
|
||||||
appendfln(result, "set %slabel \"%s\"", axis, label);
|
appendfln(result, "set %slabel \"%s\"", axis, label);
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
|
appendfln(result, "set format %s \"\"", axis);
|
||||||
appendfln(result, "set %slabel \"\"", axis);
|
appendfln(result, "set %slabel \"\"", axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StringUtils.isAllBlank(from, to)) {
|
if (!StringUtils.isAllBlank(from, to)) {
|
||||||
appendfln(result, "set %srange [\"%s\":\"%s\"]", axis, from, to);
|
final String f = StringUtils.isEmpty(from) ? "" : "\""+from+"\"";
|
||||||
|
final String t = StringUtils.isEmpty(to) ? "" : "\""+to+"\"";
|
||||||
|
appendfln(result, "set %srange [%s:%s]", axis, f, t);
|
||||||
|
}
|
||||||
|
if (logscale) {
|
||||||
|
appendfln(result, "set logscale %s", axis);
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
@@ -147,4 +179,6 @@ public class XAxisSettings {
|
|||||||
return e.getMessage();
|
return e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.lucares.pdb.plot.api.AxisScale;
|
||||||
|
import org.lucares.recommind.logs.AxisSettings.Type;
|
||||||
|
|
||||||
|
public class AxisTime {
|
||||||
|
public static AxisSettings createXAxis(GnuplotSettings settings) {
|
||||||
|
AxisSettings result = new AxisSettings();
|
||||||
|
|
||||||
|
final OffsetDateTime minDate = settings.getDateTimeRange().getStart();
|
||||||
|
final OffsetDateTime maxDate = settings.getDateTimeRange().getEnd();
|
||||||
|
final String formatX;
|
||||||
|
if (minDate.until(maxDate, ChronoUnit.WEEKS) > 1) {
|
||||||
|
formatX = "%Y-%m-%d";
|
||||||
|
} else if (minDate.until(maxDate, ChronoUnit.SECONDS) > 30) {
|
||||||
|
formatX = "%Y-%m-%d\\n%H:%M:%S";
|
||||||
|
} else {
|
||||||
|
formatX = "%Y-%m-%d\\n%H:%M:%.3S";
|
||||||
|
}
|
||||||
|
final String formattedMinDate = String.valueOf(minDate.toEpochSecond());
|
||||||
|
final String formattedMaxDate = String.valueOf(maxDate.toEpochSecond());
|
||||||
|
|
||||||
|
result.setLabel("Time");
|
||||||
|
result.setType(Type.Time);
|
||||||
|
result.setTicsEnabled(true);
|
||||||
|
result.setFormat(formatX);
|
||||||
|
result.setFrom(formattedMinDate);
|
||||||
|
result.setTo(formattedMaxDate);
|
||||||
|
result.setTicIncrement(XAxisTimeTics.computeTimeTicIncrement(settings.getWidth(), settings.getDateTimeRange()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AxisSettings createYAxis(GnuplotSettings settings, Collection<DataSeries> dataSeries) {
|
||||||
|
AxisSettings result = new AxisSettings();
|
||||||
|
result.setLabel("Duration");
|
||||||
|
result.setAxis(GnuplotAxis.Y1);
|
||||||
|
result.setTicsEnabled(true);
|
||||||
|
|
||||||
|
final int graphOffset = settings.getYAxisScale() == AxisScale.LINEAR ? 0 : 1;
|
||||||
|
if (settings.hasYRange()) {
|
||||||
|
final int min = Math.max(settings.getYRangeMin(), graphOffset);
|
||||||
|
final int max = settings.getYRangeMax();
|
||||||
|
result.setFrom(String.valueOf(min));
|
||||||
|
result.setTo(String.valueOf(max));
|
||||||
|
} else {
|
||||||
|
result.setFrom(String.valueOf(graphOffset));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setLogscale(settings.getYAxisScale() == AxisScale.LOG10);
|
||||||
|
|
||||||
|
result.setTics(YAxisTicks.computeYTicks(settings, dataSeries));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@ package org.lucares.recommind.logs;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.lucares.pdb.plot.api.AxisScale;
|
import org.lucares.pdb.plot.api.Appender;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class GnuplotFileGenerator {
|
public class GnuplotFileGenerator implements Appender{
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GnuplotFileGenerator.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GnuplotFileGenerator.class);
|
||||||
|
|
||||||
@@ -25,9 +25,23 @@ public class GnuplotFileGenerator {
|
|||||||
|
|
||||||
//settings.getAggregates().addGnuplotDefinitions(result, dataSeries);
|
//settings.getAggregates().addGnuplotDefinitions(result, dataSeries);
|
||||||
|
|
||||||
List<XAxisSettings> xAxisDefinitions = settings.getAggregates().getXAxisDefinitions(settings);
|
|
||||||
for (XAxisSettings xAxisSettings : xAxisDefinitions) {
|
|
||||||
appendln(result, xAxisSettings.toGnuplotDefinition(settings.isRenderLabels()));
|
final List<AxisSettings> xAxisDefinitions = settings.getAggregates().getXAxisDefinitions(settings, dataSeries);
|
||||||
|
for (AxisSettings axisSettings : xAxisDefinitions) {
|
||||||
|
appendln(result, axisSettings.toGnuplotDefinition(settings.isRenderLabels()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<AxisSettings> yAxisDefinitions = settings.getAggregates().getYAxisDefinitions(settings, dataSeries);
|
||||||
|
if(dataSeries.isEmpty()) {
|
||||||
|
// If there is no data, then Gnuplot won't generate an image.
|
||||||
|
// Workaround is to explicitly specify the y-axis range.
|
||||||
|
// We choose a range for which no ticks are defined. This creates an empty y-axis.
|
||||||
|
yAxisDefinitions.forEach(s -> s.setFrom("0"));
|
||||||
|
yAxisDefinitions.forEach(s -> s.setFrom("-1"));
|
||||||
|
}
|
||||||
|
for (AxisSettings axisSettings : yAxisDefinitions) {
|
||||||
|
appendln(result, axisSettings.toGnuplotDefinition(settings.isRenderLabels()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -41,27 +55,27 @@ public class GnuplotFileGenerator {
|
|||||||
// appendfln(result, "set xlabel \"%s\"", xAxis.getLabel());
|
// appendfln(result, "set xlabel \"%s\"", xAxis.getLabel());
|
||||||
// appendfln(result, "set xrange [\"%s\":\"%s\"]", xAxis.getFrom(), xAxis.getTo());
|
// appendfln(result, "set xrange [\"%s\":\"%s\"]", xAxis.getFrom(), xAxis.getTo());
|
||||||
|
|
||||||
final int graphOffset = settings.getYAxisScale() == AxisScale.LINEAR ? 0 : 1;
|
// final int graphOffset = settings.getYAxisScale() == AxisScale.LINEAR ? 0 : 1;
|
||||||
if (settings.hasYRange()) {
|
// if (settings.hasYRange()) {
|
||||||
final int min = Math.max(settings.getYRangeMin(), graphOffset);
|
// final int min = Math.max(settings.getYRangeMin(), graphOffset);
|
||||||
final int max = settings.getYRangeMax();
|
// final int max = settings.getYRangeMax();
|
||||||
appendfln(result, String.format("set yrange [\"%d\":\"%d\"]", min, max));
|
// appendfln(result, String.format("set yrange [\"%d\":\"%d\"]", min, max));
|
||||||
} else if(dataSeries.isEmpty()) {
|
// } else if(dataSeries.isEmpty()) {
|
||||||
// If there is no data, then Gnuplot won't generate an image.
|
// // If there is no data, then Gnuplot won't generate an image.
|
||||||
// Workaround is to explicitly specify the y-axis range.
|
// // Workaround is to explicitly specify the y-axis range.
|
||||||
// We choose a range for which no ticks are defined. This creates an empty y-axis.
|
// // We choose a range for which no ticks are defined. This creates an empty y-axis.
|
||||||
appendfln(result, "set yrange [\"%d\":\"%d\"]", 0, -1);
|
// appendfln(result, "set yrange [\"%d\":\"%d\"]", 0, -1);
|
||||||
}else {
|
// }else {
|
||||||
appendfln(result, "set yrange [\"" + graphOffset + "\":]");
|
// appendfln(result, "set yrange [\"" + graphOffset + "\":]");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
switch (settings.getYAxisScale()) {
|
// switch (settings.getYAxisScale()) {
|
||||||
case LINEAR:
|
// case LINEAR:
|
||||||
break;
|
// break;
|
||||||
case LOG10:
|
// case LOG10:
|
||||||
appendfln(result, "set logscale y");
|
// appendfln(result, "set logscale y");
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
appendfln(result, "set grid");
|
appendfln(result, "set grid");
|
||||||
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath().toString().replace("\\", "/"));
|
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath().toString().replace("\\", "/"));
|
||||||
@@ -77,10 +91,10 @@ public class GnuplotFileGenerator {
|
|||||||
// appendfln(result, "set x2label \"\"");
|
// appendfln(result, "set x2label \"\"");
|
||||||
// appendln(result, "set format x2 \"\"");
|
// appendln(result, "set format x2 \"\"");
|
||||||
//
|
//
|
||||||
appendfln(result, "set ylabel \"\"");
|
// appendfln(result, "set ylabel \"\"");
|
||||||
appendln(result, "set format y \"\"");
|
// appendln(result, "set format y \"\"");
|
||||||
appendln(result, "set y2label \"\"");
|
// appendln(result, "set y2label \"\"");
|
||||||
appendln(result, "set format y2 \"\"");
|
// appendln(result, "set format y2 \"\"");
|
||||||
|
|
||||||
appendln(result, "set nokey");
|
appendln(result, "set nokey");
|
||||||
} else if (!settings.isKeyOutside()) {
|
} else if (!settings.isKeyOutside()) {
|
||||||
@@ -93,10 +107,10 @@ public class GnuplotFileGenerator {
|
|||||||
appendln(result, "set bmargin 4"); // margin 4 -> 76
|
appendln(result, "set bmargin 4"); // margin 4 -> 76
|
||||||
|
|
||||||
appendfln(result, "set tics font \",%d\"", GnuplotSettings.TICKS_FONT_SIZE);
|
appendfln(result, "set tics font \",%d\"", GnuplotSettings.TICKS_FONT_SIZE);
|
||||||
appendln(result, YAxisTicks.computeYTicks(settings, dataSeries));
|
//appendln(result, YAxisTicks.computeYTicks(settings, dataSeries));
|
||||||
} else {
|
} else {
|
||||||
appendfln(result, "set tics font \",%d\"", GnuplotSettings.TICKS_FONT_SIZE);
|
appendfln(result, "set tics font \",%d\"", GnuplotSettings.TICKS_FONT_SIZE);
|
||||||
appendln(result, YAxisTicks.computeYTicks(settings, dataSeries));
|
//appendln(result, YAxisTicks.computeYTicks(settings, dataSeries));
|
||||||
}
|
}
|
||||||
|
|
||||||
appendf(result, "plot ");
|
appendf(result, "plot ");
|
||||||
@@ -112,17 +126,7 @@ public class GnuplotFileGenerator {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendfln(final StringBuilder builder, final String format, final Object... args) {
|
|
||||||
builder.append(String.format(format + "\n", args));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendln(final StringBuilder builder, final String string) {
|
|
||||||
builder.append(string + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendf(final StringBuilder builder, final String format, final Object... args) {
|
|
||||||
builder.append(String.format(format, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class GnuplotSettings {
|
|||||||
private AggregateHandlerCollection aggregates;
|
private AggregateHandlerCollection aggregates;
|
||||||
private boolean keyOutside = false;
|
private boolean keyOutside = false;
|
||||||
|
|
||||||
private XAxisSettings xAxisSettings = new XAxisSettings();
|
private AxisSettings xAxisSettings = new AxisSettings();
|
||||||
private boolean renderLabels = true;
|
private boolean renderLabels = true;
|
||||||
private int yRangeMin = -1;
|
private int yRangeMin = -1;
|
||||||
private int yRangeMax = -1;
|
private int yRangeMax = -1;
|
||||||
@@ -41,11 +41,11 @@ public class GnuplotSettings {
|
|||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XAxisSettings getxAxisSettings() {
|
public AxisSettings getxAxisSettings() {
|
||||||
return xAxisSettings;
|
return xAxisSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setxAxisSettings(final XAxisSettings xAxisSettings) {
|
public void setxAxisSettings(final AxisSettings xAxisSettings) {
|
||||||
this.xAxisSettings = xAxisSettings;
|
this.xAxisSettings = xAxisSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.nio.file.LinkOption;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package org.lucares.recommind.logs;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
|
|
||||||
import org.lucares.recommind.logs.XAxisSettings.Type;
|
|
||||||
|
|
||||||
public class XAxisTime {
|
|
||||||
public static XAxisSettings create(GnuplotSettings settings) {
|
|
||||||
XAxisSettings result = new XAxisSettings();
|
|
||||||
|
|
||||||
final OffsetDateTime minDate = settings.getDateTimeRange().getStart();
|
|
||||||
final OffsetDateTime maxDate = settings.getDateTimeRange().getEnd();
|
|
||||||
final String formatX;
|
|
||||||
if (minDate.until(maxDate, ChronoUnit.WEEKS) > 1) {
|
|
||||||
formatX = "%Y-%m-%d";
|
|
||||||
} else if (minDate.until(maxDate, ChronoUnit.SECONDS) > 30) {
|
|
||||||
formatX = "%Y-%m-%d\\n%H:%M:%S";
|
|
||||||
} else {
|
|
||||||
formatX = "%Y-%m-%d\\n%H:%M:%.3S";
|
|
||||||
}
|
|
||||||
final String formattedMinDate = String.valueOf(minDate.toEpochSecond());
|
|
||||||
final String formattedMaxDate = String.valueOf(maxDate.toEpochSecond());
|
|
||||||
|
|
||||||
result.setLabel("Time");
|
|
||||||
result.setType(Type.Time);
|
|
||||||
result.setTicsEnabled(true);
|
|
||||||
result.setFormat(formatX);
|
|
||||||
result.setFrom(formattedMinDate);
|
|
||||||
result.setTo(formattedMaxDate);
|
|
||||||
result.setTicIncrement(XAxisTimeTics.computeTimeTicIncrement(settings.getWidth(), settings.getDateTimeRange()));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,13 +9,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
class YAxisTicks {
|
class YAxisTicks {
|
||||||
|
|
||||||
|
|
||||||
public static String computeYTicks(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
public static List<String> computeYTicks(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||||
String result = "";
|
List<String> result = new ArrayList<String>();
|
||||||
|
|
||||||
final long yRangeMax;
|
final long yRangeMax;
|
||||||
final long yRangeMin;
|
final long yRangeMin;
|
||||||
@@ -41,9 +42,7 @@ class YAxisTicks {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String computeLog10YTicks(final int height, final long yRangeMin, final long yRangeMax) {
|
private static List<String> computeLog10YTicks(final int height, final long yRangeMin, final long yRangeMax) {
|
||||||
final StringBuilder result = new StringBuilder();
|
|
||||||
result.append("set ylabel \"Duration\"\n");
|
|
||||||
|
|
||||||
final List<String> ticsLabels = Arrays.asList(//
|
final List<String> ticsLabels = Arrays.asList(//
|
||||||
"\"1ms\" 1", //
|
"\"1ms\" 1", //
|
||||||
@@ -74,22 +73,20 @@ private static String computeLog10YTicks(final int height, final long yRangeMin,
|
|||||||
"\"2d\" 172800000", //
|
"\"2d\" 172800000", //
|
||||||
"\"1 week\" 604800000", //
|
"\"1 week\" 604800000", //
|
||||||
"\"2 week\" 1209600000.0", //
|
"\"2 week\" 1209600000.0", //
|
||||||
"\"4 week\" 2419200000.0" //
|
"\"4 week\" 2419200000.0", //
|
||||||
|
"\"3 month\" 7776000000.0", //
|
||||||
|
"\"1 year\" 31536000000.0", //
|
||||||
|
"\"5 year\" 157680000000.0", //
|
||||||
|
"\"10 year\" 315360000000.0"
|
||||||
);
|
);
|
||||||
|
|
||||||
result.append("set ytics (");
|
|
||||||
result.append(String.join(", ", ticsLabels));
|
|
||||||
result.append(")\n");
|
|
||||||
|
|
||||||
return result.toString();
|
return ticsLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String computeLinearYTicks(final long height, final long yRangeMin, final long yRangeMax) {
|
private static List<String> computeLinearYTicks(final long height, final long yRangeMin, final long yRangeMax) {
|
||||||
final StringBuilder result = new StringBuilder();
|
|
||||||
result.append("set ylabel \"Duration\"\n");
|
|
||||||
|
|
||||||
final long plotHeight = height - GnuplotSettings.GNUPLOT_TOP_BOTTOM_MARGIN; // sum of top/bottom margin, see
|
final long plotHeight = height - GnuplotSettings.GNUPLOT_TOP_BOTTOM_MARGIN;
|
||||||
// marker (1)
|
|
||||||
final long maxLabels = plotHeight / (GnuplotSettings.TICKS_FONT_SIZE * 5);
|
final long maxLabels = plotHeight / (GnuplotSettings.TICKS_FONT_SIZE * 5);
|
||||||
|
|
||||||
final long range = yRangeMax - yRangeMin;
|
final long range = yRangeMax - yRangeMin;
|
||||||
@@ -100,10 +97,7 @@ private static String computeLinearYTicks(final long height, final long yRangeMi
|
|||||||
ticsLabels.add("\"" + msToTic(i, msPerLabel) + "\" " + i);
|
ticsLabels.add("\"" + msToTic(i, msPerLabel) + "\" " + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.append("set ytics (");
|
return ticsLabels;
|
||||||
result.append(String.join(", ", ticsLabels));
|
|
||||||
result.append(")\n");
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long roundToLinearLabelSteps(final long msPerLabel) {
|
private static long roundToLinearLabelSteps(final long msPerLabel) {
|
||||||
@@ -128,9 +122,9 @@ private static String msToTic(final long ms, final double msPerLabel) {
|
|||||||
return ms + "ms";
|
return ms + "ms";
|
||||||
} else if (ms < MINUTES.toMillis(1)) {
|
} else if (ms < MINUTES.toMillis(1)) {
|
||||||
if (msPerLabel % 1000 == 0) {
|
if (msPerLabel % 1000 == 0) {
|
||||||
return String.format("%ds", ms / 1_000);
|
return String.format(Locale.US,"%ds", ms / 1_000);
|
||||||
} else {
|
} else {
|
||||||
return String.format("%.1fs", ms / 1_000.0);
|
return String.format(Locale.US,"%.1fs", ms / 1_000.0);
|
||||||
}
|
}
|
||||||
} else if (ms < TimeUnit.HOURS.toMillis(1)) {
|
} else if (ms < TimeUnit.HOURS.toMillis(1)) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user