From 9a20e8e614ee2db58c1865e6eeddf19d1d23250e Mon Sep 17 00:00:00 2001 From: systemed Date: Thu, 10 Dec 2020 11:02:04 +0000 Subject: [PATCH 1/3] Profile debug script to fetch a way from OSM --- profiles/debug_way.lua | 44 +++++++++++++++++++++++++++++++ profiles/lib/profile_debugger.lua | 7 +++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 profiles/debug_way.lua diff --git a/profiles/debug_way.lua b/profiles/debug_way.lua new file mode 100644 index 000000000..c1ac4dbab --- /dev/null +++ b/profiles/debug_way.lua @@ -0,0 +1,44 @@ +-- +-- Fetch a way from the OpenStreetMap API and run the given profile over it. +-- +-- You'll need to install luasec and xml2lua first: +-- > luarocks-5.1 install xml2lua +-- > luarocks-5.1 install luasec +-- [may require admin privileges] +-- +-- Then to test way 2606296 using the foot profile: +-- > lua5.1 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) diff --git a/profiles/lib/profile_debugger.lua b/profiles/lib/profile_debugger.lua index 15f835609..276850160 100644 --- a/profiles/lib/profile_debugger.lua +++ b/profiles/lib/profile_debugger.lua @@ -52,7 +52,7 @@ end function canonicalizeStringList(str) return str end - + -- debug helper @@ -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() From 83b17e664c8d149765ad23b26660ad7995657a1e Mon Sep 17 00:00:00 2001 From: systemed Date: Tue, 15 Dec 2020 12:49:52 +0000 Subject: [PATCH 2/3] Update comments --- profiles/debug_way.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/profiles/debug_way.lua b/profiles/debug_way.lua index c1ac4dbab..7c577e9a0 100644 --- a/profiles/debug_way.lua +++ b/profiles/debug_way.lua @@ -1,13 +1,13 @@ -- -- Fetch a way from the OpenStreetMap API and run the given profile over it. -- --- You'll need to install luasec and xml2lua first: --- > luarocks-5.1 install xml2lua --- > luarocks-5.1 install luasec --- [may require admin privileges] --- +-- 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: --- > lua5.1 debug_way.lua foot 2606296 +-- > lua debug_way.lua foot 2606296 -- -- initialise libraries From 158d260cbb9995c8eb895e9c35219c13318dedce Mon Sep 17 00:00:00 2001 From: systemed Date: Tue, 15 Dec 2020 12:51:28 +0000 Subject: [PATCH 3/3] Mention new script in changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8003a438c..f446a0354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: