Add test for route relation process in car.lua. Some fixes

This commit is contained in:
Denis Koronchik 2017-09-14 17:56:23 +03:00 committed by Patrick Niklaus
parent a05e9c4932
commit 3634aa9a3c
4 changed files with 86 additions and 9 deletions

View File

@ -0,0 +1,68 @@
@routing @car @relations
Feature: Car - route relations
Background:
Given the profile "car"
@sliproads
Scenario: Cardinal direction assignment to refs
Given the node map
"""
a b
| |
c------+--+------d
e------+--+------f
| |
g h
i----------------j
k----------------l
x----------------y
z----------------w
"""
And the ways
| nodes | name | highway | ref |
| ag | southbound | motorway | I 80 |
| hb | northbound | motorway | I 80 |
| dc | westbound | motorway | I 85;CO 93 |
| ef | eastbound | motorway | I 85;US 12 |
| ij | westbound-2 | motorway | I 99 |
| ji | eastbound-2 | motorway | I 99 |
| kl | eastbound-2 | motorway | I 99 |
| lk | eastbound-2 | motorway | I 99 |
| xy | watermill | motorway | I 45M; US 3 |
And the relations
| type | way:south | route | ref |
| route | ag | road | 80 |
| route | ef | road | 12 |
And the relations
| type | way:north | route | ref |
| route | hb | road | 80 |
| route | cd | road | 93 |
And the relations
| type | way:west | route | ref |
| route | dc | road | 85 |
| route | ij | road | 99 |
| route | xy | road | I 45 |
And the relations
| type | way:east | route | ref |
| route | lk | road | I 99 |
And the relations
| type | way:east | route | ref |
| route | xy | road | US 3 |
When I route I should get
| waypoints | route | ref |
| a,g | southbound,southbound | I 80 $south,I 80 $south |
| h,b | northbound,northbound | I 80 $north,I 80 $north |
| d,c | westbound,westbound | I 85 $west; CO 93 $north,I 85 $west; CO 93 $north |
| e,f | eastbound,eastbound | I 85; US 12 $south,I 85; US 12 $south |
| i,j | westbound-2,westbound-2 | I 99 $west,I 99 $west |
| l,k | eastbound-2,eastbound-2 | I 99 $east,I 99 $east |
| x,y | watermill,watermill | I 45M $west; US 3 $east,I 45M $west; US 3 $east |

View File

@ -401,10 +401,14 @@ function process_way(profile, way, result, relations)
-- now process relations data
local matched_refs = nil;
if result.ref then
matched_refs = Relations.MatchToRef(relations, result.ref)
local match_res = Relations.match_to_ref(relations, result.ref)
order = match_res['order']
matched_refs = match_res['match']
local ref = ''
for k, v in pairs(matched_refs) do
for _, k in pairs(order) do
local v = matched_refs[k]
if ref ~= '' then
ref = ref .. '; '
end

View File

@ -20,7 +20,7 @@ function Relations.Merge(relations)
end
-- match ref values to relations data
function Relations.MatchToRef(relations, ref)
function Relations.match_to_ref(relations, ref)
function calculate_scores(refs, tag_value)
local tag_tokens = Set(Utils.tokenize_common(tag_value))
@ -47,12 +47,13 @@ function Relations.MatchToRef(relations, ref)
local references = Utils.string_list_tokens(ref)
local result_match = {}
for _, r in ipairs(references) do
local order = {}
for i, r in ipairs(references) do
result_match[r] = false
order[i] = r
end
for _, rel in ipairs(relations) do
for i, rel in ipairs(relations) do
local name_scores = nil
local name_tokens = {}
local route_name = rel["route_name"]
@ -94,7 +95,11 @@ function Relations.MatchToRef(relations, ref)
end
return result_match
local result = {}
result['order'] = order
result['match'] = result_match
return result
end
return Relations

View File

@ -13,7 +13,7 @@ function Utils.string_list_tokens(str)
for s in str.gmatch(str, "([^;]*)") do
if s ~= nil and s ~= '' then
idx = idx + 1
table.insert(result, idx, (s:gsub("^%s*(.-)%s*$", "%1")))
result[idx] = s:gsub("^%s*(.-)%s*$", "%1")
end
end
@ -28,7 +28,7 @@ function Utils.tokenize_common(str)
for s in str.gmatch(str, "%S+") do
if s ~= nil and s ~= '' then
idx = idx + 1
table.insert(result, idx, (s:gsub("^%s*(.-)%s*$", "%1")))
result[idx] = s:gsub("^%s*(.-)%s*$", "%1")
end
end