pond icon indicating copy to clipboard operation
pond copied to clipboard

Resampling

Open pjm17971 opened this issue 10 years ago • 0 comments

The timeseries charts code really doesn't like having 5000 points it has to render over and over (during pan and zoom). Since don't display a 5000 pixel wide chart, we should down sample the data before it is rendered. There are several possibilities here:

A basic resample(n, avg) would divide the series into n buckets, where n might be approximately 1:1 with the resolution of the screen. We'd then apply one of the the functions to that data, like avg or max.

Another approach is to use the processing code to do a rollup("5m", avg) of the data. This would bin samples in the timeseries into time based buckets such as 5 min.

A more sophisticated approach is for each bucket calculate a representative point to use instead, such that the resulting path is visually the most similar to the original path. An algorithm that attempts to do this is called "largest triangle three buckets". Here's the paper: http://skemman.is/stream/get/1946/15343/37285/3/SS_MSthesis.pdf

tl;dr: You can just read the algorithm on page 21 ("largest triangle three buckets"). It was the one people liked the most.

Too hard to go look up page 21? here's the jist: You are dividing the samples into n buckets. For each bucket you pick a point to represent that bucket. Buckets to consider in making this decision are A (the previous bucket), B (the next bucket) and C (the current bucket). You'll need the picked point from the previous* bucket a, the average point from the next* bucket b and the samples in the current bucket C. You loop over the samples in the current bucket, each sample c, and calculate the triangle area contained within a, b and c. Largest triangle wins the prize of having its c being selected as the representative point for the current bucket. Move onto the next bucket. Repeat.

  • for the edges, basically use the first and last points. They use an extra bucket at the beginning with just the first point in it, same at the end.

pjm17971 avatar Dec 04 '15 14:12 pjm17971