update support code to handle variable annotations fields

This commit is contained in:
karenzshea 2017-01-30 18:56:43 +01:00 committed by Patrick Niklaus
parent 3106b5dd9e
commit 7256b6d0d4
3 changed files with 73 additions and 18 deletions

View File

@ -164,20 +164,23 @@ module.exports = function () {
};
this.annotationList = (instructions) => {
if (!('annotation' in instructions.legs[0]))
if (!('annotation' in instructions.legs[0]) || instructions.legs[0].annotation.length < 1)
return '';
function zip(list_1, list_2, list_3, list_4)
{
let tuples = [];
for (let i = 0; i < list_1.length; ++i) {
tuples.push([list_1[i], list_2[i], list_3[i], list_4[i]]);
}
return tuples;
}
return instructions.legs.map(l => {
const values = zip( l.annotation.weight, l.annotation.duration, l.annotation.distance, l.annotation.datasources);
return values.map(p => { return p.join(':'); }).join(',');
var fields = Object.keys(l.annotation);
if (fields.length < 1) return '';
var collected = l.annotation[fields[0]].map((f, i) => {
var zipped = [];
for (var j = 0; j < fields.length; j++) {
zipped.push(l.annotation[fields[j]][i]);
}
return zipped;
});
return collected.map((v) => {
return v.join(':');
}).join(',');
}).join(',');
};

View File

@ -118,6 +118,32 @@ Feature: Basic Map Matching
| dcba | hgfe |
| efgh | abcd |
Scenario: Testbot - request duration annotations
Given the query options
| annotations | duration |
Given the node map
"""
a b c d e g h
i
"""
And the ways
| nodes | oneway |
| abcdegh | no |
| ci | no |
And the speed file
"""
1,2,36
"""
And the contract extra arguments "--segment-speed-file {speeds_file}"
When I match I should get
| trace | matchings | annotation |
| ach | ach | 1:1,0:1:1:2:1 |
Scenario: Testbot - Duration details
Given the query options
| annotations | true |
@ -337,3 +363,29 @@ Feature: Basic Map Matching
| trace | OSM IDs |
| 12 | 1,2,3,4,5,6 |
| 21 | 6,5,4,3,2,1 |
Scenario: Testbot - return annotations based on parameter
Given the query options
| annotations | duration,weight |
Given the node map
"""
a - b
|
c
"""
And the nodes
| node | id |
| a | 1 |
| b | 2 |
| c | 3 |
And the ways
| nodes | oneway |
| abc | no |
When I match I should get
| trace | annotation |
| ac | 2:2,2:2 |
| ca | 2:2:0,2:2:0 |

View File

@ -29,8 +29,8 @@ Feature: Weight tests
| cde |
When I route I should get
| waypoints | route | annotation |
| s,t | abc,cde,cde | 1.1:1.1:10.008843:0,2:2:20.017686:0,2:2:20.020734:0,1:1:10.010367:0 |
| waypoints | route | annotation |
| s,t | abc,cde,cde | 1.1:10.008843:1.1:2:0,2:20.017686:2:3:0,2:20.020734:2:4:0,1:10.010367:1:5:0 |
When I route I should get
| waypoints | route | times | weight_name | weights |
@ -53,11 +53,11 @@ Feature: Weight tests
| abc |
When I route I should get
| waypoints | route | distances | weights | times | annotation |
| s,t | abc,abc | 20m,0m | 2.1,0 | 2.1s,0s | 3:3:20.017685:0 |
| t,s | abc,abc | 20m,0m | 2.1,0 | 2.1s,0s | 3.1:3.1:20.017685:0 |
| s,e | abc,abc | 40m,0m | 4.1,0 | 4.1s,0s | 3.1:3.1:30.026527:0,1:1:10.008842:0 |
| e,s | abc,abc | 40m,0m | 4.1,0 | 4.1s,0s | 1:1:10.008842:0,3.1:3.1:30.026527:0 |
| waypoints | route | distances | weights | times | annotation |
| s,t | abc,abc | 20m,0m | 2.1,0 | 2.1s,0s | 3:20.017685:3:1:0 |
| t,s | abc,abc | 20m,0m | 2.1,0 | 2.1s,0s | 3.1:20.017685:3.1:2:0 |
| s,e | abc,abc | 40m,0m | 4.1,0 | 4.1s,0s | 3.1:30.026527:3.1:1:0,1:10.008842:1:2:0 |
| e,s | abc,abc | 40m,0m | 4.1,0 | 4.1s,0s | 1:10.008842:1:3:0,3.1:30.026527:3.1:2:0 |
Scenario: Step weights -- way_function: fail if no weight or weight_per_meter property