Extract interface for DataSeries
This will make it possible to have DataSeries that do not require a csv file on disk.
This commit is contained in:
@@ -6,6 +6,8 @@ import org.lucares.recommind.logs.DataSeries;
|
|||||||
|
|
||||||
public interface AggregateHandler {
|
public interface AggregateHandler {
|
||||||
|
|
||||||
|
// TODO handle aggregates as normal DataSeries
|
||||||
|
|
||||||
void addGnuplotDefinitions(StringBuilder result, String separator, Collection<DataSeries> dataSeries);
|
void addGnuplotDefinitions(StringBuilder result, String separator, Collection<DataSeries> dataSeries);
|
||||||
|
|
||||||
default void appendfln(final StringBuilder builder, final String format, final Object... args) {
|
default void appendfln(final StringBuilder builder, final String format, final Object... args) {
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ package org.lucares.pdb.plot.api;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
|
import org.lucares.recommind.logs.FileBackedDataSeries;
|
||||||
|
|
||||||
public class MeanAggregate implements AggregateHandler{
|
public class MeanAggregate implements AggregateHandler{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGnuplotDefinitions(StringBuilder result, String separator, Collection<DataSeries> dataSeries) {
|
public void addGnuplotDefinitions(StringBuilder result, String separator, Collection<DataSeries> dataSeries) {
|
||||||
int count = 1;
|
int count = 1;
|
||||||
for (final DataSeries dataSerie : dataSeries) {
|
for (final DataSeries dataSerie : dataSeries) {
|
||||||
|
if (dataSerie instanceof FileBackedDataSeries){
|
||||||
appendfln(result, "stats '%s' using 2 prefix \"A%d\"", dataSerie.getDataFile(),count);
|
appendfln(result, "stats '%s' using 2 prefix \"A%d\"", ((FileBackedDataSeries) dataSerie).getDataFile(),count);
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,9 +22,11 @@ public class MeanAggregate implements AggregateHandler{
|
|||||||
public void addPlots(StringBuilder result, Collection<DataSeries> dataSeries) {
|
public void addPlots(StringBuilder result, Collection<DataSeries> dataSeries) {
|
||||||
int count = 1;
|
int count = 1;
|
||||||
for (final DataSeries dataSerie : dataSeries) {
|
for (final DataSeries dataSerie : dataSeries) {
|
||||||
appendfln(result, "A%d_mean title '%s Mean', \\", count,
|
if (dataSerie instanceof FileBackedDataSeries){
|
||||||
dataSerie.getTitle(), dataSerie.getTitle());
|
appendfln(result, "A%d_mean title '%s Mean', \\", count,
|
||||||
count++;
|
dataSerie.getTitle(), dataSerie.getTitle());
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.lucares.recommind.logs;
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -9,7 +8,7 @@ import java.util.Map;
|
|||||||
import org.lucares.pdb.plot.api.AggregatedData;
|
import org.lucares.pdb.plot.api.AggregatedData;
|
||||||
import org.lucares.pdb.plot.api.Limit;
|
import org.lucares.pdb.plot.api.Limit;
|
||||||
|
|
||||||
public class DataSeries {
|
public interface DataSeries {
|
||||||
public static final Comparator<? super DataSeries> BY_NUMBER_OF_VALUES = (
|
public static final Comparator<? super DataSeries> BY_NUMBER_OF_VALUES = (
|
||||||
a, b) -> {
|
a, b) -> {
|
||||||
return a.getValues() - b.getValues();
|
return a.getValues() - b.getValues();
|
||||||
@@ -20,40 +19,15 @@ public class DataSeries {
|
|||||||
return result < 0 ? -1 : (result > 0 ? 1 : 0);
|
return result < 0 ? -1 : (result > 0 ? 1 : 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
private final String title;
|
public String getId();
|
||||||
|
|
||||||
private CsvSummary csvSummary;
|
public String getTitle();
|
||||||
|
public int getValues();
|
||||||
|
public long getMaxValue();
|
||||||
|
|
||||||
private String id;
|
public AggregatedData getAggregatedData();
|
||||||
|
|
||||||
public DataSeries(String id, String title, CsvSummary csvSummary) {
|
public String getGnuplotPlotDefinition();
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
|
||||||
this.csvSummary = csvSummary;
|
|
||||||
}
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getDataFile() {
|
|
||||||
return csvSummary.getDataFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getValues() {
|
|
||||||
return csvSummary.getValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMaxValue() {
|
|
||||||
return csvSummary.getMaxValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AggregatedData getAggregatedData() {
|
|
||||||
return csvSummary.getAggregatedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, Integer> toMap(final List<DataSeries> dataSeries) {
|
public static Map<String, Integer> toMap(final List<DataSeries> dataSeries) {
|
||||||
final Map<String, Integer> result = new LinkedHashMap<>();
|
final Map<String, Integer> result = new LinkedHashMap<>();
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.lucares.pdb.plot.api.AggregatedData;
|
||||||
|
|
||||||
|
public class FileBackedDataSeries implements DataSeries {
|
||||||
|
|
||||||
|
private final String title;
|
||||||
|
|
||||||
|
private CsvSummary csvSummary;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
public FileBackedDataSeries(String id, String title, CsvSummary csvSummary) {
|
||||||
|
this.id = id;
|
||||||
|
this.title = title;
|
||||||
|
this.csvSummary = csvSummary;
|
||||||
|
}
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDataFile() {
|
||||||
|
return csvSummary.getDataFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValues() {
|
||||||
|
return csvSummary.getValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMaxValue() {
|
||||||
|
return csvSummary.getMaxValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AggregatedData getAggregatedData() {
|
||||||
|
return csvSummary.getAggregatedData();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getGnuplotPlotDefinition() {
|
||||||
|
return String.format("'%s' using 1:2 title '%s' with points, \\", getDataFile(),
|
||||||
|
getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,8 +62,7 @@ public class GnuplotFileGenerator {
|
|||||||
appendf(result, "plot ");
|
appendf(result, "plot ");
|
||||||
|
|
||||||
for (final DataSeries dataSerie : dataSeries) {
|
for (final DataSeries dataSerie : dataSeries) {
|
||||||
appendfln(result, "'%s' using 1:2 title '%s' with points, \\", dataSerie.getDataFile(),
|
appendfln(result, dataSerie.getGnuplotPlotDefinition());
|
||||||
dataSerie.getTitle());
|
|
||||||
}
|
}
|
||||||
settings.getAggregate().addPlots(result, dataSeries);
|
settings.getAggregate().addPlots(result, dataSeries);
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class ScatterPlot {
|
|||||||
|
|
||||||
final int id = idCounter.getAndIncrement();
|
final int id = idCounter.getAndIncrement();
|
||||||
final String title = title(groupResult.getGroupedBy(), csvSummary.getValues());
|
final String title = title(groupResult.getGroupedBy(), csvSummary.getValues());
|
||||||
final DataSeries dataSerie = new DataSeries("id"+id, title, csvSummary);
|
final DataSeries dataSerie = new FileBackedDataSeries("id"+id, title, csvSummary);
|
||||||
if (dataSerie.getValues() > 0) {
|
if (dataSerie.getValues() > 0) {
|
||||||
dataSeries.add(dataSerie);
|
dataSeries.add(dataSerie);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user