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 # TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
28 gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
\r
31 logger.info("gzipped")
33 logger.info("not gzipped")
35 gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx")
43 f_lat = point['latitude']
44 f_lon = point['longitude']
48 tp.latitude = point['latitude']
49 tp.longitude = point['longitude']
50 tp.altitude = point['altitude']
51 tp.user_id = trace.user.id
53 tp.trackid = point['segment']
57 if gpx.actual_points > 0
58 max_lat = Tracepoint.maximum('latitude', :conditions => ['gpx_id = ?', trace.id])
59 min_lat = Tracepoint.minimum('latitude', :conditions => ['gpx_id = ?', trace.id])
60 max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', trace.id])
61 min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', trace.id])
63 trace.latitude = f_lat
64 trace.longitude = f_lon
65 trace.large_picture = gpx.get_picture(min_lat, min_lon, max_lat, max_lon, gpx.actual_points)
66 trace.icon_picture = gpx.get_icon(min_lat, min_lon, max_lat, max_lon)
67 trace.size = gpx.actual_points
70 Notifier::deliver_gpx_success(trace, gpx.possible_points)
73 Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
76 rescue Exception => ex
78 Notifier::deliver_gpx_failure(trace, ex.to_s + ex.backtrace.join("\n") )