https://github.com/secomind/ex_lttb
An Elixir downsampling library that retains the visual characteristics of your data
https://github.com/secomind/ex_lttb
downsampling elixir
Last synced: 7 days ago
JSON representation
An Elixir downsampling library that retains the visual characteristics of your data
- Host: GitHub
- URL: https://github.com/secomind/ex_lttb
- Owner: secomind
- License: mit
- Created: 2018-03-09T11:21:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T14:19:43.000Z (about 7 years ago)
- Last Synced: 2025-04-30T00:13:04.898Z (7 days ago)
- Topics: downsampling, elixir
- Language: Elixir
- Size: 38.1 KB
- Stars: 31
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-elixir - ex_lttb - An Elixir downsampling library that retains the visual characteristics of your data. (Actors)
README
# ExLTTB [](https://hex.pm/packages/ex_lttb) [](https://travis-ci.org/ispirata/ex_lttb) [](https://coveralls.io/github/ispirata/ex_lttb)
An Elixir downsampling library that retains the visual characteristics of your data.
ExLTTB is based on [Largest-Triangle-Three-Buckets](https://skemman.is/handle/1946/15343) (LTTB) and it contains two implementation modules: `ExLTTB` implements the original algorithm using `Enum` and eager evaluation, `ExLTTB.Stream` implements a slightly modified version to cope with lazy evaluation and using `Stream`.
The data is assumed to be ordered by its x coordinate in both implementations.
## Installation
Add `ex_lttb` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ex_lttb, "~> 0.3.0"}
]
end
```## Documentation
You can read the documentation on [HexDocs](https://hexdocs.pm/ex_lttb).
## Examples
```elixir
# Downsample a list of data in the default shape of %{x: x, y: y}
input_samples = for x <- 1..100, do: %{x: x, y: :random.uniform() * 100}# 30 output samples
output_samples = ExLTTB.downsample_to(input_samples, 30)# Downsample a list of data of arbitrary shape
input_samples =
for x <- 1..100 do
%{nested: %{timebase: x},
data: :random.uniform() * 100,
untouched_other_key: :random.uniform() * 3
}
endsample_to_x_fun = fn sample -> sample[:nested][:timebase] end
sample_to_y_fun = fn sample -> sample[:data] end
xy_to_sample_fun = fn x, y -> %{nested: %{timebase: x}, data: y} endoutput_samples =
ExLTTB.downsample_to(
input_samples,
30,
sample_to_x_fun: sample_to_x_fun,
sample_to_y_fun: sample_to_y_fun,
xy_to_sample_fun: xy_to_sample_fun
)# Downsample a stream of data
input_stream =
Stream.iterate(%{x: 0, y: :random.uniform() * 100}, fn %{x: x} -> %{x: x + 1, y: :random.uniform() * 100} end)# Downsample rate of 2.3
output_samples = ExLTTB.Stream.downsample(input_stream, 2.3) |> Enum.take(20)# The options for arbitrary shaped data are the same for the streaming version
```