show better error message, when no data points are found

This commit is contained in:
2017-03-26 17:30:50 +02:00
parent ee00ecb4b5
commit 364997e611
5 changed files with 40 additions and 9 deletions

View File

@@ -4,6 +4,10 @@ public class InternalPlottingException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public InternalPlottingException() {
super();
}
public InternalPlottingException(final String message, final Throwable cause) { public InternalPlottingException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@@ -0,0 +1,10 @@
package org.lucares.recommind.logs;
public class NoDataPointsException extends InternalPlottingException {
private static final long serialVersionUID = 1054594230615520105L;
public NoDataPointsException() {
super();
}
}

View File

@@ -10,7 +10,9 @@ 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.nio.file.Paths;
import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
@@ -74,8 +76,8 @@ public class Plotter {
final Result result = db.get(query, groupBy); final Result result = db.get(query, groupBy);
OffsetDateTime maxDate = OffsetDateTime.MIN; OffsetDateTime maxDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC);
OffsetDateTime minDate = OffsetDateTime.MAX; OffsetDateTime minDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
for (final GroupResult groupResult : result.getGroups()) { for (final GroupResult groupResult : result.getGroups()) {
@@ -94,6 +96,10 @@ public class Plotter {
} }
} }
if (dataSeries.isEmpty()) {
throw new NoDataPointsException();
}
sortAndLimit(dataSeries, plotSettings); sortAndLimit(dataSeries, plotSettings);
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile()); final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());

View File

@@ -16,6 +16,7 @@ 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.InternalPlottingException; import org.lucares.recommind.logs.InternalPlottingException;
import org.lucares.recommind.logs.NoDataPointsException;
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;
@@ -53,6 +54,7 @@ public class PdbController implements HardcodedValues, CollectionUtils {
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request); final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
try {
final File image = plotter.plot(plotSettings); final File image = plotter.plot(plotSettings);
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath()); 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; 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(imageUrl);
} catch (final NoDataPointsException e) {
throw new NotFoundException(e);
}
} }
@RequestMapping(path = "/autocomplete", // @RequestMapping(path = "/autocomplete", //

View File

@@ -99,7 +99,13 @@ function plot(event){
$('#result-view').html('<img src=\"'+response.imageUrls+'" />'); $('#result-view').html('<img src=\"'+response.imageUrls+'" />');
}; };
var error = function(e) { var error = function(e) {
if (e.status == 404){
$('#result-view').text("No data points found.");
}
else{
$('#result-view').text("FAILED: " + JSON.stringify(e)); $('#result-view').text("FAILED: " + JSON.stringify(e));
}
}; };