Skip to content

Commit

Permalink
Add new datasource_names annotation that returns the string version…
Browse files Browse the repository at this point in the history
… of the `datasources` annotation
  • Loading branch information
danpat committed Mar 23, 2018
1 parent bc980e7 commit 52eb986
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- ADDED: Add documentation about OSM node ids in nearest service response [#4436](https://github.com/Project-OSRM/osrm-backend/pull/4436)
- Performance
- FIXED: Speed up response time when lots of legs exist and geojson is used with `steps=true` [#4936](https://github.com/Project-OSRM/osrm-backend/pull/4936)
- Misc:
- ADDED: support for new `datasource_names` annotation [#4973](https://github.com/Project-OSRM/osrm-backend/pull/4973)

# 5.16.0
- Changes from 5.15.2:
Expand Down
11 changes: 7 additions & 4 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ In addition to the [general options](#general-options) the following options are
|------------|---------------------------------------------|-------------------------------------------------------------------------------|
|alternatives|`true`, `false` (default), or Number |Search for alternative routes. Passing a number `alternatives=n` searches for up to `n` alternative routes.\* |
|steps |`true`, `false` (default) |Returned route steps for each route leg |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed` |Returns additional metadata for each coordinate along the route geometry. |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed`, `datasource_names` |Returns additional metadata for each coordinate along the route geometry. |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.|
|continue\_straight |`default` (default), `true`, `false` |Forces the route to keep going straight at waypoints constraining uturns there even if it would be faster. Default value depends on the profile. |
Expand Down Expand Up @@ -295,7 +295,7 @@ In addition to the [general options](#general-options) the following options are
|------------|------------------------------------------------|------------------------------------------------------------------------------------------|
|steps |`true`, `false` (default) |Returned route steps for each route |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed` |Returns additional metadata for each coordinate along the route geometry. |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed`, `datasource_names` |Returns additional metadata for each coordinate along the route geometry. |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.|
|timestamps |`{timestamp};{timestamp}[;{timestamp} ...]` |Timestamps for the input locations in seconds since UNIX epoch. Timestamps need to be monotonically increasing. |
|radiuses |`{radius};{radius}[;{radius} ...]` |Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy.|
Expand Down Expand Up @@ -351,7 +351,7 @@ In addition to the [general options](#general-options) the following options are
|source |`any` (default), `first` |Returned route starts at `any` or `first` coordinate |
|destination |`any` (default), `last` |Returned route ends at `any` or `last` coordinate |
|steps |`true`, `false` (default) |Returned route instructions for each trip |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed` |Returns additional metadata for each coordinate along the route geometry. |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed`, `datasource_names` |Returns additional metadata for each coordinate along the route geometry. |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.|

Expand Down Expand Up @@ -547,6 +547,7 @@ With `steps=false` and `annotations=true`:
"distance": [5,5,10,5,5],
"duration": [15,15,40,15,15],
"datasources": [1,0,0,0,1],
"datasource_names": ["traffic","lua profile","lua profile","lua profile","traffic"],
"nodes": [49772551,49772552,49786799,49786800,49786801,49786802],
"speed": [0.3, 0.3, 0.3, 0.3, 0.3]
}
Expand All @@ -561,7 +562,8 @@ Annotation of the whole route leg with fine-grained information about each segme

- `distance`: The distance, in metres, between each pair of coordinates
- `duration`: The duration between each pair of coordinates, in seconds. Does not include the duration of any turns.
- `datasources`: The index of the datasource for the speed between each pair of coordinates. `0` is the default profile, other values are supplied via `--segment-speed-file` to `osrm-contract`
- `datasources`: The index of the datasource for the speed between each pair of coordinates. `0` is the default profile, other values are supplied via `--segment-speed-file` to `osrm-contract` or `osrm-customize`
- `datasource_names`: The names of the datasources used for the speed between each pair of coordinates. `lua profile` is the default profile, other values arethe filenames supplied via `--segment-speed-file` to `osrm-contract` or `osrm-customize`
- `nodes`: The OSM node ID for each coordinate along the route, excluding the first/last user-supplied coordinates
- `weight`: The weights between each pair of coordinates. Does not include any turn costs.
- `speed`: Convenience field, calculation of `distance / duration` rounded to one decimal place
Expand All @@ -573,6 +575,7 @@ Annotation of the whole route leg with fine-grained information about each segme
"distance": [5,5,10,5,5],
"duration": [15,15,40,15,15],
"datasources": [1,0,0,0,1],
"datasource_names": ["traffic","lua profile","lua profile","lua profile","traffic"],
"nodes": [49772551,49772552,49786799,49786800,49786801,49786802],
"weight": [15,15,40,15,15]
}
Expand Down
2 changes: 1 addition & 1 deletion features/support/shared_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ module.exports = function () {
// if header matches 'a:*', parse out the values for *
// and return in that header
headers.forEach((k) => {
let whitelist = ['duration', 'distance', 'datasources', 'nodes', 'weight', 'speed'];
let whitelist = ['duration', 'distance', 'datasources', 'nodes', 'weight', 'speed', 'datasource_names'];
if (k.match(/^a:/)) {
let a_type = k.slice(2);
if (whitelist.indexOf(a_type) == -1)
Expand Down
33 changes: 33 additions & 0 deletions features/testbot/annotations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ Feature: Annotations
| a | i | abcdefghi,abcdefghi | 1:0:1:0:1:0:0:0 | 50:10:50:10:50:10:10:10 |
| i | a | abcdefghi,abcdefghi | 0:1:0:0:0:0:0:1 | 10:50:10:10:10:10:10:50 |

Scenario: datasource name annotations
Given the profile "testbot"

And the node map
"""
a b c
"""

And the ways
| nodes |
| abc |

And the contract extra arguments "--segment-speed-file {speeds_file}"
And the customize extra arguments "--segment-speed-file {speeds_file}"

And the speed file
"""
1,2,180,1
2,1,180,1
"""

And the query options
| annotations | datasource_names |

# Note - the source names here are specific to how the tests are constructed,
# so if this test is moved around (changes line number) or support code
# changes how the filenames are generated, this test will need to be updated
When I route I should get
| from | to | route | a:datasource_names |
| a | c | abc,abc | 63_datasource_name_annotations_speeds:lua profile |
| c | a | abc,abc | lua profile:63_datasource_name_annotations_speeds |


Scenario: Speed annotations should handle zero segments
Given the profile "testbot"

Expand Down
7 changes: 7 additions & 0 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ class RouteAPI : public BaseAPI
}
annotation.values["nodes"] = std::move(nodes);
}
if (requested_annotations & RouteParameters::AnnotationsType::DatasourceNames)
{
annotation.values["datasource_names"] = GetAnnotations(
leg_geometry, [&](const guidance::LegGeometry::Annotation &anno) {
return std::string(facade.GetDatasourceName(anno.datasource));
});
}

annotations.push_back(std::move(annotation));
}
Expand Down
3 changes: 2 additions & 1 deletion include/engine/api/route_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct RouteParameters : public BaseParameters
Weight = 0x08,
Datasources = 0x10,
Speed = 0x20,
All = Duration | Nodes | Distance | Weight | Datasources | Speed
DatasourceNames = 0x40,
All = Duration | Nodes | Distance | Weight | Datasources | Speed | DatasourceNames
};

RouteParameters() = default;
Expand Down
8 changes: 4 additions & 4 deletions include/server/api/route_parameters_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
"full", engine::api::RouteParameters::OverviewType::Full)(
"false", engine::api::RouteParameters::OverviewType::False);

annotations_type.add("duration", AnnotationsType::Duration)("nodes",
AnnotationsType::Nodes)(
"distance", AnnotationsType::Distance)("weight", AnnotationsType::Weight)(
"datasources", AnnotationsType::Datasources)("speed", AnnotationsType::Speed);
annotations_type.add("duration", AnnotationsType::Duration)(
"nodes", AnnotationsType::Nodes)("distance", AnnotationsType::Distance)(
"weight", AnnotationsType::Weight)("datasources", AnnotationsType::Datasources)(
"speed", AnnotationsType::Speed)("datasource_names", AnnotationsType::DatasourceNames);

base_rule =
BaseGrammar::base_rule(qi::_r1) |
Expand Down

0 comments on commit 52eb986

Please sign in to comment.