Skip to content

Instantly share code, notes, and snippets.

@nybblr
Created April 19, 2013 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nybblr/5421472 to your computer and use it in GitHub Desktop.
Save nybblr/5421472 to your computer and use it in GitHub Desktop.
require 'date'
require 'yaml'
data = []
File.open "albert.rec" do |f|
f.each_slice(2) do |slice|
# key = items.delete_at(0).downcase
reads = slice.map do |line|
items = line.chomp.split(/\s+/)
time = items[1].to_i + items[2].to_i / 1E6
time = Time.at(time).to_datetime
items = items[3..-1]
{ :time => time, :items => items }
end
pos = reads.first
laser = reads.last
pos[:items] = pos[:items].map(&:to_f)
laser[:items] = laser[:items][3..-1].map(&:to_f)
data << { :pos => pos, :laser => laser }
end
end
# puts data.to_s
File.write "albert.yml", data.to_yaml
puts data.map {|d| d[:pos][:items].to_s}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment