- 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)