use of org.locationtech.geowave.core.index.dimension.bin.BinRange in project geowave by locationtech.
the class TemporalBinningStrategy method getNormalizedRanges.
private BinRange[] getNormalizedRanges(final long min, final long max) {
final Calendar startEpoch = Calendar.getInstance(TimeZone.getTimeZone(timezone));
final long binSizeMillis = getBinSizeMillis();
// initialize the epoch to the range min and then reset appropriate
// values to 0 based on the units
startEpoch.setTimeInMillis(min);
setToEpoch(startEpoch);
// now make sure all bin definitions between the start and end bins
// are covered
final long startEpochMillis = startEpoch.getTimeInMillis();
long epochIterator = startEpochMillis;
final List<BinRange> bins = new ArrayList<>();
// track this, so that we can easily declare a range to be the full
// extent and use the information to perform a more efficient scan
boolean firstBin = (min != startEpochMillis);
boolean lastBin = false;
do {
// because not every year has 366 days, and not every month has 31
// days we need to reset next epoch to the actual epoch
final Calendar nextEpochCal = Calendar.getInstance(TimeZone.getTimeZone(timezone));
// set it to a value in the middle of the bin just to be sure (for
// example if the bin size does not get to the next epoch as is
// the case when units are days and the timezone accounts for
// daylight savings time)
nextEpochCal.setTimeInMillis(epochIterator + (long) (binSizeMillis * 1.5));
setToEpoch(nextEpochCal);
final long nextEpoch = nextEpochCal.getTimeInMillis();
final long maxOfBin = nextEpoch - 1;
final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timezone));
cal.setTimeInMillis(epochIterator);
long startMillis, endMillis;
boolean fullExtent;
if (max <= maxOfBin) {
lastBin = true;
endMillis = max;
// its questionable whether we use
fullExtent = (max == maxOfBin);
} else {
endMillis = maxOfBin;
fullExtent = !firstBin;
}
if (firstBin) {
startMillis = min;
firstBin = false;
} else {
startMillis = epochIterator;
}
// we have the millis for range, but to normalize for this bin we
// need to subtract the epoch of the bin
bins.add(new BinRange(getBinId(cal), startMillis - epochIterator, endMillis - epochIterator, fullExtent));
epochIterator = nextEpoch;
// iterate until we reach our end epoch
} while (!lastBin);
return bins.toArray(new BinRange[bins.size()]);
}
use of org.locationtech.geowave.core.index.dimension.bin.BinRange in project geowave by locationtech.
the class TemporalBinningStrategyTest method testFeb28ToMarch1NonLeapYear.
@Test
public void testFeb28ToMarch1NonLeapYear() {
final long time = 47920164930285667L;
final Calendar startCal = Calendar.getInstance();
startCal.setTimeInMillis(time);
startCal.set(Calendar.MONTH, 1);
startCal.set(Calendar.YEAR, 2015);
startCal.set(Calendar.DAY_OF_MONTH, 28);
final Calendar endCal = Calendar.getInstance();
endCal.setTimeInMillis(time);
endCal.set(Calendar.MONTH, 2);
endCal.set(Calendar.YEAR, 2015);
endCal.set(Calendar.DAY_OF_MONTH, 1);
// test the day boundaries first - going from feb28 to march 1 should
// give 2 bins
TemporalBinningStrategy binStrategy = new TemporalBinningStrategy(Unit.DAY);
BinRange[] ranges = binStrategy.getNormalizedRanges(new NumericRange(startCal.getTimeInMillis(), endCal.getTimeInMillis()));
Assert.assertEquals(2, ranges.length);
// now test the month boundaries - adding a day to feb28 for the end
// time should give 2 bins
binStrategy = new TemporalBinningStrategy(Unit.MONTH);
ranges = binStrategy.getNormalizedRanges(new NumericRange(startCal.getTimeInMillis(), startCal.getTimeInMillis() + (TemporalBinningStrategy.MILLIS_PER_DAY)));
Assert.assertEquals(2, ranges.length);
}
use of org.locationtech.geowave.core.index.dimension.bin.BinRange in project geowave by locationtech.
the class TemporalBinningStrategyTest method testFeb28ToMarch1LeapYear.
@Test
public void testFeb28ToMarch1LeapYear() {
final long time = 29374659120374656L;
final Calendar startCal = Calendar.getInstance();
startCal.setTimeInMillis(time);
startCal.set(Calendar.MONTH, 1);
startCal.set(Calendar.YEAR, 2016);
startCal.set(Calendar.DAY_OF_MONTH, 28);
final Calendar endCal = Calendar.getInstance();
endCal.setTimeInMillis(time);
endCal.set(Calendar.MONTH, 2);
endCal.set(Calendar.YEAR, 2016);
endCal.set(Calendar.DAY_OF_MONTH, 1);
// test the day boundaries first - going from feb28 to march 1 should
// give 3 bins
TemporalBinningStrategy binStrategy = new TemporalBinningStrategy(Unit.DAY);
BinRange[] ranges = binStrategy.getNormalizedRanges(new NumericRange(startCal.getTimeInMillis(), endCal.getTimeInMillis()));
Assert.assertEquals(3, ranges.length);
// now test the month boundaries - adding a day to feb28 for the end
// time should give 1 bin, adding 2 days should give 2 bins
binStrategy = new TemporalBinningStrategy(Unit.MONTH);
ranges = binStrategy.getNormalizedRanges(new NumericRange(startCal.getTimeInMillis(), startCal.getTimeInMillis() + (TemporalBinningStrategy.MILLIS_PER_DAY)));
Assert.assertEquals(1, ranges.length);
// add 2 days and now we should end up with 2 bins
ranges = binStrategy.getNormalizedRanges(new NumericRange(startCal.getTimeInMillis(), startCal.getTimeInMillis() + (TemporalBinningStrategy.MILLIS_PER_DAY * 2)));
Assert.assertEquals(2, ranges.length);
}
use of org.locationtech.geowave.core.index.dimension.bin.BinRange in project geowave by locationtech.
the class TemporalBinningStrategyTest method testNonLeapYear.
@Test
public void testNonLeapYear() {
final long time = 75470203439504394L;
final TemporalBinningStrategy binStrategy = new TemporalBinningStrategy(Unit.YEAR);
final Calendar startCal = Calendar.getInstance();
startCal.setTimeInMillis(time);
startCal.set(Calendar.YEAR, 2015);
binStrategy.setToEpoch(startCal);
// if we add 365 days to this we should get 2 year bins
final BinRange[] ranges = binStrategy.getNormalizedRanges(new NumericRange(startCal.getTimeInMillis(), startCal.getTimeInMillis() + (TemporalBinningStrategy.MILLIS_PER_DAY * 365)));
Assert.assertEquals(2, ranges.length);
}
use of org.locationtech.geowave.core.index.dimension.bin.BinRange in project geowave by locationtech.
the class TemporalBinningStrategyTest method testStartAndEndEqual.
@Test
public void testStartAndEndEqual() {
final long time = 123987564019283L;
final TemporalBinningStrategy binStrategy = new TemporalBinningStrategy(Unit.YEAR);
final BinRange[] ranges = binStrategy.getNormalizedRanges(new NumericRange(time, time));
Assert.assertEquals(1, ranges.length);
// both the min and max of the range should be equal
Assert.assertTrue(ranges[0].getNormalizedMin() == ranges[0].getNormalizedMax());
}
Aggregations