-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpxupload.rb
executable file
·52 lines (43 loc) · 1.4 KB
/
gpxupload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/ruby -I~/.gem/ruby/1.8/gems
#
# Call this as follows: RUBYLIB=~/.gem/ruby/1.8/gems ./gpxupload.rb
#
require 'rubygems'
require 'gpx-0.6/lib/gpx.rb'
require 'rest_client'
$Server = 'http://localhost:3000/slices'
#$Server = 'http://carcomm.cstimming.de/slices'
$File = ARGV.size > 0 ? ARGV[0] : nil #ENV["HOME"] + "/merkaator-export3.gpx"
def main
gpx = GPX::GPXFile.new(:gpx_file => $File)
#puts "Duration: #{gpx.duration}"
puts "File: #{$File}"
puts " Bounds: #{gpx.bounds}"
gpx.tracks.each do | track |
puts " Track Name: #{track.name}"
puts " Num Points: #{track.points.size}"
prev = nil
track.points.each do | trkpt |
if prev.nil? or trkpt.time.nil?
prev = trkpt
else
duration = prev.time.nil? ? 0 : trkpt.time - prev.time
# Ignore slices smaller than 5 seconds
if duration > 9
if duration < 95
puts "Time: #{trkpt.time} Lat: #{trkpt.lat} Lon: #{trkpt.lon} Duration: #{duration}s Startlat: #{prev.lat} Startlon: #{prev.lon}"
# RestClient.post $Server, {
# "slice[lat]" => trkpt.lat,
# "slice[lon]" => trkpt.lon,
# "slice[time]" => trkpt.time,
# "slice[duration]" => duration,
# "slice[startlat]" => prev.lat,
# "slice[startlon]" => prev.lon }
end
prev = trkpt
end
end
end
end
end
main