various ruby bits
This commit is contained in:
parent
b56b9609e2
commit
07cb7fea1a
1 changed files with 580 additions and 586 deletions
|
@ -1,5 +1,4 @@
|
|||
class AmfController < ApplicationController
|
||||
#=begin
|
||||
require 'stringio'
|
||||
|
||||
# to log:
|
||||
|
@ -19,7 +18,8 @@ class AmfController < ApplicationController
|
|||
# Parse request
|
||||
|
||||
headers=getint(req) # Read number of headers
|
||||
for i in (1..headers) # Read each header
|
||||
|
||||
headers.times do # Read each header
|
||||
name=getstring(req) # |
|
||||
req.getc # | skip boolean
|
||||
value=getvalue(req) # |
|
||||
|
@ -27,7 +27,7 @@ class AmfController < ApplicationController
|
|||
end
|
||||
|
||||
bodies=getint(req) # Read number of bodies
|
||||
for i in (1..bodies) # Read each body
|
||||
bodies.times do # Read each body
|
||||
message=getstring(req) # | get message name
|
||||
index=getstring(req) # | get index in response sequence
|
||||
bytes=getlong(req) # | get total size in bytes
|
||||
|
@ -159,7 +159,7 @@ StringIO.open(txt) do |file|
|
|||
end
|
||||
}
|
||||
end
|
||||
[presets,presetmenus,presetnames]
|
||||
return [presets,presetmenus,presetnames]
|
||||
end
|
||||
|
||||
# ----- whichways(left,bottom,right,top)
|
||||
|
@ -175,10 +175,8 @@ StringIO.open(txt) do |file|
|
|||
" AND node_a=current_nodes.id "+
|
||||
" AND (latitude BETWEEN "+(args[1].to_f-0.01).to_s+" AND "+(args[3].to_f+0.01).to_s+") "+
|
||||
" AND (longitude BETWEEN "+(args[0].to_f-0.01).to_s+" AND "+(args[2].to_f+0.01).to_s+")")
|
||||
ways=[]
|
||||
waylist.each {|a|
|
||||
ways<<a.wayid.to_i
|
||||
}
|
||||
|
||||
ways = waylist.collect {|a| a.wayid.to_i } # get an array of way id's
|
||||
|
||||
pointlist =ActiveRecord::Base.connection.select_all("SELECT current_nodes.id,current_nodes.tags "+
|
||||
" FROM current_nodes "+
|
||||
|
@ -188,11 +186,10 @@ StringIO.open(txt) do |file|
|
|||
" AND (longitude BETWEEN "+(args[0].to_f-0.01).to_s+" AND "+(args[2].to_f-0.01).to_s+") "+
|
||||
" AND cs1.id IS NULL AND cs2.id IS NULL "+
|
||||
" AND current_nodes.visible=1")
|
||||
points=[]
|
||||
pointlist.each {|a|
|
||||
points<<[a['id'],tag2array(a['tags'])]
|
||||
}
|
||||
[ways,points]
|
||||
|
||||
points = pointlist.collect {|a| [a['id'],tag2array(a['tags'])] } # get a list of node ids and their tags
|
||||
|
||||
return [ways,points]
|
||||
end
|
||||
|
||||
# ----- getway (objectname, way, baselong, basey, masterscale)
|
||||
|
@ -204,15 +201,13 @@ StringIO.open(txt) do |file|
|
|||
wayid = wayid.to_i
|
||||
points = []
|
||||
lastid = -1
|
||||
xmin=999999; xmax=-999999
|
||||
ymin=999999; ymax=-999999
|
||||
xmin = ymin = 999999
|
||||
xmax = ymax = -999999
|
||||
|
||||
readwayquery(wayid).each {|row|
|
||||
xs1=long2coord(row['long1'].to_f,baselong,masterscale); ys1=lat2coord(row['lat1'].to_f,basey,masterscale)
|
||||
xs2=long2coord(row['long2'].to_f,baselong,masterscale); ys2=lat2coord(row['lat2'].to_f,basey,masterscale)
|
||||
if (row['id1'].to_i!=lastid)
|
||||
points<<[xs1,ys1,row['id1'].to_i,0,tag2array(row['tags1']),0]
|
||||
end
|
||||
points << [xs1,ys1,row['id1'].to_i,0,tag2array(row['tags1']),0] if (row['id1'].to_i!=lastid)
|
||||
lastid = row['id2'].to_i
|
||||
points << [xs2,ys2,row['id2'].to_i,1,tag2array(row['tags2']),row['segment_id'].to_i]
|
||||
xmin = [xmin,row['long1'].to_f,row['long2'].to_f].min
|
||||
|
@ -235,7 +230,8 @@ StringIO.open(txt) do |file|
|
|||
|
||||
def putway(args)
|
||||
usertoken,originalway,points,attributes,baselong,basey,masterscale=args
|
||||
uid=getuserid(usertoken); if !uid then return end
|
||||
uid=getuserid(usertoken)
|
||||
return if !uid
|
||||
db_uqs='uniq'+uid.to_s+originalway.to_i.abs.to_s+Time.new.to_i.to_s # temp uniquesegments table name, typically 51 chars
|
||||
db_now='@now'+uid.to_s+originalway.to_i.abs.to_s+Time.new.to_i.to_s # 'now' variable name, typically 51 chars
|
||||
ActiveRecord::Base.connection.execute("SET #{db_now}=NOW()")
|
||||
|
@ -244,7 +240,7 @@ StringIO.open(txt) do |file|
|
|||
# -- 3. read original way into memory
|
||||
|
||||
xc={}; yc={}; tagc={}; seg={}
|
||||
if (originalway>0)
|
||||
if originalway>0
|
||||
way=originalway
|
||||
readwayquery(way).each { |row|
|
||||
id1=row['id1'].to_i; xc[id1]=row['long1'].to_f; yc[id1]=row['lat1'].to_f; tagc[id1]=row['tags1']
|
||||
|
@ -261,10 +257,9 @@ StringIO.open(txt) do |file|
|
|||
|
||||
# -- 5. compare nodes and update xmin,xmax,ymin,ymax
|
||||
|
||||
xmin=999999; xmax=-999999
|
||||
ymin=999999; ymax=-999999
|
||||
insertsql=''
|
||||
nodelist=''
|
||||
xmin = ymin = 999999
|
||||
xmax = ymax = -999999
|
||||
insertsql = nodelist = ''
|
||||
renumberednodes={}
|
||||
|
||||
points.each_index do |i|
|
||||
|
@ -699,5 +694,4 @@ StringIO.open(txt) do |file|
|
|||
180/Math::PI * (2*Math.atan(Math.exp(a*Math::PI/180))-Math::PI/2)
|
||||
end
|
||||
|
||||
#=end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue