From c7e30e2266309081982f31283d15029c3d97adb2 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Fri, 13 Nov 2015 17:57:07 -0500 Subject: [PATCH] Add a summary to each match result showing distance and duration. Helpful for comparing how long the routing engine thinks the matched trace should take to travel. --- features/step_definitions/matching.rb | 4 +++ features/testbot/matching_turns.feature | 37 ++++++++++++++++++++++++- plugins/match.hpp | 6 ++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/features/step_definitions/matching.rb b/features/step_definitions/matching.rb index 3015f5a43..b82051949 100644 --- a/features/step_definitions/matching.rb +++ b/features/step_definitions/matching.rb @@ -156,6 +156,7 @@ When /^I match with turns I should get$/ do |table| modes = mode_list json['matchings'][0]['instructions'] times = time_list json['matchings'][0]['instructions'] distances = distance_list json['matchings'][0]['instructions'] + summary = json['matchings'][0]['route_summary'] end end @@ -168,6 +169,9 @@ When /^I match with turns I should get$/ do |table| if table.headers.include? '#' # comment column got['#'] = row['#'] # copy value so it always match end + if table.headers.include? 'duration' + got['duration'] = "#{summary["total_time"]}" + end sub_matchings = [] if response.code == "200" diff --git a/features/testbot/matching_turns.feature b/features/testbot/matching_turns.feature index 2d0a55820..58ed7d587 100644 --- a/features/testbot/matching_turns.feature +++ b/features/testbot/matching_turns.feature @@ -79,4 +79,39 @@ Feature: Turn directions/codes | gm | xg,xm | head,slight_left,destination | gm | | go | xg,xo | head,straight,destination | go | | ga | xg,xa | head,slight_right,destination | ga | - | gc | xg,xc | head,right,destination | gc | \ No newline at end of file + | gc | xg,xc | head,right,destination | gc | + + Scenario: Turn directions + Given the node map + | o | p | a | b | c | + | n | | | | d | + | m | | x | | e | + | l | | | | f | + | k | j | i | h | g | + + And the ways + | nodes | + | xa | + | xb | + | xc | + | xd | + | xe | + | xf | + | xg | + | xh | + | xi | + | xj | + | xk | + | xl | + | xm | + | xn | + | xo | + | xp | + + When I match with turns I should get + | trace | route | turns | matchings | duration | + | im | xi,xm | head,left,destination | im | 80 | + | io | xi,xo | head,slight_left,destination | io | 88 | + | ia | xi,xa | head,straight,destination | ia | 80 | + | ic | xi,xc | head,slight_right,destination | ic | 88 | + | ie | xi,xe | head,right,destination | ie | 60 | diff --git a/plugins/match.hpp b/plugins/match.hpp index 55a8c1404..978c27376 100644 --- a/plugins/match.hpp +++ b/plugins/match.hpp @@ -238,6 +238,12 @@ template class MapMatchingPlugin : public BasePlugin subtrace.values["instructions"] = json_descriptor.BuildTextualDescription(factory, temp_segments); } + factory.BuildRouteSummary(factory.get_entire_length(), + raw_route.shortest_path_length); + osrm::json::Object json_route_summary; + json_route_summary.values["total_distance"] = factory.summary.distance; + json_route_summary.values["total_time"] = factory.summary.duration; + subtrace.values["route_summary"] = json_route_summary; } subtrace.values["indices"] = osrm::json::make_array(sub.indices);