Takes a LabNation export, and finds transitions. The file can be loaded in D3, for visualization
#!/usr/bin/env ruby -w | |
require 'csv' | |
file = ARGV[0] | |
out = file.split('.').join('-compressed.') | |
unless file | |
puts "Usage: compress [filename]" | |
exit(-1) | |
end | |
CSV.open(out, 'w') do |csv| | |
index = 0 | |
sample_period = 0 | |
last = 0 | |
high = 12 | |
low = 0 | |
threshold = (high - low) / 2 | |
CSV.foreach(file, headers: true) do |line| | |
val = line['ChannelA_Acq00000'].to_f > threshold ? high : low | |
if index == 0 | |
sample_period = line['SamplePeriodInSeconds'] | |
csv << [ 0, val ] | |
last = val | |
elsif val != last | |
ts = sample_period * index | |
csv << [ ts, last ] | |
csv << [ ts, val ] | |
last = val | |
end | |
index += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment