BeamConsole.Series.Downsampler (beam_console v0.5.3)

Copy Markdown View Source

Deterministically reduces numeric chart points while retaining endpoints and spikes.

Points are maps containing :sampled_at_ms and :value. Segment metadata is preserved, allowing the browser renderer to keep recording gaps disconnected.

Summary

Functions

Applies Largest-Triangle-Three-Buckets downsampling to an ordered series.

Types

point()

@type point() :: %{
  :sampled_at_ms => integer(),
  :value => number(),
  optional(:segment) => non_neg_integer() | String.t()
}

Functions

downsample(points, limit)

@spec downsample([point()], pos_integer()) :: [point()]

Applies Largest-Triangle-Three-Buckets downsampling to an ordered series.

Examples

iex> points = for value <- 1..10, do: %{sampled_at_ms: value, value: value}
iex> result = BeamConsole.Series.Downsampler.downsample(points, 4)
iex> {length(result), hd(result).value, List.last(result).value}
{4, 1, 10}