From ce995454c61fbce7341c4459eee9f63e18bb4a1e Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Tue, 6 Feb 2018 14:15:46 -0800 Subject: [PATCH] Filter out slight/sharp modifiers, and fix stateful XML parsing bug. --- features/support/data.js | 12 ++++++------ package-lock.json | 15 +++++++++++++++ package.json | 1 + scripts/tests2doc.js | 38 +++++++++++++++++++++++++++++++------- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/features/support/data.js b/features/support/data.js index 3821b6159..956085918 100644 --- a/features/support/data.js +++ b/features/support/data.js @@ -12,9 +12,6 @@ const errorReason = require('../lib/utils').errorReason; const child_process = require('child_process'); -const osmtogeojson = require('osmtogeojson'); -const osmxmltojson = require('osmtogeojson/parse_osmxml'); - module.exports = function () { this.setGridSize = (meters) => { // the constant is calculated (with BigDecimal as: 1.0/(DEG_TO_RAD*EARTH_RADIUS_IN_METERS @@ -176,11 +173,14 @@ module.exports = function () { var q = d3.queue(1); q.defer(fs.writeFile, this.scenarioCacheFile, xml); - q.defer((cb) => { + q.defer((xml, cb) => { + delete require.cache[require.resolve('osmtogeojson/parse_osmxml')]; + var osmtogeojson = require('osmtogeojson'); + var osmxmltojson = require('osmtogeojson/parse_osmxml'); var json = osmxmltojson.parseFromString(xml); var geojson = osmtogeojson(json); - fs.writeFile(`${this.scenarioCacheFile}.geojson`,JSON.stringify(geojson),cb); - }); + fs.writeFile(`${this.scenarioCacheFile}.geojson`, JSON.stringify(geojson), cb); + }, xml); var params = ['cat',this.scenarioCacheFile,'-O','-o',this.scenarioCacheFilePBF, '--no-progress']; q.defer(child_process.execFile,'/usr/local/bin/osmium', params, {maxBuffer: 1024 * 1024 * 1000, env: {}}); diff --git a/package-lock.json b/package-lock.json index 1979c1e37..35d44aa3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13062,6 +13062,21 @@ "lodash": "4.17.4" } }, + "xmldoc": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/xmldoc/-/xmldoc-1.1.0.tgz", + "integrity": "sha1-JckvCPJj80TayNCzI3CnAe6dDpM=", + "requires": { + "sax": "1.2.4" + }, + "dependencies": { + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + } + } + }, "xmldom": { "version": "0.1.27", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz", diff --git a/package.json b/package.json index 4ebfa04b9..530c48ffb 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "node-pre-gyp": "^0.6.36", "osmtogeojson": "^3.0.0-beta.3" "rimraf": "^2.5.4" + "xmldoc": "^1.1.0" }, "browserify": { "transform": [ diff --git a/scripts/tests2doc.js b/scripts/tests2doc.js index dfbb42cfc..291bb4142 100644 --- a/scripts/tests2doc.js +++ b/scripts/tests2doc.js @@ -73,6 +73,22 @@ var stylesheet = ` 'highway=' + [highway] + + [highway] = 'secondary' or [highway] = 'secondary_link' or [highway] = 'tertiary' or [highway] = 'tertiary_link' or [highway] = 'residential' or [highway] = 'service' or [highway] = 'living_street' + + + 'name=' + [name] + 'highway=' + [highway] + + + + [route] = 'ferry' + + + 'name=' + [name] + 'route=' + [route] + + @@ -136,18 +152,24 @@ find('test/cache').filter((f) => f.match(/[0-9]+_results.json$/)).forEach((f) => var results = JSON.parse(fs.readFileSync(f)); - - // Generate map image - - var imagefile = `${files[1]}_${files[2]}`.replace(/\//g,'_'); - + var imagefile = `${files[1]}_${files[2]}.png`.replace(/\//g,'_'); + /* var png = makemappng(`${files[1]}.geojson`, `${files[1]}_${files[2]}_shape.geojson`, (png) => { fs.writeFileSync(`report/${imagefile}`,png); }); + */ toc.push({ title: `${results.feature} - ${results.scenario}`, link: imagefile }); + if (typeof results.got.turns === 'object') + results.got.turns = results.got.turns.join(','); + + if (typeof results.expected.turns === 'string') + results.expected.turns = results.expected.turns.replace(/slight /g,'').replace(/sharp /g, ''); + if (typeof results.got.turns === 'string') + results.got.turns = results.got.turns.replace(/slight /g,'').replace(/sharp /g, ''); + report += `

${results.feature} - ${results.scenario}

@@ -158,8 +180,8 @@ find('test/cache').filter((f) => f.match(/[0-9]+_results.json$/)).forEach((f) =>
- - + +
RouteTurns
Expected${results.expected.route}${results.expected.turns}
Got${results.got.route}${results.got.turns}
OSRM${results.expected.route}${results.expected.turns}
Valhalla${results.got.route}${results.got.turns}
@@ -182,6 +204,8 @@ console.log(` .error { color: red; } +Notes: OSRM "slight" and "sharp" indicators have been removed for comparison purposes. +
`); toc.forEach(r => { console.log(`${r.title}
`);