Created
January 16, 2017 21:23
-
-
Save madpilot/c894e2096a7f7ea8b31060cb3bc72ebe to your computer and use it in GitHub Desktop.
Takes a LabNation export, and finds transitions. The file can be loaded in D3, for visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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