From 0dfec13c0aa2630b42a3c993d975608780150e3a Mon Sep 17 00:00:00 2001 From: Denis Koronchik Date: Fri, 29 Sep 2017 19:01:33 +0300 Subject: [PATCH] Fix some problems --- profiles/car.lua | 44 +------------------ profiles/lib/relations.lua | 42 ++++++++++++++++++ .../mocks/mock_scripting_environment.hpp | 2 +- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/profiles/car.lua b/profiles/car.lua index a141eaab3..c61415099 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -316,48 +316,6 @@ function process_node(profile, node, result, relations) end end -function parse_relation(relation, obj) - local t = relation:get_value_by_key("type") - local role = relation:get_role(obj) - local result = {} - - function add_extra_data(m) - local name = relation:get_value_by_key("name") - if name then - result['route_name'] = name - end - - local ref = relation:get_value_by_key("ref") - if ref then - result['route_ref'] = ref - end - end - - if t == 'route' then - local route = relation:get_value_by_key("route") - if route == 'road' then - -- process case, where directions set as role - if role == 'north' or role == 'south' or role == 'west' or role == 'east' then - result['route_direction'] = role - add_extra_data(m) - end - end - - local direction = relation:get_value_by_key('direction') - if direction then - direction = string.lower(direction) - if direction == 'north' or direction == 'south' or direction == 'west' or direction == 'east' then - if role == 'forward' then - result['route_direction'] = direction - add_extra_data(m) - end - end - end - end - - return result -end - function process_way(profile, way, result, relations) -- the intial filtering of ways based on presence of tags -- affects processing times significantly, because all ways @@ -448,7 +406,7 @@ function process_way(profile, way, result, relations) local rel_id_list = relations:get_relations(way) for i, r in ipairs(rel_id_list) do local rel_id = relations:relation(r) - parsed_rel_list[i] = parse_relation(rel_id, way) + parsed_rel_list[i] = Relations.parse_route_relation(rel_id, way) end -- now process relations data diff --git a/profiles/lib/relations.lua b/profiles/lib/relations.lua index d72fac82f..a1474bad5 100644 --- a/profiles/lib/relations.lua +++ b/profiles/lib/relations.lua @@ -91,4 +91,46 @@ function Relations.match_to_ref(relations, ref) return result end +function Relations.parse_route_relation(relation, obj) + local t = relation:get_value_by_key("type") + local role = relation:get_role(obj) + local result = {} + + function add_extra_data(m) + local name = relation:get_value_by_key("name") + if name then + result['route_name'] = name + end + + local ref = relation:get_value_by_key("ref") + if ref then + result['route_ref'] = ref + end + end + + if t == 'route' then + local route = relation:get_value_by_key("route") + if route == 'road' then + -- process case, where directions set as role + if role == 'north' or role == 'south' or role == 'west' or role == 'east' then + result['route_direction'] = role + add_extra_data(m) + end + end + + local direction = relation:get_value_by_key('direction') + if direction then + direction = string.lower(direction) + if direction == 'north' or direction == 'south' or direction == 'west' or direction == 'east' then + if role == 'forward' then + result['route_direction'] = direction + add_extra_data(m) + end + end + end + end + + return result +end + return Relations \ No newline at end of file diff --git a/unit_tests/mocks/mock_scripting_environment.hpp b/unit_tests/mocks/mock_scripting_environment.hpp index 216f0ae82..cdef7d737 100644 --- a/unit_tests/mocks/mock_scripting_environment.hpp +++ b/unit_tests/mocks/mock_scripting_environment.hpp @@ -29,6 +29,7 @@ class MockScriptingEnvironment : public extractor::ScriptingEnvironment std::vector GetNameSuffixList() override final { return {}; } std::vector> GetExcludableClasses() override final { return {}; }; std::vector GetClassNames() override { return {}; }; + std::vector GetRelations() override { return {}; }; std::vector GetRestrictions() override final { return {}; } void ProcessTurn(extractor::ExtractionTurn &) override final {} @@ -40,7 +41,6 @@ class MockScriptingEnvironment : public extractor::ScriptingEnvironment const extractor::ExtractionRelationContainer &, std::vector> &, std::vector> &, - std::vector> &, std::vector &) override final { }