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} (#{trace.id}) 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")
36 gpx = OSM::GPXImporter.new("/home/osm/gpx/#{trace.id}.gpx")
44 f_lat = point['latitude']
45 f_lon = point['longitude']
49 tp.lat = point['latitude'].to_f
50 tp.lng = point['longitude'].to_f
51 tp.altitude = point['altitude'].to_f
52 tp.user_id = trace.user.id
54 tp.trackid = point['segment'].to_i
58 if gpx.actual_points > 0
59 max_lat = Tracepoint.maximum('latitude', :conditions => ['gpx_id = ?', trace.id])
60 min_lat = Tracepoint.minimum('latitude', :conditions => ['gpx_id = ?', trace.id])
61 max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', trace.id])
62 min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', trace.id])
64 max_lat = max_lat.to_f / 1000000
65 min_lat = min_lat.to_f / 1000000
66 max_lon = max_lon.to_f / 1000000
67 min_lon = min_lon.to_f / 1000000
69 trace.latitude = f_lat
70 trace.longitude = f_lon
71 trace.large_picture = gpx.get_picture(min_lat, min_lon, max_lat, max_lon, gpx.actual_points)
72 trace.icon_picture = gpx.get_icon(min_lat, min_lon, max_lat, max_lon)
73 trace.size = gpx.actual_points
77 logger.info "done trace #{trace.id} -------------------------------------------------------------------------------"
78 # Notifier::deliver_gpx_success(trace, gpx.possible_points)
81 # Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
84 rescue Exception => ex
86 ex.backtrace.each {|l| logger.info l }
88 # Notifier::deliver_gpx_failure(trace, ex.to_s + ex.backtrace.join("\n") )