Skip to content

Instantly share code, notes, and snippets.

@rbino
rbino / ex_lttb_stream.exs
Created Mar 23, 2018
ExLTTB.Stream example
View ex_lttb_stream.exs
input_stream =
Stream.iterate(%{x: 0, y: :random.uniform() * 100}, fn %{x: x} ->
%{x: x + 1, y: :random.uniform() * 100}
end)
# Take 20 samples output samples after downsampling by 2.3
# The 20 output samples will correspond to ~ 20 * 2.3 input samples
output_samples =
ExLTTB.Stream.downsample(input_stream, 2.3)
|> Enum.take(20)
@rbino
rbino / complex_ex_lttb.exs
Last active Mar 23, 2018
Complex ExLTTB example
View complex_ex_lttb.exs
# 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
@rbino
rbino / simple_ex_lttb.exs
Created Mar 23, 2018
Simple ExLTTB example
View simple_ex_lttb.exs
# Downsample a list of data in the default shape of %{x: x, y: y}
input_samples = for x <- 1..1000, do: %{x: x, y: :random.uniform() * 100}
# 50 output samples
output_samples = ExLTTB.downsample_to(input_samples, 50)
View keybase.md

Keybase proof

I hereby claim:

  • I am rbino on github.
  • I am rbino (https://keybase.io/rbino) on keybase.
  • I have a public key whose fingerprint is 937F 416B 9ECB 6179 6FFE 62FC 74AE CC9F 5480 C3EB

To claim this, I am signing this object: