@Test public void testDownsampleStartCalculation() throws Exception { long queryStart = System.currentTimeMillis() - 86400000; long period = 60000; long keyTimestamp = queryStart + (86400000 / 2 + 3256); Set<Long> expectedStartTimes = new HashSet<>(); for (long i = queryStart; i < queryStart + 86400000; i += period) { expectedStartTimes.add(i); } assertEquals(1440, expectedStartTimes.size()); long sampleStart = keyTimestamp - ((keyTimestamp - queryStart) % period); assertTrue(expectedStartTimes.contains(sampleStart)); }
@Override public void add(long ts, double value) { if (ts < start) { throw new IllegalArgumentException("timestamp is out of range"); } long sampleStart = ts - ((ts - start) % period); AggregatedValue val = buckets.get(sampleStart); if (null == val) { buckets.put(sampleStart, val = new AggregatedValue()); } val.setValue(aggregator.aggregate(val.getValue(), val.getCount(), value)); val.incrementCount(); }
Downsample extends Aggregation implements Iterable<Sample>, Serializable { @Override public void add(long ts, double value) { if (ts < start) { throw new IllegalArgumentException("timestamp is out of range"); } long sampleStart = ts - ((ts - start) % period); AggregatedValue val = buckets.get(sampleStart); if (null == val) { buckets.put(sampleStart, val = new AggregatedValue()); } val.setValue(aggregator.aggregate(val.getValue(), val.getCount(), value)); val.incrementCount(); } }
Downsample extends Aggregation implements Iterable<Sample>, Serializable { @Override public void add(long ts, double value) { if (ts < start) { throw new IllegalArgumentException("timestamp is out of range"); } long sampleStart = ts - ((ts - start) % period); AggregatedValue val = buckets.get(sampleStart); if (null == val) { buckets.put(sampleStart, val = new AggregatedValue()); } val.setValue(aggregator.aggregate(val.getValue(), val.getCount(), value)); val.incrementCount(); } Downsample(long start, long end, long period, Aggregator agg); }
Downsample extends Aggregation implements Iterable<Sample>, Serializable { @Override public void add(long ts, double value) { if (ts < start) { throw new IllegalArgumentException("timestamp is out of range"); } long sampleStart = ts - ((ts - start) % period); AggregatedValue val = buckets.get(sampleStart); if (null == val) { buckets.put(sampleStart, val = new AggregatedValue()); } val.setValue(aggregator.aggregate(val.getValue(), val.getCount(), value)); val.incrementCount(); } Downsample(long start, long end, long period, Aggregator agg); @Override void add(long ts, double value); @Override String toString(); static Downsample combineDownsample(Collection<Downsample> samples, RateOption rateOption); }
Downsample extends Aggregation implements Iterable<Sample>, Serializable { @Override public void add(long ts, double value) { if (ts < start) { throw new IllegalArgumentException("timestamp is out of range"); } long sampleStart = ts - ((ts - start) % period); AggregatedValue val = buckets.get(sampleStart); if (null == val) { buckets.put(sampleStart, val = new AggregatedValue()); } val.setValue(aggregator.aggregate(val.getValue(), val.getCount(), value)); val.incrementCount(); } Downsample(long start, long end, long period, Aggregator agg); @Override void add(long ts, double value); @Override String toString(); static Downsample combineDownsample(Collection<Downsample> samples, RateOption rateOption);  }