add dashboard

This commit is contained in:
2018-04-27 19:36:31 +02:00
parent 38ffff38de
commit 913057c6df
11 changed files with 304 additions and 60 deletions

View File

@@ -20,6 +20,10 @@ public class PlotSettings {
private int width;
private int thumbnailMaxWidth = 0;
private int thumbnailMaxHeight = 0;
private List<String> groupBy;
private Limit limitBy;
@@ -62,6 +66,22 @@ public class PlotSettings {
this.width = width;
}
public int getThumbnailMaxWidth() {
return thumbnailMaxWidth;
}
public void setThumbnailMaxWidth(final int thumbnailMaxWidth) {
this.thumbnailMaxWidth = thumbnailMaxWidth;
}
public int getThumbnailMaxHeight() {
return thumbnailMaxHeight;
}
public void setThumbnailMaxHeight(final int thumbnailMaxHeight) {
this.thumbnailMaxHeight = thumbnailMaxHeight;
}
public List<String> getGroupBy() {
return groupBy;
}
@@ -160,20 +180,22 @@ public class PlotSettings {
@Override
public String toString() {
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", groupBy=" + groupBy
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", thumbnailMaxWidth="
+ thumbnailMaxWidth + ", thumbnailMaxHeight=" + thumbnailMaxHeight + ", groupBy=" + groupBy
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateFrom=" + dateFrom + ", dateRange=" + dateRange
+ ", axisScale=" + yAxisScale + ", aggregate="+aggregate+", keyOutside="+keyOutside+"]";
+ ", yAxisScale=" + yAxisScale + ", aggregate=" + aggregate + ", keyOutside=" + keyOutside
+ ", plotType=" + plotType + "]";
}
public void setAggregate(AggregateHandler aggregate) {
public void setAggregate(final AggregateHandler aggregate) {
this.aggregate = aggregate;
}
public AggregateHandler getAggregate() {
return aggregate;
}
public void setKeyOutside(boolean keyOutside) {
public void setKeyOutside(final boolean keyOutside) {
this.keyOutside = keyOutside;
}
@@ -181,10 +203,10 @@ public class PlotSettings {
return keyOutside;
}
public void setPlotType(PlotType plotType) {
public void setPlotType(final PlotType plotType) {
this.plotType = plotType;
}
public PlotType getPlotType() {
return plotType;
}

View File

@@ -101,7 +101,7 @@ public class PercentilePlot implements ConcretePlotter {
gnuplotSettings.setKeyOutside(plotSettings.isKeyOutside());
gnuplot.plot(gnuplotSettings, dataSeries);
return new PlotResult(outputFile, dataSeries);
return new PlotResult(outputFile, dataSeries, null); // TODO thumbail
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Plotting was interrupted.");

View File

@@ -6,11 +6,13 @@ import java.util.List;
public class PlotResult {
private final Path imagePath;
private final List<DataSeries> dataSeries;
private final Path thumbnail;
public PlotResult(final Path imagePath, final List<DataSeries> dataSeries) {
public PlotResult(final Path imagePath, final List<DataSeries> dataSeries, final Path thumbnail) {
super();
this.imagePath = imagePath;
this.dataSeries = dataSeries;
this.thumbnail = thumbnail;
}
public Path getImageName() {
@@ -21,6 +23,14 @@ public class PlotResult {
return imagePath;
}
public Path getThumbnailName() {
return thumbnail.getFileName();
}
public Path getThumbnailPath() {
return thumbnail;
}
public List<DataSeries> getDataSeries() {
return dataSeries;
}

View File

@@ -1,5 +1,7 @@
package org.lucares.recommind.logs;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -21,6 +23,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import javax.imageio.ImageIO;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.GroupResult;
import org.lucares.pdb.api.Result;
@@ -118,7 +122,10 @@ public class ScatterPlot implements ConcretePlotter {
gnuplotSettings.setKeyOutside(plotSettings.isKeyOutside());
gnuplot.plot(gnuplotSettings, dataSeries);
return new PlotResult(outputFile, dataSeries);
final Path thumbnail = createOptionalThumbnail(outputFile, plotSettings.getThumbnailMaxWidth(),
plotSettings.getThumbnailMaxHeight());
return new PlotResult(outputFile, dataSeries, thumbnail);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Plotting was interrupted.");
@@ -130,6 +137,44 @@ public class ScatterPlot implements ConcretePlotter {
}
}
private static BufferedImage resizeImage(final BufferedImage originalImage, final Integer img_width,
final Integer img_height) {
final int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
final BufferedImage resizedImage = new BufferedImage(img_width, img_height, type);
final Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, img_width, img_height, null);
g.dispose();
return resizedImage;
}
private Path createOptionalThumbnail(final Path originalImage, final int thumbnailMaxWidth,
final int thumbnailMaxHeight) {
Path result;
if (thumbnailMaxWidth > 0 && thumbnailMaxHeight > 0) {
try {
final long start = System.nanoTime();
final BufferedImage image = ImageIO.read(originalImage.toFile());
final BufferedImage thumbnail = resizeImage(image, thumbnailMaxWidth, thumbnailMaxHeight);
final Path thumbnailPath = originalImage.getParent()
.resolve(originalImage.getFileName() + ".thumbnail.jpg");
ImageIO.write(thumbnail, "JPG", thumbnailPath.toFile());
LOGGER.info("thumbnail creation: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
result = thumbnailPath;
} catch (final IOException e) {
LOGGER.warn("failed to scale image", e);
result = null;
}
} else {
result = null;
}
return result;
}
private void defineXAxis(final GnuplotSettings gnuplotSettings, final OffsetDateTime minDate,
final OffsetDateTime maxDate) {