Skip to content

Instantly share code, notes, and snippets.

@etaque
Created September 25, 2013 07:53
Show Gist options
  • Save etaque/6696417 to your computer and use it in GitHub Desktop.
Save etaque/6696417 to your computer and use it in GitHub Desktop.
require 'date'
require 'nokogiri'
require 'gnuplot'
class Point
attr_accessor :lon, :lat, :speed, :time
def initialize(lon, lat, speed, time)
@lon = lon
@lat = lat
@speed = speed
@time = time
end
end
doc = Nokogiri::XML(open(ARGV.first))
raw_points = doc.xpath('//xmlns:trkpt').map{|trk|
Point.new(
trk['lon'].to_s.to_f,
trk['lat'].to_s.to_f,
trk.at_xpath('.//mytracks:speed').content.to_f * 0.54,
DateTime.parse(trk.at_css('time').content)
)
}
points = raw_points.select{|p| p.speed < 50 && p.speed > 0 }
speeds = points.map(&:speed)
times = points.map(&:time).map(&:to_s)
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.terminal "png"
plot.output "./speeds.png"
plot.ylabel "knots"
plot.yrange "[0:10]"
plot.xrange "[0:4600]"
plot.data << Gnuplot::DataSet.new([speeds]) do |ds|
ds.with = "lines"
ds.smooth = "bezier"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment