Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile debug script which fetches a way from OSM #5908

Merged
merged 3 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- Changes from 5.23.0
- Misc:
- 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)
- Profile:
- 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)
- Infrastructure
- CHANGED: Bundled protozero updated to v1.7.0. [#5858](https://github.com/Project-OSRM/osrm-backend/pull/5858)
- Windows:
Expand Down
44 changes: 44 additions & 0 deletions profiles/debug_way.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--
-- Fetch a way from the OpenStreetMap API and run the given profile over it.
--
-- You'll need to install xml2lua first (may require admin privileges):
-- > luarocks install xml2lua
--
-- You may also need to install luasec and luasocket if you don't have them already.
--
-- Then to test way 2606296 using the foot profile:
-- > lua debug_way.lua foot 2606296
--

-- initialise libraries
local pprint = require('lib/pprint')
local Debug = require('lib/profile_debugger')
local xml2lua = require('xml2lua')
local handler = require('xmlhandler.tree')
local https = require('ssl.https')

-- load the profile
Debug.load_profile(arg[1])

-- load way from the OSM API
local url = 'https://www.openstreetmap.org/api/0.6/way/'..arg[2]
local body, statusCode, headers, statusText = https.request(url)

-- parse way tags
local parser = xml2lua.parser(handler)
parser:parse(body)

-- convert XML-flavoured table to a simple k/v table
local way = {}
for i, p in pairs(handler.root.osm.way.tag) do
way[p._attr.k] = p._attr.v
end

-- call the way function
local result = {}
Debug.process_way(way,result)

-- print input and output
pprint(way)
print("=>")
pprint(result)
7 changes: 5 additions & 2 deletions profiles/lib/profile_debugger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end
function canonicalizeStringList(str)
return str
end



-- debug helper
Expand Down Expand Up @@ -123,11 +123,14 @@ function Debug.process_way(way,result)
result.forward_classes = {}
result.backward_classes = {}

-- intercept tag function normally provided via C++
-- intercept tag functions normally provided via C++
function way:get_value_by_key(k)
Debug.register_tag_fetch(k)
return self[k]
end
function way:get_location_tag(k)
return nil
end

-- reset tag counts
Debug:reset_tag_fetch_counts()
Expand Down