RSS
 

Archive for the ‘Development’ Category

Ten times faster!

11 Aug

I’ve managed to optimize the performance of my Hac4/GPS data merging script.

Optimized Version
2,33s user 0,06s system 89% cpu 2,677 total

Old merge and libxml-ruby
13,06s user 0,15s system 91% cpu 14,382 total

Old merge and rexml
26,86s user 0,21s system 96% cpu 27,987 total

And this is the track which I used for the tests. The track has 1554 trackpoints. I took this route on Saturday.

 
 

New merge algorithm

06 Aug

This should be a comment to a previous post, but it seems that code is not well formatted in comments :(

This code snippet below should lead me into the right direction for better performance in merging my cycling log data

def new_merge(gpx, hac, delta)

  #
  # adjust the 2 arrays
  # (works only if gpx starts earlier)
  #
  while gpx.first[:time] < asc.first[:time]
    gpx.shift
  end
 
  #
  # merge data
  #
  asc.each do |h|

    # next if there gps dropouts
    next if h[:time] + 2 > gpx.first[:time]
    h.merge!(gpx.shift)
    break if gpx.size == 0
  end
  0
end
 
No Comments

Posted in Ruby, geo/gps

 

Combine Hac4 Data with GPS logger data

05 Aug

If have already a script running which is merging the data of those two devices. But after using libxml I got aware of the awful performance of the merging algorithm.

d = Array.new
asc.each do |c|
  gpx.each do |e|
    f = (c[:time] + @delta.to_i) - e[:time]    
    if  f <= 2 && f >= -2
      d << {:gpx => e, :asc => c}
    end
  end
end

I created the image which will probably help me in developing a faster algorithm.

 
2 Comments

Posted in Ruby, geo/gps

 

Reading GPX with Ruby

05 Aug

Sometime back in May I wrote some utilities to manage the GPX files from my Royaltek RGM 3800. I’ve used rexml to parse the XML file. Now after I’ve read about libxml for ruby I’ve had tried this little gem and I have registered that parsing the GPX file is significantly faster.
This was the old code from May with rexml:

def parse_gpx(file)
  require 'rexml/document'
  include REXML
  a = Array.new
  doc = Document.new File.new(file)
  i = 0
  doc.elements.each("gpx/trk/trkseg/trkpt") { |e|
    a << {:time => Time.parse(e.elements["time"].to_a.first.to_s)}
    a[i][:lat] = e.attributes["lat"].to_s;
    a[i][:lon] = e.attributes["lon"].to_s;
    a[i][:ele] = e.elements["ele"].to_a.first.to_s
    a[i][:speed] = e.elements["speed"].to_a.first.to_s
    a[i][:course] = e.elements["course"].to_a.first.to_s
    a[i][:fix] = e.elements["fix"].to_a.first.to_s
    i += 1
  }
  return a
end

And this is the code using libxml which I wrote after learning a little bit more ruby ;)

def parse_gpx(file)
  require 'rubygems'
  require 'libxml'
  a = Array.new
  doc = LibXML::XML::Document.file(file)
  nodes = doc.find '/ns:gpx/ns:trk/ns:trkseg/ns:trkpt',
                     "ns:http://www.topografix.com/GPX/1/0"
  nodes.each do |e|
    a << {:lat => e[:lat], :lon => e[:lon]}
    node = a.last
    e.each do |n|
      node[n.name.to_sym] = n.children.to_s if n.children?
    end
    node[:time] = Time.parse(node[:time])
  end
  return a
end

This code is part of a little script which I use to combine data from the GPS logger device with the data which is provided by my cycle computer (heart rate, barometric height, cadence, speed etc.).

 
7 Comments

Posted in Ruby, geo/gps

 

geocoding

09 Dec
include Geocode
begin
  # input is an postal address
  result = geocode ARGV.to_s

  # debugging output
  puts "#{result[:address1]}, #{result[:city]},
      #{result[:state]}, #{result[:zipcode]}"

  puts "#{result[:latitude]}, #{result[:longitude]}"

  # convert decimal values to DMS
  puts dec2dms(result[:latitude])
  puts dec2dms(result[:longitude])
end
 
No Comments

Posted in Ruby