3 #You might want to change this
4 ENV["RAILS_ENV"] ||= "development"
6 require File.dirname(__FILE__) + "/../../config/environment"
13 logger = ActiveRecord::Base.logger
17 ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
19 traces = Trace.find(:all, :conditions => ['inserted = ?', false])
21 if traces and traces.length > 0
22 traces.each do |trace|
25 logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
27 gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
30 logger.info("gzipped")
32 logger.info("not gzipped")
34 gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx")
42 f_lat = point['latitude']
43 f_lon = point['longitude']
47 tp.latitude = point['latitude']
48 tp.longitude = point['longitude']
49 tp.altitude = point['altitude']
50 tp.user_id = trace.user.id
52 tp.trackid = point['segment']
56 if gpx.actual_points > 0
57 max_lat = Tracepoint.maximum('latitude', :conditions => ['gpx_id = ?', trace.id])
58 min_lat = Tracepoint.minimum('latitude', :conditions => ['gpx_id = ?', trace.id])
59 max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', trace.id])
60 min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', trace.id])
62 trace.latitude = f_lat
63 trace.longitude = f_lat
64 trace.large_picture = gpx.get_picture(min_lat, min_lon, max_lat, max_lon, gpx.actual_points)
65 trace.icon_picture = gpx.get_icon(min_lat, min_lon, max_lat, max_lon)
66 trace.size = gpx.actual_points
69 Notifier::deliver_gpx_success(trace, gpx.possible_points)
72 Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
75 rescue Exception => ex
77 Notifier::deliver_gpx_failure(trace, ex.to_s + ex.backtrace.join("\n") )