Skip to content

Commit

Permalink
Updated data for export-test with more recent brouter-app
Browse files Browse the repository at this point in the history
  • Loading branch information
tbsmark86 committed Dec 8, 2024
1 parent 18e6511 commit 7ec3735
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 149 deletions.
68 changes: 51 additions & 17 deletions tests/control/Export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,64 @@ const fs = require('fs');
const indexHtmlString = fs.readFileSync('index.html', 'utf8');
const indexHtml = new DOMParser().parseFromString(indexHtmlString, 'text/html');

// &lonlats=8.467712,49.488117;8.469354,49.488394;8.470556,49.488946;8.469982,49.489176 + turnInstructionMode=2
// Geojson results created by server for
// * lonlats=8.467712,49.488117;8.469354,49.488394;8.470556,49.488946;8.469982,49.489176
// * with turnInstructionMode=2
//
// a) Each segment separate
// * curl "https://brouter.de/brouter?lonlats=8.467712,49.488117|8.469354,49.488394&profile=trekking&alternativeidx=0&format=geojson&profile:turnInstructionMode=2"
// * repeated for each segment and copied together
const segments = require('./data/segments.json');
// b) All segments in a single request
// * curl "https://brouter.de/brouter?lonlats=8.467712,49.488117|8.469354,49.488394|8.470556,49.488946|8.469982,49.489176&profile=trekking&alternativeidx=0&format=geojson&profile:turnInstructionMode=2" > ./data/segments.json
const brouterTotal = require('./data/brouterTotal.json');

// fix turn instruction distance
// This is buggy on the backend when request a route with a waypoint
brouterTotal.features[0].properties.voicehints[0][3] += 53;
brouterTotal.features[0].properties.voicehints[2][3] += 49;
function allowRoundigDifference(obj, field, client, brouter) {
if (obj[field] === client) {
obj[field] = brouter;
}
}

// resolve intended/accepted differences before comparing
function adopt(total, brouterTotal) {
// BRouter total aggregates messages over segments, client total does not,
// but that's Ok, so just fix for the test comparison
const messages = total.features[0].properties.messages;
const message = messages[4].slice();
messages[4] = message;
message[3] = (+message[3] + +messages[2][3] + +messages[3][3]).toString();
message[6] = (+message[6] + +messages[2][6] + +messages[3][6]).toString();
messages.splice(2, 2);

// fix minor float rounding difference
total.features[0].properties.times[6] = 28.833; // 28.832

total.features[0].properties.name = brouterTotal.features[0].properties.name;
let messages = total.features[0].properties.messages;

// Time & Energy are totals: Client restart those at segment boundary
let offsetTime = 0,
offsetEnergy = 0;
for (let i = 1; i < messages.length; i++) {
// 3 - distance, 9 - WayTags, 11 - Time, 12 - Energy
let message = messages[i].slice();
messages[i] = message;
if (message[9] === messages[i - 1][9]) {
messages[i - 1][3] = (+message[3] + +messages[i - 1][3]).toString();
offsetTime = +messages[i - 1][11];
messages[i - 1][11] = (+message[11] + +messages[i - 1][11]).toString();
offsetEnergy = +messages[i - 1][12];
messages[i - 1][12] = (+message[12] + +messages[i - 1][12]).toString();
messages.splice(i, 1);
i--;
} else {
message[11] = (+message[11] + offsetTime).toString();
message[12] = (+message[12] + offsetEnergy).toString();
}
}

allowRoundigDifference(total.features[0].properties, 'total-energy', '6835', '6837');
allowRoundigDifference(total.features[0].properties, 'total-time', '69', '68');
allowRoundigDifference(total.features[0].properties, 'filtered ascend', '3', '2');
allowRoundigDifference(total.features[0].properties, 'plain-ascend', '2', '-1');

allowRoundigDifference(total.features[0].properties.messages[2], 11, '41', '42');
allowRoundigDifference(total.features[0].properties.messages[2], 12, '4201', '4202');
allowRoundigDifference(total.features[0].properties.messages[3], 11, '57', '58');
allowRoundigDifference(total.features[0].properties.messages[3], 12, '5817', '5818');
allowRoundigDifference(total.features[0].properties.messages[4], 11, '66', '68');
allowRoundigDifference(total.features[0].properties.messages[4], 12, '6835', '6837');

allowRoundigDifference(total.features[0].properties.times, 7, 58.182, 58.183);
}

let track;
Expand Down Expand Up @@ -79,7 +113,7 @@ test('hint distance fix', () => {
// special case: second segment without hint
segmentsCopy[1].feature.properties.voicehints = null;
let total = BR.Export._concatTotalTrack(segmentsCopy);
expect(total.features[0].properties.voicehints[0][3]).toEqual(299);
expect(total.features[0].properties.voicehints[0][3]).toEqual(294);
});

test('include route points', () => {
Expand Down
87 changes: 44 additions & 43 deletions tests/control/data/brouterTotal.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"creator": "BRouter-1.1",
"name": "brouter_1615489279610_0",
"track-length": "388",
"filtered ascend": "1",
"plain-ascend": "0",
"total-time": "44",
"total-energy": "4420",
"cost": "703",
"voicehints": [
[1,5,0,88.0,89],
[6,2,0,99.0,-90],
[7,2,0,10.0,-90]
],
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags"],
["8468340", "49488794", "101", "89", "1000", "0", "0", "0", "0", "highway=residential surface=asphalt cycleway=lane oneway=yes lcn=yes smoothness=good route_bicycle_icn=yes route_bicycle_ncn=yes route_bicycle_rcn=yes", ""],
["8469852", "49489230", "100", "299", "1150", "0", "270", "0", "0", "highway=residential surface=asphalt oneway=yes smoothness=good", ""]
],
"times": [0,9.592,12.271,14.13,19.406,22.134,28.833,37.817,38.938,44.217]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.467714, 49.488115, 101.5],
[8.468340, 49.488794, 101.5],
[8.468586, 49.488698, 101.5],
[8.468743, 49.488636, 101.5],
[8.469161, 49.488473, 101.75],
[8.469355, 49.488395, 102.0],
[8.469971, 49.488151, 103.5],
[8.470671, 49.488909, 99.5],
[8.470561, 49.488951, 99.5],
[8.469984, 49.489178, 100.0]
]
}
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"creator": "BRouter-1.7.0",
"name": "brouter_trekking_0",
"track-length": "382",
"filtered ascend": "2",
"plain-ascend": "-1",
"total-time": "68",
"total-energy": "6837",
"cost": "696",
"voicehints": [
[1,5,0,138.0,89],
[6,2,0,98.0,-90],
[7,2,0,58.0,-90]
],
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags", "Time", "Energy"],
["8468340", "49488794", "101", "88", "1000", "0", "0", "0", "0", "highway=residential surface=asphalt oneway=yes lcn=yes cycleway:right=lane cycleway:left=no smoothness=good route_bicycle_icn=yes route_bicycle_rcn=yes", "", "14", "1478"],
["8469971", "49488151", "103", "138", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes oneway:bicycle=no smoothness=good", "", "42", "4202"],
["8470671", "49488909", "99", "98", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes smoothness=good", "", "58", "5818"],
["8469935", "49489198", "100", "58", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes oneway:bicycle=no smoothness=good", "", "68", "6837"]
],
"times": [0,14.784,18.312,20.496,26.725,29.906,42.02,58.183,59.679,68.367]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.467714, 49.488114, 101.5],
[8.468340, 49.488794, 101.5],
[8.468586, 49.488698, 101.5],
[8.468743, 49.488636, 101.5],
[8.469161, 49.488473, 101.75],
[8.469355, 49.488395, 103.5],
[8.469971, 49.488151, 103.5],
[8.470671, 49.488909, 99.5],
[8.470561, 49.488951, 100.0],
[8.469984, 49.489178, 100.0]
]
}
]
}
}
]
}
179 changes: 90 additions & 89 deletions tests/control/data/segments.json
Original file line number Diff line number Diff line change
@@ -1,97 +1,98 @@
[{
"feature": {
"type": "Feature",
"properties": {
"creator": "BRouter-1.1",
"name": "brouter_1615393581719_0",
"track-length": "177",
"filtered ascend": "0",
"plain-ascend": "1",
"total-time": "22",
"total-energy": "2213",
"cost": "280",
"voicehints": [
[1,5,0,88.0,89]
],
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags"],
["8468340", "49488794", "101", "89", "1000", "0", "0", "0", "0", "highway=residential surface=asphalt cycleway=lane oneway=yes lcn=yes smoothness=good route_bicycle_icn=yes route_bicycle_ncn=yes route_bicycle_rcn=yes", ""],
["8469971", "49488151", "102", "88", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes smoothness=good", ""]
],
"times": [0,9.592,12.271,14.13,19.406,22.134]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.467714, 49.488115, 101.5],
[8.468340, 49.488794, 101.5],
[8.468586, 49.488698, 101.5],
[8.468743, 49.488636, 101.5],
[8.469161, 49.488473, 101.75],
[8.469355, 49.488395, 102.0]
]
}
"feature": {
"type": "Feature",
"properties": {
"creator": "BRouter-1.7.0",
"name": "brouter_trekking_0",
"track-length": "174",
"filtered ascend": "2",
"plain-ascend": "2",
"total-time": "30",
"total-energy": "2990",
"cost": "277",
"voicehints": [
[1,5,0,86.0,89]
],
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags", "Time", "Energy"],
["8468340", "49488794", "101", "88", "1000", "0", "0", "0", "0", "highway=residential surface=asphalt oneway=yes lcn=yes cycleway:right=lane cycleway:left=no smoothness=good route_bicycle_icn=yes route_bicycle_rcn=yes", "", "14", "1478"],
["8469971", "49488151", "103", "86", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes oneway:bicycle=no smoothness=good", "", "29", "2990"]
],
"times": [0,14.784,18.312,20.496,26.725,29.906]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.467714, 49.488114, 101.5],
[8.468340, 49.488794, 101.5],
[8.468586, 49.488698, 101.5],
[8.468743, 49.488636, 101.5],
[8.469161, 49.488473, 101.75],
[8.469355, 49.488395, 103.5]
]
}
}
},
{
"feature": {
"type": "Feature",
"properties": {
"creator": "BRouter-1.1",
"name": "brouter_1615393581719_0",
"track-length": "162",
"filtered ascend": "1",
"plain-ascend": "-2",
"total-time": "17",
"total-energy": "1680",
"cost": "367",
"voicehints": [
[1,2,0,99.0,-90],
[2,2,0,10.0,-90]
],
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags"],
["8469852", "49489230", "99", "162", "1150", "0", "180", "0", "0", "highway=residential surface=asphalt oneway=yes smoothness=good", ""]
],
"times": [0,6.698,15.683,16.804]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.469355, 49.488395, 102.0],
[8.469971, 49.488151, 103.5],
[8.470671, 49.488909, 99.5],
[8.470561, 49.488951, 99.5]
]
}
"feature": {
"type": "Feature",
"properties": {
"creator": "BRouter-1.7.0",
"name": "brouter_trekking_0",
"track-length": "159",
"filtered ascend": "1",
"plain-ascend": "-1",
"total-time": "30",
"total-energy": "2977",
"cost": "363",
"voicehints": [
[1,2,0,98.0,-90],
[2,2,0,9.0,-90]
],
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags", "Time", "Energy"],
["8469971", "49488151", "103", "52", "1150", "0", "0", "0", "0", "highway=residential surface=asphalt oneway=yes oneway:bicycle=no smoothness=good", "", "12", "1211"],
["8470671", "49488909", "99", "98", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes smoothness=good", "", "28", "2827"],
["8469935", "49489198", "100", "9", "1150", "0", "90", "0", "0", "highway=residential surface=asphalt oneway=yes oneway:bicycle=no smoothness=good", "", "29", "2977"]
],
"times": [0,12.114,28.276,29.773]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.469355, 49.488395, 102.0],
[8.469971, 49.488151, 103.5],
[8.470671, 49.488909, 99.5],
[8.470561, 49.488951, 100.0]
]
}
}

},
{
"feature": {
"type": "Feature",
"properties": {
"creator": "BRouter-1.1",
"name": "brouter_1615393581719_0",
"track-length": "49",
"filtered ascend": "0",
"plain-ascend": "1",
"total-time": "5",
"total-energy": "527",
"cost": "56",
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags"],
["8469852", "49489230", "100", "49", "1150", "0", "0", "0", "0", "highway=residential surface=asphalt oneway=yes smoothness=good", ""]
],
"times": [0,5.279]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.470561, 49.488951, 99.5],
[8.469984, 49.489178, 100.0]
]
}
}
"feature": {
"type": "Feature",
"properties": {
"creator": "BRouter-1.7.0",
"name": "brouter_trekking_0",
"track-length": "49",
"filtered ascend": "0",
"plain-ascend": "1",
"total-time": "9",
"total-energy": "868",
"cost": "56",
"messages": [
["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags", "Time", "Energy"],
["8469935", "49489198", "100", "49", "1150", "0", "0", "0", "0", "highway=residential surface=asphalt oneway=yes oneway:bicycle=no smoothness=good", "", "8", "868"]
],
"times": [0,8.688]
},
"geometry": {
"type": "LineString",
"coordinates": [
[8.470561, 49.488951, 99.5],
[8.469984, 49.489178, 100.0]
]
}
}
}
]
]

0 comments on commit 7ec3735

Please sign in to comment.