group plots by a single field
This commit is contained in:
@@ -11,22 +11,17 @@ public class DataSeries {
|
||||
|
||||
private final Integer pointType;
|
||||
|
||||
public DataSeries(final File dataFile, final String title) {
|
||||
private final int values;
|
||||
|
||||
public DataSeries(final File dataFile, final String title, final int values) {
|
||||
super();
|
||||
this.dataFile = dataFile;
|
||||
this.title = title;
|
||||
this.values = values;
|
||||
this.color = null;
|
||||
this.pointType = null;
|
||||
}
|
||||
|
||||
public DataSeries(final File dataFile, final String title, final GnuplotColor color, final Integer pointType) {
|
||||
super();
|
||||
this.dataFile = dataFile;
|
||||
this.title = title;
|
||||
this.color = color;
|
||||
this.pointType = pointType;
|
||||
}
|
||||
|
||||
public GnuplotColor getColor() {
|
||||
return color;
|
||||
}
|
||||
@@ -42,4 +37,8 @@ public class DataSeries {
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public int getValues() {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,11 @@ import java.util.Iterator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.lucares.pdb.api.Entry;
|
||||
import org.lucares.pdb.api.GroupResult;
|
||||
import org.lucares.pdb.api.Result;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.performance.db.FileUtils;
|
||||
import org.lucares.performance.db.Grouping;
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
|
||||
public class Plotter {
|
||||
@@ -43,17 +47,24 @@ public class Plotter {
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
public File plot(final String query, final int height, final int width) throws InternalPlottingException {
|
||||
public File plot(final String query, final int height, final int width, final String groupBy)
|
||||
throws InternalPlottingException {
|
||||
try {
|
||||
final Collection<DataSeries> dataSeries = new ArrayList<>();
|
||||
|
||||
final Stream<Entry> entries = db.get(query).singleGroup().asStream();
|
||||
final Result result = db.get(query, groupBy);
|
||||
|
||||
final File dataFile = File.createTempFile("data", ".dat", tmpBaseDir.toFile());
|
||||
final DataSeries dataSerie = new DataSeries(dataFile, query);
|
||||
toCsv(entries, dataFile);
|
||||
for (final GroupResult groupResult : result.getGroups()) {
|
||||
|
||||
dataSeries.add(dataSerie);
|
||||
final Stream<Entry> entries = groupResult.asStream();
|
||||
|
||||
final File dataFile = File.createTempFile("data", ".dat", tmpBaseDir.toFile());
|
||||
final int values = toCsv(entries, dataFile);
|
||||
|
||||
final String title = title(groupResult.getGroupedBy(), values);
|
||||
final DataSeries dataSerie = new DataSeries(dataFile, title, values);
|
||||
dataSeries.add(dataSerie);
|
||||
}
|
||||
|
||||
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
||||
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);
|
||||
@@ -70,6 +81,23 @@ public class Plotter {
|
||||
}
|
||||
}
|
||||
|
||||
private String title(final Tags tags, final int values) {
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
assert tags.getKeys().size() <= 1;
|
||||
tags.forEach((k, v) -> {
|
||||
result.append(v);
|
||||
});
|
||||
|
||||
result.append("(");
|
||||
result.append(values);
|
||||
result.append(")");
|
||||
|
||||
return result.toString();
|
||||
|
||||
}
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
final Path dataDirectory = Paths.get(args[0]);
|
||||
final Path outputDirectory = Paths.get(args[1]);
|
||||
@@ -81,7 +109,7 @@ public class Plotter {
|
||||
|
||||
try (PerformanceDb db = new PerformanceDb(dataDirectory)) {
|
||||
final Plotter plotter = new Plotter(db, tmpBaseDir, outputDirectory);
|
||||
final File image = plotter.plot(query, 1600, 1200);
|
||||
final File image = plotter.plot(query, 1600, 1200, Grouping.NO_GROUPING);
|
||||
System.out.println("plotted image: " + image);
|
||||
}
|
||||
|
||||
@@ -90,7 +118,7 @@ public class Plotter {
|
||||
}
|
||||
}
|
||||
|
||||
private static void toCsv(final Stream<Entry> entries, final File dataFile) throws IOException {
|
||||
private static int toCsv(final Stream<Entry> entries, final File dataFile) throws IOException {
|
||||
|
||||
final long start = System.nanoTime();
|
||||
int count = 0;
|
||||
@@ -111,6 +139,8 @@ public class Plotter {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("wrote " + count + " values to csv in: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user