java.lang.Object
eu.bengreen.data.utility.DownSampleImpl
All Implemented Interfaces:
DownSampler
Direct Known Subclasses:
LargestTriangleThreeBuckets, LargestTriangleThreeBucketsTime

public abstract class DownSampleImplextends Object implements DownSampler
Naive implementation of down sample with simple array input Largest-Triangle-Three-Buckets, from Sveinn Steinarsson's thesis, section 4.2..
  • Field Details

    • threshold

      protected final int threshold
      Number of data points to downsample to.
  • Constructor Details

    • DownSampleImpl

      protected DownSampleImpl(int threshold)
      Number of data points to downsample to.
      Parameters:
      threshold - number of data points to downsample to
  • Method Details

    • setDataSetLine

      protected void setDataSetLine(DownSampler.DataSet sampled, int rank, long timestamp, double value)
      Populate a single element in the downsampled data set.
      Parameters:
      sampled - the data set receiving the timestamp and value at this rank
      rank - the position within the downsampled data set to write
      timestamp - the source timestamp, in seconds since the epoch
      value - the source value retained for this rank
    • downsize

      public DownSampler.DataSet downsize(long[] timestamps, double[] values)
      Description copied from interface: DownSampler
      Downsample the given data.
      Specified by:
      downsize in interface DownSampler
      Parameters:
      timestamps - the timestamps, parallel to values
      values - the values, parallel to timestamps
      Returns:
      the downsampled data set
    • downsizeImpl

      protected abstract DownSampler.DataSet downsizeImpl(DownSampler.DataSet sampled, long[] timestamps, double[] values)
      Reduces the source series into the pre-allocated output set. Implementations pick the ranks to keep, write them one slot at a time with setDataSetLine(DownSampler.DataSet, int, long, double), and return that same set; downsize(long[], double[]) has already rejected inputs shorter than the output and mismatched array lengths.
      Parameters:
      sampled - the empty output set allocated by downsize(long[], double[]), holding exactly threshold timestamp and value slots to fill
      timestamps - the full source timestamps in seconds since the epoch, more than threshold in number
      values - the full source values, the same length as timestamps
      Returns:
      the same sampled set, with the threshold chosen ranks written into it