refactor match service response

This commit is contained in:
Antoine GIRET 2018-07-13 15:01:09 +02:00
parent f928956584
commit 595a1acaed
8 changed files with 34 additions and 31 deletions

View File

@ -1,5 +1,8 @@
# UNRELEASED # UNRELEASED
- Changes from 5.18.0: - Changes from 5.18.0:
- API:
- CHANGED: refactor property `matchings_index` to `matching_index` in `tracepoints` object of `match` service response
- CHANGED: refactor property `waypoint_index` to `leg_index` in `tracepoints` object of `match` service response
- Bugfixes: - Bugfixes:
- FIXED: collapsing of ExitRoundabout instructions [#5114](https://github.com/Project-OSRM/osrm-backend/issues/5114) - FIXED: collapsing of ExitRoundabout instructions [#5114](https://github.com/Project-OSRM/osrm-backend/issues/5114)

View File

@ -428,8 +428,8 @@ The area to search is chosen such that the correct candidate should be considere
- `tracepoints`: Array of `Waypoint` objects representing all points of the trace in order. - `tracepoints`: Array of `Waypoint` objects representing all points of the trace in order.
If the trace point was ommited by map matching because it is an outlier, the entry will be `null`. If the trace point was ommited by map matching because it is an outlier, the entry will be `null`.
Each `Waypoint` object has the following additional properties: Each `Waypoint` object has the following additional properties:
- `matchings_index`: Index to the `Route` object in `matchings` the sub-trace was matched to. - `matching_index`: Index to the `Route` object in `matchings` the sub-trace was matched to.
- `waypoint_index`: Index of the waypoint inside the matched route. - `leg_index`: Index to the `Leg` object inside the matched route.
- `alternatives_count`: Number of probable alternative matchings for this trace point. A value of zero indicate that this point was matched unambiguously. Split the trace at these points for incremental map matching. - `alternatives_count`: Number of probable alternative matchings for this trace point. A value of zero indicate that this point was matched unambiguously. Split the trace at these points for incremental map matching.
- `matchings`: An array of `Route` objects that assemble the trace. Each `Route` object has the following additional properties: - `matchings`: An array of `Route` objects that assemble the trace. Each `Route` object has the following additional properties:
- `confidence`: Confidence of the matching. `float` value between 0 and 1. 1 is very confident that the matching is correct. - `confidence`: Confidence of the matching. `float` value between 0 and 1. 1 is very confident that the matching is correct.

View File

@ -224,9 +224,9 @@ osrm.match(options, function(err, response) {
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** containing `tracepoints` and `matchings`. Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** containing `tracepoints` and `matchings`.
**`tracepoints`** Array of [`Ẁaypoint`](#waypoint) objects representing all points of the trace in order. **`tracepoints`** Array of [`Ẁaypoint`](#waypoint) objects representing all points of the trace in order.
If the trace point was ommited by map matching because it is an outlier, the entry will be null. If the trace point was ommited by map matching because it is an outlier, the entry will be null.
Each `Waypoint` object includes two additional properties, 1) `matchings_index`: Index to the Each `Waypoint` object includes two additional properties, 1) `matching_index`: Index to the
[`Route`](#route) object in matchings the sub-trace was matched to, 2) `waypoint_index`: Index of [`Route`](#route) object in matchings the sub-trace was matched to, 2) `leg_index`: Index to the
the waypoint inside the matched route. [`Leg`](#leg) object inside the matched route.
**`matchings`** is an array of [`Route`](#route) objects that assemble the trace. Each `Route` object has an additional `confidence` property, **`matchings`** is an array of [`Route`](#route) objects that assemble the trace. Each `Route` object has an additional `confidence` property,
which is the confidence of the matching. float value between `0` and `1`. `1` is very confident that the matching is correct. which is the confidence of the matching. float value between `0` and `1`. `1` is very confident that the matching is correct.

View File

@ -59,7 +59,7 @@ module.exports = function () {
for(var i = start_index; i < json.tracepoints.length; i++){ for(var i = start_index; i < json.tracepoints.length; i++){
if (json.tracepoints[i] === null) continue; if (json.tracepoints[i] === null) continue;
let current_index = json.tracepoints[i].matchings_index; let current_index = json.tracepoints[i].matching_index;
if(prev_index !== current_index) { if(prev_index !== current_index) {
if (sub.length > 0) subMatchings.push(sub); if (sub.length > 0) subMatchings.push(sub);
@ -191,7 +191,7 @@ module.exports = function () {
var got_loc = []; var got_loc = [];
for (let i = 0; i < json.tracepoints.length; i++) { for (let i = 0; i < json.tracepoints.length; i++) {
if (!json.tracepoints[i]) continue; if (!json.tracepoints[i]) continue;
if (json.tracepoints[i].waypoint_index != null) if (json.tracepoints[i].leg_index != null)
got_loc.push(json.tracepoints[i].location); got_loc.push(json.tracepoints[i].location);
} }

View File

@ -116,8 +116,8 @@ class MatchAPI final : public RouteAPI
const auto &phantom = const auto &phantom =
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index]; sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
auto waypoint = BaseAPI::MakeWaypoint(phantom); auto waypoint = BaseAPI::MakeWaypoint(phantom);
waypoint.values["matchings_index"] = matching_index.sub_matching_index; waypoint.values["matching_index"] = matching_index.sub_matching_index;
waypoint.values["waypoint_index"] = matching_index.point_index; waypoint.values["leg_index"] = matching_index.point_index;
waypoint.values["alternatives_count"] = waypoint.values["alternatives_count"] =
sub_matchings[matching_index.sub_matching_index] sub_matchings[matching_index.sub_matching_index]
.alternatives_count[matching_index.point_index]; .alternatives_count[matching_index.point_index];
@ -127,12 +127,12 @@ class MatchAPI final : public RouteAPI
{ {
if (tidy_result.was_waypoint[trace_index]) if (tidy_result.was_waypoint[trace_index])
{ {
waypoint.values["waypoint_index"] = was_waypoint_idx; waypoint.values["leg_index"] = was_waypoint_idx;
was_waypoint_idx++; was_waypoint_idx++;
} }
else else
{ {
waypoint.values["waypoint_index"] = util::json::Null(); waypoint.values["leg_index"] = util::json::Null();
} }
} }
waypoints.values.push_back(std::move(waypoint)); waypoints.values.push_back(std::move(waypoint));

View File

@ -373,9 +373,9 @@ NAN_METHOD(Engine::tile)
* @returns {Object} containing `tracepoints` and `matchings`. * @returns {Object} containing `tracepoints` and `matchings`.
* **`tracepoints`** Array of [`aypoint`](#waypoint) objects representing all points of the trace in order. * **`tracepoints`** Array of [`aypoint`](#waypoint) objects representing all points of the trace in order.
* If the trace point was ommited by map matching because it is an outlier, the entry will be null. * If the trace point was ommited by map matching because it is an outlier, the entry will be null.
* Each `Waypoint` object includes two additional properties, 1) `matchings_index`: Index to the * Each `Waypoint` object includes two additional properties, 1) `matching_index`: Index to the
* [`Route`](#route) object in matchings the sub-trace was matched to, 2) `waypoint_index`: Index of * [`Route`](#route) object in matchings the sub-trace was matched to, 2) `leg_index`: Index to the
* the waypoint inside the matched route. * [`Leg`](#leg) object inside the matched route.
* **`matchings`** is an array of [`Route`](#route) objects that assemble the trace. Each `Route` object has an additional `confidence` property, * **`matchings`** is an array of [`Route`](#route) objects that assemble the trace. Each `Route` object has an additional `confidence` property,
* which is the confidence of the matching. float value between `0` and `1`. `1` is very confident that the matching is correct. * which is the confidence of the matching. float value between `0` and `1`. `1` is very confident that the matching is correct.
* *

View File

@ -20,7 +20,7 @@ test('match: match in Monaco', function(assert) {
})) }))
assert.equal(response.tracepoints.length, 3); assert.equal(response.tracepoints.length, 3);
assert.ok(response.tracepoints.every(function(t) { assert.ok(response.tracepoints.every(function(t) {
return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; return !!t.hint && !isNaN(t.matching_index) && !isNaN(t.leg_index) && !!t.name;
})); }));
}); });
}); });
@ -320,7 +320,7 @@ test('match: match in Monaco with waypoints', function(assert) {
})) }))
assert.equal(response.tracepoints.length, 3); assert.equal(response.tracepoints.length, 3);
assert.ok(response.tracepoints.every(function(t) { assert.ok(response.tracepoints.every(function(t) {
return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; return !!t.hint && !isNaN(t.matching_index) && !isNaN(t.leg_index) && !!t.name;
})); }));
}); });
}); });

View File

@ -45,17 +45,17 @@ BOOST_AUTO_TEST_CASE(test_match)
{ {
BOOST_CHECK(waypoint_check(waypoint)); BOOST_CHECK(waypoint_check(waypoint));
const auto &waypoint_object = waypoint.get<json::Object>(); const auto &waypoint_object = waypoint.get<json::Object>();
const auto matchings_index = const auto matching_index =
waypoint_object.values.at("matchings_index").get<json::Number>().value; waypoint_object.values.at("matching_index").get<json::Number>().value;
const auto waypoint_index = const auto leg_index =
waypoint_object.values.at("waypoint_index").get<json::Number>().value; waypoint_object.values.at("leg_index").get<json::Number>().value;
const auto &route_legs = matchings[matchings_index] const auto &route_legs = matchings[matching_index]
.get<json::Object>() .get<json::Object>()
.values.at("legs") .values.at("legs")
.get<json::Array>() .get<json::Array>()
.values; .values;
BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1); BOOST_CHECK_LT(leg_index, route_legs.size() + 1);
BOOST_CHECK_LT(matchings_index, number_of_matchings); BOOST_CHECK_LT(matching_index, number_of_matchings);
} }
else else
{ {
@ -95,18 +95,18 @@ BOOST_AUTO_TEST_CASE(test_match_split)
{ {
BOOST_CHECK(waypoint_check(waypoint)); BOOST_CHECK(waypoint_check(waypoint));
const auto &waypoint_object = waypoint.get<json::Object>(); const auto &waypoint_object = waypoint.get<json::Object>();
const auto matchings_index = const auto matching_index =
waypoint_object.values.at("matchings_index").get<json::Number>().value; waypoint_object.values.at("matching_index").get<json::Number>().value;
const auto waypoint_index = const auto leg_index =
waypoint_object.values.at("waypoint_index").get<json::Number>().value; waypoint_object.values.at("leg_index").get<json::Number>().value;
BOOST_CHECK_LT(matchings_index, number_of_matchings); BOOST_CHECK_LT(matching_index, number_of_matchings);
expected_waypoint_index = expected_waypoint_index =
(current_matchings_index != matchings_index) ? 0 : expected_waypoint_index; (current_matchings_index != matching_index) ? 0 : expected_waypoint_index;
BOOST_CHECK_EQUAL(waypoint_index, expected_waypoint_index); BOOST_CHECK_EQUAL(leg_index, expected_waypoint_index);
current_matchings_index = matchings_index; current_matchings_index = matching_index;
++expected_waypoint_index; ++expected_waypoint_index;
} }
else else