show better error message, when no data points are found
This commit is contained in:
@@ -4,6 +4,10 @@ public class InternalPlottingException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InternalPlottingException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InternalPlottingException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.lucares.recommind.logs;
|
||||
|
||||
public class NoDataPointsException extends InternalPlottingException {
|
||||
|
||||
private static final long serialVersionUID = 1054594230615520105L;
|
||||
|
||||
public NoDataPointsException() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,9 @@ import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
@@ -74,8 +76,8 @@ public class Plotter {
|
||||
|
||||
final Result result = db.get(query, groupBy);
|
||||
|
||||
OffsetDateTime maxDate = OffsetDateTime.MIN;
|
||||
OffsetDateTime minDate = OffsetDateTime.MAX;
|
||||
OffsetDateTime maxDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC);
|
||||
OffsetDateTime minDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
|
||||
|
||||
for (final GroupResult groupResult : result.getGroups()) {
|
||||
|
||||
@@ -94,6 +96,10 @@ public class Plotter {
|
||||
}
|
||||
}
|
||||
|
||||
if (dataSeries.isEmpty()) {
|
||||
throw new NoDataPointsException();
|
||||
}
|
||||
|
||||
sortAndLimit(dataSeries, plotSettings);
|
||||
|
||||
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.lucares.pdbui.domain.PlotRequest;
|
||||
import org.lucares.pdbui.domain.PlotResponse;
|
||||
import org.lucares.performance.db.CollectionUtils;
|
||||
import org.lucares.recommind.logs.InternalPlottingException;
|
||||
import org.lucares.recommind.logs.NoDataPointsException;
|
||||
import org.lucares.recommind.logs.Plotter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -53,6 +54,7 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
|
||||
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||
|
||||
try {
|
||||
final File image = plotter.plot(plotSettings);
|
||||
|
||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||
@@ -60,6 +62,9 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + relativeImgUrl;
|
||||
LOGGER.trace("image url: {}", imageUrl);
|
||||
return new PlotResponse(imageUrl);
|
||||
} catch (final NoDataPointsException e) {
|
||||
throw new NotFoundException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/autocomplete", //
|
||||
|
||||
@@ -99,7 +99,13 @@ function plot(event){
|
||||
$('#result-view').html('<img src=\"'+response.imageUrls+'" />');
|
||||
};
|
||||
var error = function(e) {
|
||||
|
||||
if (e.status == 404){
|
||||
$('#result-view').text("No data points found.");
|
||||
}
|
||||
else{
|
||||
$('#result-view').text("FAILED: " + JSON.stringify(e));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user