return information about the plotted sequences
this information can be used for tests
This commit is contained in:
@@ -2,6 +2,9 @@ package org.lucares.recommind.logs;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class DataSeries {
|
public class DataSeries {
|
||||||
public static final Comparator<? super DataSeries> BY_VALUES = (a, b) -> {
|
public static final Comparator<? super DataSeries> BY_VALUES = (a, b) -> {
|
||||||
@@ -46,4 +49,16 @@ public class DataSeries {
|
|||||||
public int getValues() {
|
public int getValues() {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, Integer> toMap(final List<DataSeries> dataSeries) {
|
||||||
|
final Map<String, Integer> result = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (final DataSeries dataSerie : dataSeries) {
|
||||||
|
|
||||||
|
result.put(dataSerie.getTitle(), dataSerie.values);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class GnuplotFileGenerator {
|
|||||||
|
|
||||||
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
||||||
|
|
||||||
appendfln(result, "set output \"%s\"", settings.getOutput().getAbsolutePath());
|
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath());
|
||||||
appendf(result, "plot ");
|
appendf(result, "plot ");
|
||||||
|
|
||||||
for (final DataSeries dataSerie : dataSeries) {
|
for (final DataSeries dataSerie : dataSeries) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.lucares.recommind.logs;
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
import java.io.File;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class GnuplotSettings {
|
public class GnuplotSettings {
|
||||||
private String terminal = "png";
|
private String terminal = "png";
|
||||||
@@ -21,12 +21,12 @@ public class GnuplotSettings {
|
|||||||
private String ylabel = "Duration in ms";
|
private String ylabel = "Duration in ms";
|
||||||
|
|
||||||
// set output "datausage.png"
|
// set output "datausage.png"
|
||||||
private File output = new File("/tmp/out.png");
|
private final Path output;
|
||||||
|
|
||||||
// set xtics rotate by 80
|
// set xtics rotate by 80
|
||||||
private int rotateXAxisLabel = -80;
|
private int rotateXAxisLabel = -80;
|
||||||
|
|
||||||
public GnuplotSettings(final File output) {
|
public GnuplotSettings(final Path output) {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +102,10 @@ public class GnuplotSettings {
|
|||||||
this.ylabel = ylabel;
|
this.ylabel = ylabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getOutput() {
|
public Path getOutput() {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOutput(final File output) {
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PlotResult {
|
||||||
|
private final Path imageName;
|
||||||
|
private final List<DataSeries> dataSeries;
|
||||||
|
|
||||||
|
public PlotResult(final Path imageName, final List<DataSeries> dataSeries) {
|
||||||
|
super();
|
||||||
|
this.imageName = imageName;
|
||||||
|
this.dataSeries = dataSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path getImageName() {
|
||||||
|
return imageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataSeries> getDataSeries() {
|
||||||
|
return dataSeries;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.LinkOption;
|
import java.nio.file.LinkOption;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
@@ -29,7 +28,6 @@ import org.lucares.pdb.api.Tags;
|
|||||||
import org.lucares.pdb.plot.api.Limit;
|
import org.lucares.pdb.plot.api.Limit;
|
||||||
import org.lucares.pdb.plot.api.PlotSettings;
|
import org.lucares.pdb.plot.api.PlotSettings;
|
||||||
import org.lucares.performance.db.FileUtils;
|
import org.lucares.performance.db.FileUtils;
|
||||||
import org.lucares.performance.db.Grouping;
|
|
||||||
import org.lucares.performance.db.PerformanceDb;
|
import org.lucares.performance.db.PerformanceDb;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -59,7 +57,7 @@ public class Plotter {
|
|||||||
return outputDir;
|
return outputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File plot(final PlotSettings plotSettings) throws InternalPlottingException {
|
public PlotResult plot(final PlotSettings plotSettings) throws InternalPlottingException {
|
||||||
|
|
||||||
final String tmpSubDir = uniqueDirectoryName();
|
final String tmpSubDir = uniqueDirectoryName();
|
||||||
final Path tmpDir = tmpBaseDir.resolve(tmpSubDir);
|
final Path tmpDir = tmpBaseDir.resolve(tmpSubDir);
|
||||||
@@ -102,14 +100,15 @@ public class Plotter {
|
|||||||
|
|
||||||
sortAndLimit(dataSeries, plotSettings);
|
sortAndLimit(dataSeries, plotSettings);
|
||||||
|
|
||||||
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
final Path outputFile = Files.createTempFile(outputDir, "out", ".png");
|
||||||
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);
|
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);
|
||||||
final GnuplotSettings gnuplotSettings = new GnuplotSettings(outputFile);
|
final GnuplotSettings gnuplotSettings = new GnuplotSettings(outputFile);
|
||||||
gnuplotSettings.setHeight(height);
|
gnuplotSettings.setHeight(height);
|
||||||
gnuplotSettings.setWidth(width);
|
gnuplotSettings.setWidth(width);
|
||||||
gnuplotSettings.setFormatX(getFormatX(minDate, maxDate));
|
gnuplotSettings.setFormatX(getFormatX(minDate, maxDate));
|
||||||
gnuplot.plot(gnuplotSettings, dataSeries);
|
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||||
return outputFile;
|
|
||||||
|
return new PlotResult(outputFile.getFileName(), dataSeries);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IllegalStateException("Plotting was interrupted.");
|
throw new IllegalStateException("Plotting was interrupted.");
|
||||||
@@ -176,34 +175,6 @@ public class Plotter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(final String[] args) throws Exception {
|
|
||||||
final Path dataDirectory = Paths.get(args[0]);
|
|
||||||
final Path outputDirectory = Paths.get(args[1]);
|
|
||||||
final String query = args[2];
|
|
||||||
final Path tmpBaseDir = Paths.get(args[0], "tmp", "gnuplot");
|
|
||||||
Files.createDirectories(tmpBaseDir);
|
|
||||||
Files.createDirectories(outputDirectory);
|
|
||||||
try {
|
|
||||||
|
|
||||||
try (PerformanceDb db = new PerformanceDb(dataDirectory)) {
|
|
||||||
final Plotter plotter = new Plotter(db, tmpBaseDir, outputDirectory);
|
|
||||||
// query, 1600, 1200, Grouping.NO_GROUPING
|
|
||||||
|
|
||||||
final PlotSettings plotSettings = new PlotSettings();
|
|
||||||
plotSettings.setQuery(query);
|
|
||||||
plotSettings.setWidth(1600);
|
|
||||||
plotSettings.setHeight(1200);
|
|
||||||
plotSettings.setGroupBy(Grouping.NO_GROUPING);
|
|
||||||
|
|
||||||
final File image = plotter.plot(plotSettings);
|
|
||||||
LOGGER.trace("plotted image: {}", image);
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
FileUtils.delete(tmpBaseDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CsvSummary toCsv(final Stream<Entry> entries, final File dataFile, final OffsetDateTime dateFrom,
|
private static CsvSummary toCsv(final Stream<Entry> entries, final File dataFile, final OffsetDateTime dateFrom,
|
||||||
final OffsetDateTime dateTo) throws IOException {
|
final OffsetDateTime dateTo) throws IOException {
|
||||||
|
|
||||||
|
|||||||
18
pdb-ui/src/main/java/org/lucares/pdbui/BadRequest.java
Normal file
18
pdb-ui/src/main/java/org/lucares/pdbui/BadRequest.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "BadRequest")
|
||||||
|
public class BadRequest extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 694206253376122420L;
|
||||||
|
|
||||||
|
public BadRequest(final String message, final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BadRequest(final Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.lucares.pdbui;
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -19,8 +17,10 @@ import org.lucares.pdbui.domain.AutocompleteResponse;
|
|||||||
import org.lucares.pdbui.domain.PlotRequest;
|
import org.lucares.pdbui.domain.PlotRequest;
|
||||||
import org.lucares.pdbui.domain.PlotResponse;
|
import org.lucares.pdbui.domain.PlotResponse;
|
||||||
import org.lucares.performance.db.CollectionUtils;
|
import org.lucares.performance.db.CollectionUtils;
|
||||||
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
import org.lucares.recommind.logs.InternalPlottingException;
|
import org.lucares.recommind.logs.InternalPlottingException;
|
||||||
import org.lucares.recommind.logs.NoDataPointsException;
|
import org.lucares.recommind.logs.NoDataPointsException;
|
||||||
|
import org.lucares.recommind.logs.PlotResult;
|
||||||
import org.lucares.recommind.logs.Plotter;
|
import org.lucares.recommind.logs.Plotter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -73,13 +73,12 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final File image = plotter.plot(plotSettings);
|
final PlotResult result = plotter.plot(plotSettings);
|
||||||
|
|
||||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + result.getImageName();
|
||||||
final String relativeImgUrl = relativeImagePath.toString().replace('\\', '/');
|
|
||||||
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + relativeImgUrl;
|
|
||||||
LOGGER.trace("image url: {}", imageUrl);
|
LOGGER.trace("image url: {}", imageUrl);
|
||||||
return new PlotResponse(imageUrl);
|
|
||||||
|
return new PlotResponse(DataSeries.toMap(result.getDataSeries()), imageUrl);
|
||||||
} catch (final NoDataPointsException e) {
|
} catch (final NoDataPointsException e) {
|
||||||
throw new NotFoundException(e);
|
throw new NotFoundException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,14 @@ package org.lucares.pdbui.domain;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlotResponse {
|
public class PlotResponse {
|
||||||
private List<String> imageUrls = new ArrayList<>();
|
private List<String> imageUrls = new ArrayList<>();
|
||||||
|
private Map<String, Integer> dataSeries;
|
||||||
|
|
||||||
public PlotResponse() {
|
public PlotResponse(final Map<String, Integer> dataSeries, final String... imageUrls) {
|
||||||
super();
|
this.dataSeries = dataSeries;
|
||||||
}
|
|
||||||
|
|
||||||
public PlotResponse(final String... imageUrls) {
|
|
||||||
this.imageUrls.addAll(Arrays.asList(imageUrls));
|
this.imageUrls.addAll(Arrays.asList(imageUrls));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,9 +22,17 @@ public class PlotResponse {
|
|||||||
this.imageUrls = imageUrls;
|
this.imageUrls = imageUrls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Integer> getDataSeries() {
|
||||||
|
return dataSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataSeries(final Map<String, Integer> dataSeries) {
|
||||||
|
this.dataSeries = dataSeries;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.valueOf(imageUrls);
|
return String.valueOf(imageUrls) + " " + dataSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user