Skip to content

Instantly share code, notes, and snippets.

@rbino
Last active Mar 23, 2018
Embed
What would you like to do?
Complex ExLTTB example
# Downsample a list of data of arbitrary shape
input_samples =
for x <- 1..1000 do
%{nested: %{timestamp: x},
data: :random.uniform() * 100,
untouched_other_key: :random.uniform() * 3
}
end
sample_to_x_fun = fn sample -> sample[:nested][:timestamp] end
sample_to_y_fun = fn sample -> sample[:data] end
xy_to_sample_fun = fn x, y -> %{nested: %{timestamp: x}, data: y} end
# Output samples will contain all the original fields
output_samples =
ExLTTB.downsample_to(
input_samples,
50,
sample_to_x_fun: sample_to_x_fun,
sample_to_y_fun: sample_to_y_fun,
xy_to_sample_fun: xy_to_sample_fun
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment