OpenTSDB/opentsdb — pull request #325 by jesse5e (2014-04-29 01:17:21+00:00)
Title: Align the start of downsampling

Aligned the start time of downsampling by the given downsampling interval
so that the same set of data points belongs to the same downsampling period
regardless of the start time of a user-requested time range.
- Made the start time of a downsampling period its representative timestamp
without computing the average of the timestamps of the data points of the
period.
- Factored downsampling code out from Span.java to its own class to make it
easier to write unit tests.
- Made the type of downsampling result double regardless of the original type
to get rid of the loop that checked the type of the raw input data points.
By using double, we could handle very small integers and very big integers
within a reasonable error margin. Some values are too small to round off.
For example, the integer average of four values (2, 2, 2, 1) is 1, which is
far from the real average of 1.75. Some values are so big that it could
cause long-integer overflow while downsampling.