From f532912e6297525e2edf504ba9a6a1470ab6351e Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Tue, 6 Feb 2018 20:53:22 -0800 Subject: [PATCH] Make images bigger, fix buffering. Log request and responses. --- features/support/http.js | 7 +++- features/support/route.js | 19 +++++---- features/support/shared_steps.js | 7 +++- scripts/tests2doc.js | 67 +++++++++++++++++++------------- 4 files changed, 63 insertions(+), 37 deletions(-) diff --git a/features/support/http.js b/features/support/http.js index 9e3704f0b..41ec126ec 100644 --- a/features/support/http.js +++ b/features/support/http.js @@ -1,5 +1,6 @@ var Timeout = require('node-timeout'); var request = require('request'); +var fs = require('fs'); module.exports = function () { this.paramsToString = (params) => { @@ -22,14 +23,17 @@ module.exports = function () { // FIXME this needs to be simplified! // - remove usage of node-timeout // - replace with node's native timout mechanism - this.sendRequest = (baseUri, parameters, type, callback) => { + this.sendRequest = (baseUri, parameters, type, logfile, callback) => { var limit = Timeout(this.TIMEOUT, { err: { statusCode: 408 } }); var runRequest = (cb) => { if (type === 'GET') { + var params = this.paramsToString(parameters); this.query = baseUri + (params.length ? '/' + params : ''); + + if (logfile && typeof logfile !== 'function') fs.writeFileSync(logfile, `GET ${this.query}`); request(this.query, (err, res, body) => { if (err && err.code === 'ECONNREFUSED') { return cb(new Error('*** osrm-routed is not running.')); @@ -41,6 +45,7 @@ module.exports = function () { }); } else { this.query = baseUri; + if (logfile && typeof logfile !== 'function') fs.writeFileSync(logfile, `POST ${this.query}\n\n${JSON.stringify(parameters)}`); request.post(this.query, {body: JSON.stringify(parameters)}, (err, res, body) => { if (err && err.code === 'ECONNREFUSED') { return cb(new Error('*** osrm-routed is not running.')); diff --git a/features/support/route.js b/features/support/route.js index 6f59d315b..712b55a1a 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -5,7 +5,7 @@ const request = require('request'); const ensureDecimal = require('../lib/utils').ensureDecimal; module.exports = function () { - this.requestPath = (service, params, callback) => { + this.requestPath = (service, params, logfile, callback) => { var uri; if (service == 'timestamp' || this.osrmLoader.method === 'valhalla') { uri = [this.HOST, service].join('/'); @@ -13,7 +13,7 @@ module.exports = function () { uri = [this.HOST, service, 'v1', this.profile].join('/'); } - return this.sendRequest(uri, params, this.osrmLoader.method === 'valhalla' ? 'POST' : 'GET', callback); + return this.sendRequest(uri, params, this.osrmLoader.method === 'valhalla' ? 'POST' : 'GET', logfile, callback); }; this.requestUrl = (path, callback) => { @@ -46,7 +46,7 @@ module.exports = function () { return waypoints.map(w => [w.lon, w.lat].map(ensureDecimal).join(',')); }; - this.requestRoute = (waypoints, bearings, approaches, userParams, callback) => { + this.requestRoute = (waypoints, bearings, approaches, userParams, logfile, callback) => { if (bearings.length && bearings.length !== waypoints.length) throw new Error('*** number of bearings does not equal the number of waypoints'); if (approaches.length && approaches.length !== waypoints.length) throw new Error('*** number of approaches does not equal the number of waypoints'); @@ -82,7 +82,7 @@ module.exports = function () { } - return this.requestPath('route', params, callback); + return this.requestPath('route', params, logfile, callback); }; this.requestNearest = (node, userParams, callback) => { @@ -316,14 +316,19 @@ var typemap = { 25: {type: 'merge', modifier: null }, - 26: {type: 'roundabout', modifier: null }, - 27: {type: 'roundabout-exit', modifier: null }, + 26: {type: 'roundabout-exit', modifier: null }, + 27: {type: 'exit roundabout', modifier: null }, + + 28: {type: 'enter ferry', modifier: null }, + 29: {type: 'exit ferry', modifier: null } } return instructions.legs.reduce((m, v) => m.concat(v.maneuvers), []) .map(v => { if (v.type in typemap) { - if (typemap[v.type].modifier) { + if (v.type === 26) { // special construction for roundabout instructions + return `${typemap[v.type].type}-${v.roundabout_exit_count}`; + } else if (typemap[v.type].modifier) { return `${typemap[v.type].type} ${typemap[v.type].modifier}`; } else { return `${typemap[v.type].type}`; diff --git a/features/support/shared_steps.js b/features/support/shared_steps.js index 2682cbb42..253be94fd 100644 --- a/features/support/shared_steps.js +++ b/features/support/shared_steps.js @@ -95,6 +95,7 @@ module.exports = function () { } } fs.writeFileSync(`${this.scenarioCacheFile}_${rowIndex}_results.json`,JSON.stringify(resultdata)); + fs.writeFileSync(`${this.scenarioCacheFile}_${rowIndex}_response.json`,body); var geojson = { type: 'FeatureCollection', @@ -324,7 +325,9 @@ module.exports = function () { got.from = row.from; got.to = row.to; - this.requestRoute(waypoints, bearings, approaches, params, afterRequest); + + this.currentRowIndex = rowIndex; + this.requestRoute(waypoints, bearings, approaches, params, `${this.scenarioCacheFile}_${rowIndex}_request.txt`, afterRequest); } else if (row.waypoints) { row.waypoints.split(',').forEach((n) => { var node = this.findNodeByName(n.trim()); @@ -332,7 +335,7 @@ module.exports = function () { waypoints.push(node); }); got.waypoints = row.waypoints; - this.requestRoute(waypoints, bearings, approaches, params, afterRequest); + this.requestRoute(waypoints, bearings, approaches, params, `${this.scenarioCacheFile}_${rowIndex}_request.txt`, afterRequest); } else { return cb(new Error('*** no waypoints')); } diff --git a/scripts/tests2doc.js b/scripts/tests2doc.js index 291bb4142..6cfb6d027 100644 --- a/scripts/tests2doc.js +++ b/scripts/tests2doc.js @@ -32,61 +32,61 @@ var stylesheet = ` [highway] = 'motorway' - 'name=' + [name] - 'highway=' + [highway] + 'name=' + [name] + 'highway=' + [highway] [highway] = 'motorway_link' - 'name=' + [name] - 'highway=' + [highway] + 'name=' + [name] + 'highway=' + [highway] [highway] = 'trunk' - 'name=' + [name] - 'highway=' + [highway] + 'name=' + [name] + 'highway=' + [highway] [highway] = 'trunk_link' - 'name=' + [name] - 'highway=' + [highway] + 'name=' + [name] + 'highway=' + [highway] [highway] = 'primary' - 'name=' + [name] - 'highway=' + [highway] + 'name=' + [name] + 'highway=' + [highway] [highway] = 'primary_link' - 'name=' + [name] - 'highway=' + [highway] + 'name=' + [name] + '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] + 'name=' + [name] + 'highway=' + [highway] [route] = 'ferry' - 'name=' + [name] - 'route=' + [route] + 'name=' + [name] + 'route=' + [route] @@ -105,14 +105,14 @@ var stylesheet = ` - @@ -125,19 +125,19 @@ var stylesheet = ` `; - var map = new mapnik.Map(300, 200); + var map = new mapnik.Map(400, 300); map.fromStringSync(stylesheet,{strict:true}); map.zoomAll(); var extent = map.extent; - extent[0] = extent[0] - Math.abs(extent[0]) * 0.00001; - extent[1] = extent[1] - Math.abs(extent[1]) * 0.00001; + extent[0] = extent[0] - Math.abs(extent[0]) * 0.00005; + extent[1] = extent[1] - Math.abs(extent[1]) * 0.00005; - extent[2] = extent[2] + Math.abs(extent[2]) * 0.00001; - extent[3] = extent[3] + Math.abs(extent[3]) * 0.00001; + extent[2] = extent[2] + Math.abs(extent[2]) * 0.00005; + extent[3] = extent[3] + Math.abs(extent[3]) * 0.00005; map.zoomToBox(extent); - var buffer = new mapnik.Image(300,200) + var buffer = new mapnik.Image(400,300) map.render(buffer, {}, (err,image) => { callback(image.encodeSync('png')); }); @@ -154,11 +154,19 @@ find('test/cache').filter((f) => f.match(/[0-9]+_results.json$/)).forEach((f) => // Generate map image 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); }); - */ + + var osmfile = `${files[1]}`.replace(/\//g,'_'); + var pbffile = `${files[1]}`.replace(/\//g,'_').replace(/.osm/,'.pbf'); + var responsefile = `${files[1]}_${files[2]}_response.json`.replace(/\//g,'_'); + var requestfile = `${files[1]}_${files[2]}_request.txt`.replace(/\//g,'_'); + + fs.writeFileSync(`report/${osmfile}`, fs.readFileSync(files[1])); + fs.writeFileSync(`report/${pbffile}`, fs.readFileSync(`${files[1].replace(/.osm$/,'.pbf')}`)); + fs.writeFileSync(`report/${responsefile}`, fs.readFileSync(`${files[1]}_${files[2]}_response.json`)); + fs.writeFileSync(`report/${requestfile}`, fs.readFileSync(`${files[1]}_${files[2]}_request.txt`)); toc.push({ title: `${results.feature} - ${results.scenario}`, link: imagefile }); @@ -172,6 +180,11 @@ find('test/cache').filter((f) => f.match(/[0-9]+_results.json$/)).forEach((f) => report += `