Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T14:19:43.000Z (over 6 years ago)
- Last Synced: 2024-04-10T11:13:46.631Z (8 months ago)
- Topics: downsampling, elixir
- Language: Elixir
- Size: 38.1 KB
- Stars: 29
- Watchers: 5
- Forks: 3
- 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 [![hex.pm version](https://img.shields.io/hexpm/v/ex_lttb.svg)](https://hex.pm/packages/ex_lttb) [![Build Status](https://travis-ci.org/ispirata/ex_lttb.svg?branch=master)](https://travis-ci.org/ispirata/ex_lttb) [![Coverage Status](https://coveralls.io/repos/github/ispirata/ex_lttb/badge.svg)](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
```