Skip to content

Commit dddf83d

Browse files
authored
Merge pull request #5908 from systemed/debug_way
Profile debug script which fetches a way from OSM
2 parents 5266ac1 + 158d260 commit dddf83d

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- REMOVED: we no longer publish Node 8 binary modules (they are still buildable from source) [#5918](https://github.com/Project-OSRM/osrm-backend/pull/5918)
77
- Misc:
88
- CHANGED: Unify `.osrm.turn_penalites_index` dump processing same with `.osrm.turn_weight_penalties` and `.osrm.turn_duration_penalties` [#5868](https://github.com/Project-OSRM/osrm-backend/pull/5868)
9+
- Profile:
10+
- ADDED: Profile debug script which fetches a way from OSM then outputs the result of the profile. [#5908](https://github.com/Project-OSRM/osrm-backend/pull/5908)
911
- Infrastructure
1012
- CHANGED: Bundled protozero updated to v1.7.0. [#5858](https://github.com/Project-OSRM/osrm-backend/pull/5858)
1113
- Windows:

profiles/debug_way.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--
2+
-- Fetch a way from the OpenStreetMap API and run the given profile over it.
3+
--
4+
-- You'll need to install xml2lua first (may require admin privileges):
5+
-- > luarocks install xml2lua
6+
--
7+
-- You may also need to install luasec and luasocket if you don't have them already.
8+
--
9+
-- Then to test way 2606296 using the foot profile:
10+
-- > lua debug_way.lua foot 2606296
11+
--
12+
13+
-- initialise libraries
14+
local pprint = require('lib/pprint')
15+
local Debug = require('lib/profile_debugger')
16+
local xml2lua = require('xml2lua')
17+
local handler = require('xmlhandler.tree')
18+
local https = require('ssl.https')
19+
20+
-- load the profile
21+
Debug.load_profile(arg[1])
22+
23+
-- load way from the OSM API
24+
local url = 'https://www.openstreetmap.org/api/0.6/way/'..arg[2]
25+
local body, statusCode, headers, statusText = https.request(url)
26+
27+
-- parse way tags
28+
local parser = xml2lua.parser(handler)
29+
parser:parse(body)
30+
31+
-- convert XML-flavoured table to a simple k/v table
32+
local way = {}
33+
for i, p in pairs(handler.root.osm.way.tag) do
34+
way[p._attr.k] = p._attr.v
35+
end
36+
37+
-- call the way function
38+
local result = {}
39+
Debug.process_way(way,result)
40+
41+
-- print input and output
42+
pprint(way)
43+
print("=>")
44+
pprint(result)

profiles/lib/profile_debugger.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ end
5252
function canonicalizeStringList(str)
5353
return str
5454
end
55-
55+
5656

5757

5858
-- debug helper
@@ -123,11 +123,14 @@ function Debug.process_way(way,result)
123123
result.forward_classes = {}
124124
result.backward_classes = {}
125125

126-
-- intercept tag function normally provided via C++
126+
-- intercept tag functions normally provided via C++
127127
function way:get_value_by_key(k)
128128
Debug.register_tag_fetch(k)
129129
return self[k]
130130
end
131+
function way:get_location_tag(k)
132+
return nil
133+
end
131134

132135
-- reset tag counts
133136
Debug:reset_tag_fetch_counts()

0 commit comments

Comments
 (0)