@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
<%= @trace_name %>
-failed to import :-(
+failed to import. Here's the error:
+
+ <%= @error %>
<%= @trace_name %>
-loaded successfully with <%= @trace_points %> points.
+loaded successfully with <%= @trace_points %> out of a possible
+<%= @possible_points %> points.
$running = false
end
+logger = ActiveRecord::Base.logger
+
while($running) do
ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
traces.each do |trace|
begin
- ActiveRecord::Base.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)
+ logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
+
+ 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
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
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