limit the number of plots
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
package org.lucares.pdb.plot.api;
|
||||||
|
|
||||||
|
public enum Limit {
|
||||||
|
NO_LIMIT, MOST_VALUES, FEWEST_VALUES
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package org.lucares.pdb.plot.api;
|
||||||
|
|
||||||
|
public class PlotSettings {
|
||||||
|
private String query;
|
||||||
|
|
||||||
|
private int height;
|
||||||
|
|
||||||
|
private int width;
|
||||||
|
|
||||||
|
private String groupBy;
|
||||||
|
|
||||||
|
private Limit limitBy;
|
||||||
|
|
||||||
|
private int limit;
|
||||||
|
|
||||||
|
public String getQuery() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuery(final String query) {
|
||||||
|
this.query = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeight(final int height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(final int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupBy() {
|
||||||
|
return groupBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupBy(final String groupBy) {
|
||||||
|
this.groupBy = groupBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Limit getLimitBy() {
|
||||||
|
return limitBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLimitBy(final Limit limitBy) {
|
||||||
|
this.limitBy = limitBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLimit(final int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package org.lucares.recommind.logs;
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
public class DataSeries {
|
public class DataSeries {
|
||||||
|
public static final Comparator<? super DataSeries> BY_VALUES = (a, b) -> {
|
||||||
|
return a.getValues() - b.getValues();
|
||||||
|
};
|
||||||
|
|
||||||
private final File dataFile;
|
private final File dataFile;
|
||||||
|
|
||||||
private final String title;
|
private final String title;
|
||||||
|
|||||||
@@ -12,14 +12,17 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.lucares.pdb.api.Entry;
|
import org.lucares.pdb.api.Entry;
|
||||||
import org.lucares.pdb.api.GroupResult;
|
import org.lucares.pdb.api.GroupResult;
|
||||||
import org.lucares.pdb.api.Result;
|
import org.lucares.pdb.api.Result;
|
||||||
import org.lucares.pdb.api.Tags;
|
import org.lucares.pdb.api.Tags;
|
||||||
|
import org.lucares.pdb.plot.api.Limit;
|
||||||
|
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.Grouping;
|
||||||
import org.lucares.performance.db.PerformanceDb;
|
import org.lucares.performance.db.PerformanceDb;
|
||||||
@@ -47,10 +50,14 @@ public class Plotter {
|
|||||||
return outputDir;
|
return outputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File plot(final String query, final int height, final int width, final String groupBy)
|
public File plot(final PlotSettings plotSettings) throws InternalPlottingException {
|
||||||
throws InternalPlottingException {
|
|
||||||
try {
|
try {
|
||||||
final Collection<DataSeries> dataSeries = new ArrayList<>();
|
final List<DataSeries> dataSeries = new ArrayList<>();
|
||||||
|
|
||||||
|
final String query = plotSettings.getQuery();
|
||||||
|
final String groupBy = plotSettings.getGroupBy();
|
||||||
|
final int height = plotSettings.getHeight();
|
||||||
|
final int width = plotSettings.getWidth();
|
||||||
|
|
||||||
final Result result = db.get(query, groupBy);
|
final Result result = db.get(query, groupBy);
|
||||||
|
|
||||||
@@ -66,12 +73,14 @@ public class Plotter {
|
|||||||
dataSeries.add(dataSerie);
|
dataSeries.add(dataSerie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortAndLimit(dataSeries, plotSettings);
|
||||||
|
|
||||||
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
||||||
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);
|
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);
|
||||||
final GnuplotSettings settings = new GnuplotSettings(outputFile);
|
final GnuplotSettings gnuplotSettings = new GnuplotSettings(outputFile);
|
||||||
settings.setHeight(height);
|
gnuplotSettings.setHeight(height);
|
||||||
settings.setWidth(width);
|
gnuplotSettings.setWidth(width);
|
||||||
gnuplot.plot(settings, dataSeries);
|
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||||
return outputFile;
|
return outputFile;
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
@@ -81,6 +90,29 @@ public class Plotter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sortAndLimit(final List<DataSeries> dataSeries, final PlotSettings plotSettings) {
|
||||||
|
|
||||||
|
final Limit limitBy = plotSettings.getLimitBy();
|
||||||
|
if (limitBy != Limit.NO_LIMIT) {
|
||||||
|
|
||||||
|
dataSeries.sort(getDataSeriesComparator(limitBy));
|
||||||
|
|
||||||
|
while (dataSeries.size() > plotSettings.getLimit()) {
|
||||||
|
dataSeries.remove(plotSettings.getLimit());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Comparator<? super DataSeries> getDataSeriesComparator(final Limit limitBy) {
|
||||||
|
|
||||||
|
if (limitBy == Limit.MOST_VALUES) {
|
||||||
|
return DataSeries.BY_VALUES.reversed();
|
||||||
|
}
|
||||||
|
|
||||||
|
return DataSeries.BY_VALUES;
|
||||||
|
}
|
||||||
|
|
||||||
private String title(final Tags tags, final int values) {
|
private String title(final Tags tags, final int values) {
|
||||||
|
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
@@ -109,7 +141,15 @@ public class Plotter {
|
|||||||
|
|
||||||
try (PerformanceDb db = new PerformanceDb(dataDirectory)) {
|
try (PerformanceDb db = new PerformanceDb(dataDirectory)) {
|
||||||
final Plotter plotter = new Plotter(db, tmpBaseDir, outputDirectory);
|
final Plotter plotter = new Plotter(db, tmpBaseDir, outputDirectory);
|
||||||
final File image = plotter.plot(query, 1600, 1200, Grouping.NO_GROUPING);
|
// 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);
|
||||||
System.out.println("plotted image: " + image);
|
System.out.println("plotted image: " + image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.lucares.ludb.Proposal;
|
import org.lucares.ludb.Proposal;
|
||||||
|
import org.lucares.pdb.plot.api.PlotSettings;
|
||||||
import org.lucares.pdbui.domain.AutocompleteProposal;
|
import org.lucares.pdbui.domain.AutocompleteProposal;
|
||||||
import org.lucares.pdbui.domain.AutocompleteProposalByValue;
|
import org.lucares.pdbui.domain.AutocompleteProposalByValue;
|
||||||
import org.lucares.pdbui.domain.AutocompleteResponse;
|
import org.lucares.pdbui.domain.AutocompleteResponse;
|
||||||
@@ -46,12 +47,10 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
PlotResponse createPlot(@RequestBody final PlotRequest request) {
|
PlotResponse createPlot(@RequestBody final PlotRequest request) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String query = request.getQuery();
|
|
||||||
final int height = request.getHeight();
|
|
||||||
final int width = request.getWidth();
|
|
||||||
|
|
||||||
System.out.println(query);
|
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||||
final File image = plotter.plot(query, height, width, request.getGroupBy());
|
|
||||||
|
final File image = plotter.plot(plotSettings);
|
||||||
|
|
||||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||||
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImagePath.toString());
|
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImagePath.toString());
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
|
import org.lucares.pdb.plot.api.Limit;
|
||||||
|
import org.lucares.pdb.plot.api.PlotSettings;
|
||||||
|
import org.lucares.pdbui.domain.LimitBy;
|
||||||
|
import org.lucares.pdbui.domain.PlotRequest;
|
||||||
|
|
||||||
|
class PlotSettingsTransformer {
|
||||||
|
static PlotSettings toSettings(final PlotRequest request) {
|
||||||
|
|
||||||
|
final PlotSettings result = new PlotSettings();
|
||||||
|
|
||||||
|
result.setQuery(request.getQuery());
|
||||||
|
result.setGroupBy(request.getGroupBy());
|
||||||
|
result.setHeight(request.getHeight());
|
||||||
|
result.setWidth(request.getWidth());
|
||||||
|
result.setLimit(request.getLimit());
|
||||||
|
result.setLimitBy(toLimit(request.getLimitBy()));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Limit toLimit(final LimitBy limitBy) {
|
||||||
|
switch (limitBy) {
|
||||||
|
case NO_LIMIT:
|
||||||
|
return Limit.NO_LIMIT;
|
||||||
|
case FEWEST_VALUES:
|
||||||
|
return Limit.FEWEST_VALUES;
|
||||||
|
case MOST_VALUES:
|
||||||
|
return Limit.MOST_VALUES;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("unhandled enum: " + limitBy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.lucares.pdbui.domain;
|
||||||
|
|
||||||
|
public enum LimitBy {
|
||||||
|
NO_LIMIT, MOST_VALUES, FEWEST_VALUES
|
||||||
|
}
|
||||||
@@ -9,6 +9,10 @@ public class PlotRequest {
|
|||||||
|
|
||||||
private String groupBy;
|
private String groupBy;
|
||||||
|
|
||||||
|
private LimitBy limitBy = LimitBy.NO_LIMIT;
|
||||||
|
|
||||||
|
private int limit = Integer.MAX_VALUE;
|
||||||
|
|
||||||
public String getQuery() {
|
public String getQuery() {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
@@ -45,4 +49,20 @@ public class PlotRequest {
|
|||||||
public void setGroupBy(final String groupBy) {
|
public void setGroupBy(final String groupBy) {
|
||||||
this.groupBy = groupBy;
|
this.groupBy = groupBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LimitBy getLimitBy() {
|
||||||
|
return limitBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLimitBy(final LimitBy limitBy) {
|
||||||
|
this.limitBy = limitBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLimit(final int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
content: "\f1c5"
|
content: "\f1c5"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fa-area-chart:before {
|
||||||
|
content: "\f1fe"
|
||||||
|
}
|
||||||
|
|
||||||
.fa-icons:before {
|
.fa-icons:before {
|
||||||
content: "\f002";
|
content: "\f002";
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,15 @@
|
|||||||
data-autocomplete-empty-message="nothing found" />
|
data-autocomplete-empty-message="nothing found" />
|
||||||
</div>
|
</div>
|
||||||
<label for="search-group-by">Group By:</label> <select id="search-group-by"></select>
|
<label for="search-group-by">Group By:</label> <select id="search-group-by"></select>
|
||||||
<button id="search-submit"><i class="fa fa-file-image-o"> Plot</i></button>
|
|
||||||
|
<label for="search-limit-by">Limit By:</label>
|
||||||
|
<select id="search-limit-by">
|
||||||
|
<option value="NO_LIMIT" selected="selected">no limit</option>
|
||||||
|
<option value="MOST_VALUES">most values</option>
|
||||||
|
<option value="FEWEST_VALUES">fewest values</option>
|
||||||
|
</select>
|
||||||
|
<input type="number" id="search-limit-value" name="search-limit-value" min="1" max="1000000" value="10" style="display: none;"/>
|
||||||
|
<button id="search-submit"><i class="fa fa-area-chart"> Plot</i></button>
|
||||||
</div>
|
</div>
|
||||||
<div id="result-view">
|
<div id="result-view">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
renderFields();
|
renderFields();
|
||||||
|
|
||||||
|
$('#search-limit-by').change(function () {
|
||||||
|
var optionSelected = $(this).find("option:selected");
|
||||||
|
var valueSelected = optionSelected.val();
|
||||||
|
console.log(valueSelected);
|
||||||
|
if (valueSelected == "NO_LIMIT"){
|
||||||
|
$('#search-limit-value').hide();
|
||||||
|
}else{
|
||||||
|
$('#search-limit-value').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
AutoComplete({
|
AutoComplete({
|
||||||
HttpMethod: "GET",
|
HttpMethod: "GET",
|
||||||
Delay: 300,
|
Delay: 300,
|
||||||
@@ -69,9 +80,12 @@ function plot(event){
|
|||||||
showLoadingIcon();
|
showLoadingIcon();
|
||||||
var request = {};
|
var request = {};
|
||||||
request['query'] = $('#search-input').val();
|
request['query'] = $('#search-input').val();
|
||||||
request['height'] = $('#result-view').height()-10;
|
request['height'] = $('#result-view').height()-15;
|
||||||
request['width'] = $('#result-view').width()-10;
|
request['width'] = $('#result-view').width()-15;
|
||||||
request['groupBy'] = $('#search-group-by').val();
|
request['groupBy'] = $('#search-group-by').val();
|
||||||
|
request['limitBy'] = $('#search-limit-by').val();
|
||||||
|
request['limit'] = parseInt($('#search-limit-value').val());
|
||||||
|
|
||||||
|
|
||||||
var success = function(response){
|
var success = function(response){
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user