Skip to content

Instantly share code, notes, and snippets.

@rbino
Last active March 23, 2018 13:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rbino/4e40be19a553228e2230c41a561fc2b1 to your computer and use it in GitHub Desktop.
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