updates from hacking day
This commit is contained in:
parent
e5a5f957ef
commit
89e976c6e5
12 changed files with 150 additions and 45 deletions
|
@ -55,7 +55,9 @@ class ApiController < ApplicationController
|
|||
|
||||
node_ids = nodes.collect {|node| node.id }
|
||||
|
||||
# (in the future, we may wish to abort here if we found too many nodes)
|
||||
if node_ids.length > 50_000
|
||||
report_error("You requested too many nodes (limit is 50,000). Either request a smaller area, or use planet.osm")
|
||||
end
|
||||
|
||||
# grab the segments
|
||||
segments = Array.new
|
||||
|
@ -85,18 +87,54 @@ class ApiController < ApplicationController
|
|||
way_segments = WaySegment.find_all_by_segment_id(segment_ids)
|
||||
way_ids = way_segments.collect {|way_segment| way_segment.id }
|
||||
ways = Way.find(way_ids) # NB: doesn't pick up segments, tags from db until accessed via way.way_segments etc.
|
||||
|
||||
# seg_ids = way_segments.collect {|way_segment| way_segment.segment_id }
|
||||
|
||||
list_of_way_segs = ways.collect {|way| way.way_segments}
|
||||
list_of_way_segs.flatten!
|
||||
|
||||
list_of_way_segments = list_of_way_segs.collect { |way_seg| way_seg.segment_id }
|
||||
|
||||
end
|
||||
|
||||
segments_to_fetch = list_of_way_segments.uniq - segment_ids
|
||||
|
||||
if segments_to_fetch.length > 0
|
||||
segments += Segment.find(segments_to_fetch)
|
||||
end
|
||||
|
||||
# get more nodes
|
||||
#
|
||||
|
||||
segments_nodes = segments.collect {|segment| segment.node_a }
|
||||
segments_nodes += segments.collect {|segment| segment.node_b }
|
||||
|
||||
node_ids_a = nodes.collect {|node| node.id }
|
||||
|
||||
nodes_to_get = segments_nodes - node_ids_a
|
||||
nodes += Node.find(nodes_to_get) if nodes_to_get.length > 0
|
||||
|
||||
visible_nodes = {}
|
||||
user_display_name_cache = {}
|
||||
|
||||
nodes.each do |node|
|
||||
doc.root << node.to_xml_node()
|
||||
if node.visible?
|
||||
doc.root << node.to_xml_node(user_display_name_cache)
|
||||
visible_nodes[node.id] = node
|
||||
end
|
||||
end
|
||||
|
||||
visible_segments = {}
|
||||
|
||||
segments.each do |segment|
|
||||
doc.root << segment.to_xml_node()
|
||||
if visible_nodes[segment.node_a] and visible_nodes[segment.node_b] and segment.visible?
|
||||
doc.root << segment.to_xml_node(user_display_name_cache)
|
||||
visible_segments[segment.id] = segment
|
||||
end
|
||||
end
|
||||
|
||||
ways.each do |way|
|
||||
doc.root << way.to_xml_node()
|
||||
doc.root << way.to_xml_node(visible_segments, user_display_name_cache) if way.visible?
|
||||
end
|
||||
|
||||
render :text => doc.to_s
|
||||
|
|
|
@ -78,12 +78,22 @@ class Node < ActiveRecord::Base
|
|||
return doc
|
||||
end
|
||||
|
||||
def to_xml_node
|
||||
def to_xml_node(user_display_name_cache = nil)
|
||||
el1 = XML::Node.new 'node'
|
||||
el1['id'] = self.id.to_s
|
||||
el1['lat'] = self.latitude.to_s
|
||||
el1['lon'] = self.longitude.to_s
|
||||
el1['user'] = self.user.display_name if self.user.data_public?
|
||||
|
||||
# el['user'] = self.user.display_name if self.user.data_public?
|
||||
|
||||
if user_display_name_cache and user_display_name_cache[self.user_id]
|
||||
# use the cache if available
|
||||
else
|
||||
user_display_name_cache[self.user_id] = self.user.display_name
|
||||
end
|
||||
|
||||
el1['user'] = user_display_name_cache[self.user_id]
|
||||
|
||||
Node.split_tags(el1, self.tags)
|
||||
el1['visible'] = self.visible.to_s
|
||||
el1['timestamp'] = self.timestamp.xmlschema
|
||||
|
|
|
@ -73,12 +73,20 @@ class Segment < ActiveRecord::Base
|
|||
return doc
|
||||
end
|
||||
|
||||
def to_xml_node
|
||||
def to_xml_node(user_display_name_cache = nil)
|
||||
el1 = XML::Node.new 'segment'
|
||||
el1['id'] = self.id.to_s
|
||||
el1['from'] = self.node_a.to_s
|
||||
el1['to'] = self.node_b.to_s
|
||||
el1['user'] = self.user.display_name if self.user.data_public?
|
||||
if user_display_name_cache and user_display_name_cache[self.user_id]
|
||||
# use the cache if available
|
||||
else
|
||||
user_display_name_cache[self.user_id] = self.user.display_name
|
||||
end
|
||||
|
||||
#el1['user'] = self.user.display_name if self.user.data_public?
|
||||
el1['user'] = user_display_name_cache[self.user_id]
|
||||
|
||||
Segment.split_tags(el1, self.tags)
|
||||
el1['visible'] = self.visible.to_s
|
||||
el1['timestamp'] = self.timestamp.xmlschema
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
class Tracepoint < ActiveRecord::Base
|
||||
set_table_name 'gps_points'
|
||||
set_table_name 'gps_points'
|
||||
|
||||
# validates_numericality_of :latitude
|
||||
# validates_numericality_of :longitude
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :trace, :foreign_key => 'gpx_id'
|
||||
|
||||
def lat=(l)
|
||||
self.latitude = l * 1000000
|
||||
end
|
||||
|
||||
def lng=(l)
|
||||
self.longitude = l * 1000000
|
||||
end
|
||||
|
||||
def lat
|
||||
return self.latitude.to_f / 1000000
|
||||
end
|
||||
|
||||
def lon
|
||||
return self.longitude.to_f / 1000000
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.authenticate(email, passwd)
|
||||
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])
|
||||
find(:first, :conditions => [ "email = ? AND pass_crypt = ? AND active = true", email, Digest::MD5.hexdigest(passwd)])
|
||||
end
|
||||
|
||||
def self.authenticate_token(token)
|
||||
|
|
|
@ -50,22 +50,44 @@ class Way < ActiveRecord::Base
|
|||
return doc
|
||||
end
|
||||
|
||||
def to_xml_node
|
||||
def to_xml_node(visible_segments = nil, user_display_name_cache = nil)
|
||||
el1 = XML::Node.new 'way'
|
||||
el1['id'] = self.id.to_s
|
||||
el1['visible'] = self.visible.to_s
|
||||
el1['timestamp'] = self.timestamp.xmlschema
|
||||
el1['user'] = self.user.display_name if self.user.data_public?
|
||||
|
||||
if user_display_name_cache and user_display_name_cache[self.user_id]
|
||||
# use the cache if available
|
||||
else
|
||||
user_display_name_cache[self.user_id] = self.user.display_name
|
||||
end
|
||||
|
||||
#el1['user'] = self.user.display_name if self.user.data_public?
|
||||
el1['user'] = user_display_name_cache[self.user_id]
|
||||
|
||||
# make sure segments are output in sequence_id order
|
||||
ordered_segments = []
|
||||
self.way_segments.each do |seg|
|
||||
if visible_segments
|
||||
# if there is a list of visible segments then use that to weed out deleted segments
|
||||
if visible_segments[seg.segment_id]
|
||||
ordered_segments[seg.sequence_id] = seg.segment_id.to_s
|
||||
end
|
||||
else
|
||||
# otherwise, manually go to the db to check things
|
||||
if seg.segment.visible? and seg.segment.from_node.visible? and seg.segment.to_node.visible?
|
||||
ordered_segments[seg.sequence_id] = seg.segment_id.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ordered_segments.each do |seg_id|
|
||||
if seg_id
|
||||
e = XML::Node.new 'seg'
|
||||
e['id'] = seg_id
|
||||
el1 << e
|
||||
end
|
||||
end
|
||||
|
||||
self.way_tags.each do |tag|
|
||||
e = XML::Node.new 'tag'
|
||||
|
@ -76,7 +98,6 @@ class Way < ActiveRecord::Base
|
|||
return el1
|
||||
end
|
||||
|
||||
|
||||
def segs
|
||||
unless @segs
|
||||
@segs = Array.new
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
function init(){
|
||||
|
||||
OpenLayers.Util.onImageLoadError = function() {
|
||||
this.src = "http://www.openstreetmap.org/javascript/img/404.png";
|
||||
this.src = "http://www.openstreetmap.org/javascripts/img/404.png";
|
||||
}
|
||||
map = new OpenLayers.Map( "map",
|
||||
{maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), maxZoomLevel:18, maxResolution:156543, units:'meters', projection: "EPSG:41001"} );
|
||||
|
|
|
@ -62,8 +62,6 @@ Go to <%= link_to 'your account page', :controller => 'user', :action => 'accoun
|
|||
<% end %>
|
||||
<br />
|
||||
<br />
|
||||
<%= link_to 'diary', :controller => 'user', :action => 'diary', :display_name => @this_user.display_name %><br /><br />
|
||||
|
||||
|
||||
<p><%= params[:display_name] %> says: </p>
|
||||
<%= simple_format(@this_user.description) %>
|
||||
|
|
|
@ -15,7 +15,7 @@ development:
|
|||
database: openstreetmap
|
||||
username: openstreetmap
|
||||
password: openstreetmap
|
||||
host: localhost
|
||||
host: 128.40.58.203
|
||||
|
||||
# Warning: The database defined as 'test' will be erased and
|
||||
# re-generated from your development database when you run 'rake'.
|
||||
|
@ -32,4 +32,4 @@ production:
|
|||
database: openstreetmap
|
||||
username: openstreetmap
|
||||
password: openstreetmap
|
||||
host: db.openstreetmap.org
|
||||
host: 128.40.58.203
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Uncomment below to force Rails into production mode when
|
||||
# you don't control web/app server and can't set it the proper way
|
||||
# ENV['RAILS_ENV'] ||= 'production'
|
||||
ENV['RAILS_ENV'] ||= 'production'
|
||||
|
||||
# Specifies gem version of Rails to use when vendor/rails is not present
|
||||
RAILS_GEM_VERSION = '1.2.3'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
#You might want to change this
|
||||
ENV["RAILS_ENV"] ||= "development"
|
||||
#ENV["RAILS_ENV"] ||= "development"
|
||||
|
||||
require File.dirname(__FILE__) + "/../../config/environment"
|
||||
|
||||
|
@ -16,13 +16,13 @@ while($running) do
|
|||
|
||||
ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
|
||||
|
||||
traces = Trace.find(:all, :conditions => ['inserted = ?', false])
|
||||
traces = Trace.find(:all) #, :conditions => ['inserted = ?', false])
|
||||
|
||||
if traces and traces.length > 0
|
||||
traces.each do |trace|
|
||||
begin
|
||||
|
||||
logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
|
||||
logger.info("GPX Import importing #{trace.name} (#{trace.id}) from #{trace.user.email}")
|
||||
|
||||
# TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
|
||||
gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
|
||||
|
@ -32,10 +32,11 @@ while($running) do
|
|||
else
|
||||
logger.info("not gzipped")
|
||||
end
|
||||
gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx")
|
||||
|
||||
gpx = OSM::GPXImporter.new("/home/osm/gpx/#{trace.id}.gpx")
|
||||
|
||||
f_lat = 0
|
||||
l_lon = 0
|
||||
f_lon = 0
|
||||
first = true
|
||||
|
||||
gpx.points do |point|
|
||||
|
@ -45,12 +46,12 @@ while($running) do
|
|||
end
|
||||
|
||||
tp = Tracepoint.new
|
||||
tp.latitude = point['latitude']
|
||||
tp.longitude = point['longitude']
|
||||
tp.altitude = point['altitude']
|
||||
tp.lat = point['latitude'].to_f
|
||||
tp.lng = point['longitude'].to_f
|
||||
tp.altitude = point['altitude'].to_f
|
||||
tp.user_id = trace.user.id
|
||||
tp.gpx_id = trace.id
|
||||
tp.trackid = point['segment']
|
||||
tp.trackid = point['segment'].to_i
|
||||
tp.save!
|
||||
end
|
||||
|
||||
|
@ -60,6 +61,11 @@ while($running) do
|
|||
max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', trace.id])
|
||||
min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', trace.id])
|
||||
|
||||
max_lat = max_lat.to_f / 1000000
|
||||
min_lat = min_lat.to_f / 1000000
|
||||
max_lon = max_lon.to_f / 1000000
|
||||
min_lon = min_lon.to_f / 1000000
|
||||
|
||||
trace.latitude = f_lat
|
||||
trace.longitude = f_lon
|
||||
trace.large_picture = gpx.get_picture(min_lat, min_lon, max_lat, max_lon, gpx.actual_points)
|
||||
|
@ -67,15 +73,19 @@ while($running) do
|
|||
trace.size = gpx.actual_points
|
||||
trace.inserted = true
|
||||
trace.save
|
||||
Notifier::deliver_gpx_success(trace, gpx.possible_points)
|
||||
|
||||
logger.info "done trace #{trace.id} -------------------------------------------------------------------------------"
|
||||
# Notifier::deliver_gpx_success(trace, gpx.possible_points)
|
||||
else
|
||||
#trace.destroy
|
||||
Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
|
||||
# Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
|
||||
end
|
||||
|
||||
rescue Exception => ex
|
||||
logger.info ex
|
||||
ex.backtrace.each {|l| logger.info l }
|
||||
#trace.destroy
|
||||
Notifier::deliver_gpx_failure(trace, ex.to_s + ex.backtrace.join("\n") )
|
||||
# Notifier::deliver_gpx_failure(trace, ex.to_s + ex.backtrace.join("\n") )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -125,6 +125,7 @@ module OSM
|
|||
end
|
||||
|
||||
def get_picture(min_lat, min_lon, max_lat, max_lon, num_points)
|
||||
#puts "getting picfor bbox #{min_lat},#{min_lon} - #{max_lat},#{max_lon}"
|
||||
frames = 10
|
||||
width = 250
|
||||
height = 250
|
||||
|
@ -157,13 +158,14 @@ module OSM
|
|||
images[n].stroke_width(1)
|
||||
images[n].stroke('#BBBBBB')
|
||||
images[n].fill('#BBBBBB')
|
||||
# puts "A #{px},#{py} - #{oldpx},#{oldpy}"
|
||||
images[n].line(px, py, oldpx, oldpy ) unless first
|
||||
end
|
||||
images[mm].stroke_width(3)
|
||||
images[mm].stroke('#000000')
|
||||
images[mm].fill('#000000')
|
||||
images[mm].line(px, py, oldpx, oldpy ) unless first
|
||||
|
||||
# puts "B #{px},#{py} - #{oldpx},#{oldpy}"
|
||||
m +=1
|
||||
if m > num_points.to_f / frames.to_f * (mm+1)
|
||||
mm += 1
|
||||
|
@ -193,6 +195,7 @@ module OSM
|
|||
end
|
||||
|
||||
def get_icon(min_lat, min_lon, max_lat, max_lon)
|
||||
puts "getting icon for bbox #{min_lat},#{min_lon} - #{max_lat},#{max_lon}"
|
||||
width = 50
|
||||
height = 50
|
||||
rat= Math.cos( ((max_lat + min_lat)/2.0) / 180.0 * 3.141592)
|
||||
|
@ -216,6 +219,7 @@ module OSM
|
|||
px = proj.x(p['longitude'])
|
||||
py = proj.y(p['latitude'])
|
||||
gc.line(px, py, oldpx, oldpy ) unless first
|
||||
# puts "C #{px},#{py} - #{oldpx},#{oldpy}"
|
||||
first = false
|
||||
oldpy = py
|
||||
oldpx = px
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue