gpx insert now works

This commit is contained in:
Steve Coast 2006-12-01 17:56:13 +00:00
parent fac305e87b
commit 92418b7954
5 changed files with 42 additions and 15 deletions

View file

@ -21,18 +21,20 @@ class Notifier < ActionMailer::Base
@body['pass'] = pass
end
def gpx_success(trace)
@recipients = user.email
def gpx_success(trace, possible_points)
@recipients = trace.user.email
@from = 'abuse@openstreetmap.org'
@subject = '[OpenStreetMap] GPX Import success'
@body['trace_name'] = trace.name
@body['trace_points'] = trace.size
@body['possible_points'] = possible_points
end
def gpx_failure(trace)
@recipients = user.email
def gpx_failure(trace, error)
@recipients = trace.user.email
@from = 'abuse@openstreetmap.org'
@subject = '[OpenStreetMap] GPX Import failure'
@body['trace_name'] = trace.name
@body['error'] = error
end
end

View file

@ -4,4 +4,6 @@ It looks like your GPX file
<%= @trace_name %>
failed to import :-(
failed to import. Here's the error:
<%= @error %>

View file

@ -4,4 +4,5 @@ It looks like your GPX file
<%= @trace_name %>
loaded successfully with <%= @trace_points %> points.
loaded successfully with <%= @trace_points %> out of a possible
<%= @possible_points %> points.

View file

@ -10,6 +10,8 @@ Signal.trap("TERM") do
$running = false
end
logger = ActiveRecord::Base.logger
while($running) do
ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
@ -20,16 +22,33 @@ while($running) do
traces.each do |trace|
begin
ActiveRecord::Base.logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
# gpx = OSM::GPXImporter.new('/tmp/2.gpx')
# gpx.points do |point|
# puts point['latitude']
# end
Notifier::deliver_gpx_success(trace)
rescue
Notifier::deliver_gpx_failure(trace)
gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
if gzipped
logger.info("gzipped")
else
logger.info("not gzipped")
end
gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx")
gpx.points do |point|
tp = Tracepoint.new
tp.latitude = point['latitude']
tp.latitude = point['longitude']
tp.altitude = point['altitude']
tp.user_id = trace.user.id
tp.gpx_id = trace.id
tp.trackid = point['segment']
end
trace.size = gpx.actual_points
trace.inserted = true
trace.save
Notifier::deliver_gpx_success(trace, gpx.possible_points)
rescue Exception => ex
trace.destroy
Notifier::deliver_gpx_failure(trace, ex.to_s)
end
end
end

View file

@ -14,11 +14,13 @@ module OSM
class GPXImporter
attr_reader :possible_points
attr_reader :actual_points
attr_reader :tracksegs
def initialize(filename)
@filename = filename
@possible_points = 0
@actual_points = 0
@tracksegs = 0
end
@ -61,6 +63,7 @@ module OSM
if gotlatlon && gotdate
ele = '0' unless gotele
if lat < 90 && lat > -90 && lon > -180 && lon < 180
@actual_points += 1
yield Hash['latitude' => lat,'longitude' => lon,'timestamp' => date,'altitude' => ele,'segment' => @tracksegs]
end
end