Use now 3 parameters for matrix: loc/dst/src
This commit is contained in:
committed by
Patrick Niklaus
parent
478d4a571a
commit
f2ee0aad20
@@ -4,16 +4,21 @@ When /^I request a travel time matrix I should get$/ do |table|
|
||||
raise "*** Top-left cell of matrix table must be empty" unless table.headers[0]==""
|
||||
|
||||
nodes = []
|
||||
sources = []
|
||||
column_headers = table.headers[1..-1]
|
||||
row_headers = table.rows.map { |h| h.first }
|
||||
unless column_headers==row_headers || @query_params['src']
|
||||
raise "*** Column and row headers must match in matrix table, got #{column_headers.inspect} and #{row_headers.inspect}"
|
||||
end
|
||||
column_headers.each do |node_name|
|
||||
node = find_node_by_name(node_name)
|
||||
raise "*** unknown node '#{node_name}" unless node
|
||||
nodes << node
|
||||
end
|
||||
if column_headers!=row_headers
|
||||
row_headers.each do |node_name|
|
||||
node = find_node_by_name(node_name)
|
||||
raise "*** unknown node '#{node_name}" unless node
|
||||
sources << node
|
||||
end
|
||||
end
|
||||
|
||||
reprocess
|
||||
actual = []
|
||||
@@ -22,11 +27,7 @@ When /^I request a travel time matrix I should get$/ do |table|
|
||||
|
||||
# compute matrix
|
||||
params = @query_params
|
||||
if params['src']
|
||||
node = find_node_by_name(params['src'])
|
||||
params['src'] = node.lat + ',' + node.lon
|
||||
end
|
||||
response = request_table nodes, params
|
||||
response = request_table nodes, sources, params
|
||||
if response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
result = json['distance_table']
|
||||
|
||||
@@ -41,9 +41,13 @@ def request_route waypoints, params={}
|
||||
request_path "viaroute", waypoints, defaults.merge(params)
|
||||
end
|
||||
|
||||
def request_table waypoints, params={}
|
||||
def request_table waypoints, sources, params={}
|
||||
defaults = { 'output' => 'json' }
|
||||
request_path "table", waypoints, defaults.merge(params)
|
||||
options = defaults.merge(params)
|
||||
locs = (sources.size > 0) ? (waypoints.compact.map { |w| "dst=#{w.lat},#{w.lon}" } + sources.compact.map { |w| "src=#{w.lat},#{w.lon}" }) : waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" }
|
||||
params = (locs + options.to_param).join('&')
|
||||
uri = generate_request_url ("table" + '?' + params)
|
||||
response = send_request uri, waypoints, options, sources
|
||||
end
|
||||
|
||||
def got_route? response
|
||||
|
||||
@@ -116,8 +116,25 @@ Feature: Basic Distance Matrix
|
||||
|
||||
And the query options
|
||||
| mapped_points | true |
|
||||
| src | a |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 100 | 200 | 300 |
|
||||
|
||||
Scenario: Testbot - Travel time 3x2 matrix
|
||||
Given the node map
|
||||
| a | b | c |
|
||||
| d | e | f |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abc |
|
||||
| def |
|
||||
| ad |
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | b | e | f |
|
||||
| a | 100 | 200 | 300 |
|
||||
| b | 0 | 100 | 200 |
|
||||
|
||||
Reference in New Issue
Block a user