replace startDate + dateRange with start and end date
The new datetimepicker can be used to specify date ranges. We no longer need to define a start date and a range. This simplifies the code for zooming and shifting considerably.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public class DateTimeRange {
|
||||
private final OffsetDateTime start;
|
||||
private final OffsetDateTime end;
|
||||
|
||||
public DateTimeRange(final OffsetDateTime start, final OffsetDateTime end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public OffsetDateTime getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public OffsetDateTime getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return start + "-" + end;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public class PlotSettings {
|
||||
|
||||
@@ -30,9 +29,7 @@ public class PlotSettings {
|
||||
|
||||
private int limit;
|
||||
|
||||
private String dateFrom;
|
||||
|
||||
private String dateRange;
|
||||
private String dateRangeAsString;
|
||||
|
||||
private AxisScale yAxisScale;
|
||||
|
||||
@@ -110,68 +107,24 @@ public class PlotSettings {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public String getDateFrom() {
|
||||
return dateFrom;
|
||||
}
|
||||
|
||||
public void setDateFrom(final String dateFrom) {
|
||||
this.dateFrom = dateFrom;
|
||||
}
|
||||
|
||||
public String getDateRange() {
|
||||
return dateRange;
|
||||
return dateRangeAsString;
|
||||
}
|
||||
|
||||
public void setDateRange(final String dateRange) {
|
||||
this.dateRange = dateRange;
|
||||
public void setDateRange(final String dateRangeAsString) {
|
||||
this.dateRangeAsString = dateRangeAsString;
|
||||
}
|
||||
|
||||
public OffsetDateTime dateFrom() {
|
||||
public DateTimeRange dateRange() {
|
||||
|
||||
if (StringUtils.isEmpty(dateFrom)) {
|
||||
final String[] startEnd = dateRangeAsString.split(Pattern.quote(" - "));
|
||||
Preconditions.checkArgument(startEnd.length == 2, "invalid date range");
|
||||
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC);
|
||||
} else {
|
||||
return LocalDateTime.parse(dateFrom, DATE_FORMAT).atOffset(ZoneOffset.UTC);
|
||||
}
|
||||
}
|
||||
final OffsetDateTime startDate = LocalDateTime.parse(startEnd[0], DATE_FORMAT).atOffset(ZoneOffset.UTC);
|
||||
final OffsetDateTime endDate = LocalDateTime.parse(startEnd[1], DATE_FORMAT).atOffset(ZoneOffset.UTC);
|
||||
|
||||
public OffsetDateTime dateTo() {
|
||||
return new DateTimeRange(startDate, endDate);
|
||||
|
||||
if (StringUtils.isEmpty(dateRange)) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
|
||||
} else {
|
||||
final int period = Integer.parseInt(dateRange.split(" ")[0]);
|
||||
final ChronoUnit unit = toChronoUnit(dateRange.split(" ")[1]);
|
||||
|
||||
return dateFrom().plus(period, unit);
|
||||
}
|
||||
}
|
||||
|
||||
private ChronoUnit toChronoUnit(final String string) {
|
||||
|
||||
switch (string) {
|
||||
case "second":
|
||||
case "seconds":
|
||||
return ChronoUnit.SECONDS;
|
||||
case "minute":
|
||||
case "minutes":
|
||||
return ChronoUnit.MINUTES;
|
||||
case "hour":
|
||||
case "hours":
|
||||
return ChronoUnit.HOURS;
|
||||
case "day":
|
||||
case "days":
|
||||
return ChronoUnit.DAYS;
|
||||
case "week":
|
||||
case "weeks":
|
||||
return ChronoUnit.WEEKS;
|
||||
case "month":
|
||||
case "months":
|
||||
return ChronoUnit.MONTHS;
|
||||
default:
|
||||
throw new IllegalArgumentException(string + " is an unknown chrono unit");
|
||||
}
|
||||
}
|
||||
|
||||
public void setYAxisScale(final AxisScale axisScale) {
|
||||
@@ -186,7 +139,7 @@ public class PlotSettings {
|
||||
public String toString() {
|
||||
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", thumbnailMaxWidth="
|
||||
+ thumbnailMaxWidth + ", thumbnailMaxHeight=" + thumbnailMaxHeight + ", groupBy=" + groupBy
|
||||
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateFrom=" + dateFrom + ", dateRange=" + dateRange
|
||||
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateRangeAsString=" + dateRangeAsString
|
||||
+ ", yAxisScale=" + yAxisScale + ", aggregate=" + aggregate + ", yRangeMin=" + yRangeMin
|
||||
+ ", yRangeMax=" + yRangeMax + ", yRangeUnit=" + yRangeUnit + ", keyOutside=" + keyOutside
|
||||
+ ", generateThumbnail=" + generateThumbnail + "]";
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.lucares.pdb.api.GroupResult;
|
||||
import org.lucares.pdb.api.Result;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.plot.api.CustomAggregator;
|
||||
import org.lucares.pdb.plot.api.DateTimeRange;
|
||||
import org.lucares.pdb.plot.api.Limit;
|
||||
import org.lucares.pdb.plot.api.PlotSettings;
|
||||
import org.lucares.pdb.plot.api.TimeRangeUnitInternal;
|
||||
@@ -78,8 +79,9 @@ public class ScatterPlot {
|
||||
final List<String> groupBy = plotSettings.getGroupBy();
|
||||
final int height = plotSettings.getHeight();
|
||||
final int width = plotSettings.getWidth();
|
||||
final OffsetDateTime dateFrom = plotSettings.dateFrom();
|
||||
final OffsetDateTime dateTo = plotSettings.dateTo();
|
||||
final DateTimeRange dateRange = plotSettings.dateRange();
|
||||
final OffsetDateTime dateFrom = dateRange.getStart();
|
||||
final OffsetDateTime dateTo = dateRange.getEnd();
|
||||
|
||||
final Result result = db.get(query, groupBy);
|
||||
|
||||
@@ -117,7 +119,7 @@ public class ScatterPlot {
|
||||
final GnuplotSettings gnuplotSettings = new GnuplotSettings(outputFile);
|
||||
gnuplotSettings.setHeight(height);
|
||||
gnuplotSettings.setWidth(width);
|
||||
defineXAxis(gnuplotSettings, plotSettings.dateFrom(), plotSettings.dateTo());
|
||||
defineXAxis(gnuplotSettings, plotSettings.dateRange());
|
||||
|
||||
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
|
||||
gnuplotSettings.setAggregate(plotSettings.getAggregate());
|
||||
@@ -134,7 +136,7 @@ public class ScatterPlot {
|
||||
final GnuplotSettings gnuplotSettings = new GnuplotSettings(thumbnail);
|
||||
gnuplotSettings.setHeight(plotSettings.getThumbnailMaxHeight());
|
||||
gnuplotSettings.setWidth(plotSettings.getThumbnailMaxWidth());
|
||||
defineXAxis(gnuplotSettings, plotSettings.dateFrom(), plotSettings.dateTo());
|
||||
defineXAxis(gnuplotSettings, plotSettings.dateRange());
|
||||
|
||||
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
|
||||
gnuplotSettings.setAggregate(plotSettings.getAggregate());
|
||||
@@ -169,9 +171,10 @@ public class ScatterPlot {
|
||||
}
|
||||
}
|
||||
|
||||
private void defineXAxis(final GnuplotSettings gnuplotSettings, final OffsetDateTime minDate,
|
||||
final OffsetDateTime maxDate) {
|
||||
private void defineXAxis(final GnuplotSettings gnuplotSettings, final DateTimeRange dateTimeRange) {
|
||||
|
||||
final OffsetDateTime minDate = dateTimeRange.getStart();
|
||||
final OffsetDateTime maxDate = dateTimeRange.getEnd();
|
||||
String formatX;
|
||||
int rotateX;
|
||||
String formattedMinDate;
|
||||
|
||||
Reference in New Issue
Block a user