Skip to content

Instantly share code, notes, and snippets.

@matsumotory
Last active May 28, 2017 04:01
Show Gist options
  • Save matsumotory/c3d75d96dbc294424aa9af0c32d12c8c to your computer and use it in GitHub Desktop.
Save matsumotory/c3d75d96dbc294424aa9af0c32d12c8c to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Sat May 27 17:56:34 2017 1495875394 0 773 773 772
# Sat May 27 17:56:39 2017 1495875399 0 773 773 765
# Sat May 27 17:56:18 2017 1495875378 0 773 773 771
# Sat May 27 17:56:19 2017 1495875379 0 774 774 771
# Sat May 27 17:56:19 2017 1495875379 0 774 774 770
# Sat May 27 17:56:19 2017 1495875379 0 774 774 772
smooth_data = []
$stdin.each_line do |l|
new = l.split("\t")
next if new[0] == "starttime"
old = smooth_data[-1]
if old && old[0] == new[0]
smooth_data[-1] = [old[0],
old[1],
(old[2].to_i + new[2].to_i) / 2,
(old[3].to_i + new[3].to_i) / 2,
(old[4].to_i + new[4].to_i) / 2,
(old[5].to_i + new[5].to_i) / 2]
else
smooth_data << [new[0],
new[1],
new[2].to_i,
new[3].to_i,
new[4].to_i,
new[5].to_i]
end
end
smooth_data.each do |d|
puts "#{d[0]}\t#{d[2]}\t#{d[3]}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment