Make images bigger, fix buffering. Log request and responses.

This commit is contained in:
Daniel Patterson 2018-02-06 20:53:22 -08:00
parent ce995454c6
commit f532912e62
No known key found for this signature in database
GPG Key ID: 19C12BE1725A028B
4 changed files with 63 additions and 37 deletions

View File

@ -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.'));

View File

@ -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}`;

View File

@ -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'));
}

View File

@ -32,61 +32,61 @@ var stylesheet = `
<Filter>[highway] = 'motorway'</Filter>
<LineSymbolizer stroke-width="12" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#aacc77" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='10'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='10'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[highway] = 'motorway_link'</Filter>
<LineSymbolizer stroke-width="12" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#77aacc" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='10'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='10'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[highway] = 'trunk'</Filter>
<LineSymbolizer stroke-width="12" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#ccaa77" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='10'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='10'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[highway] = 'trunk_link'</Filter>
<LineSymbolizer stroke-width="12" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#aa77cc" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='10'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-10'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='10'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[highway] = 'primary'</Filter>
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="8" stroke-linejoin="round" stroke-linecap="round" stroke="#77ccaa" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='8'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='8'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[highway] = 'primary_link'</Filter>
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="8" stroke-linejoin="round" stroke-linecap="round" stroke="#aa77cc" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='8'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='8'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[highway] = 'secondary' or [highway] = 'secondary_link' or [highway] = 'tertiary' or [highway] = 'tertiary_link' or [highway] = 'residential' or [highway] = 'service' or [highway] = 'living_street'</Filter>
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="8" stroke-linejoin="round" stroke-linecap="round" stroke="#77bb77" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='8'>'highway=' + [highway]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='8'>'highway=' + [highway]</TextSymbolizer>
</Rule>
<Rule>
<Filter>[route] = 'ferry'</Filter>
<LineSymbolizer stroke-width="10" stroke-linejoin="round" stroke-linecap="round" stroke="#bbbbbb" />
<LineSymbolizer stroke-width="8" stroke-linejoin="round" stroke-linecap="round" stroke="#7777bb" />
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="false" dy='8'>'route=' + [route]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='-8'>'name=' + [name]</TextSymbolizer>
<TextSymbolizer face-name="Arial Regular" size="10" fill="black" placement="line" allow-overlap="true" dy='8'>'route=' + [route]</TextSymbolizer>
</Rule>
</Style>
@ -105,14 +105,14 @@ var stylesheet = `
<LineSymbolizer stroke-width="3" stroke-linejoin="round" stroke-linecap="round" stroke="#0000ff" offset="6"/>
</Rule>
</Style>
<Style name="testroute-markers" filter-mode="all">
<Style name="testroute-markers" filter-mode="first">
<Rule>
<Filter>[type] = 'startpoint'</Filter>
<MarkersSymbolizer fill="green" width="20" height="20" stroke="green"/>
<MarkersSymbolizer fill="green" width="20" height="20" stroke="green" allow-overlap="true"/>
</Rule>
<Rule>
<Filter>[type] = 'endpoint'</Filter>
<MarkersSymbolizer fill="red" width="20" height="20" stroke="red"/>
<MarkersSymbolizer fill="red" width="20" height="20" stroke="red" allow-overlap="true"/>
</Rule>
</Style>
<Layer name="testroute" srs="+init=epsg:4326">
@ -125,19 +125,19 @@ var stylesheet = `
</Layer>
</Map>`;
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 += `<div class='scenario ${results.got.turns == results.expected.turns ? 'ok' : 'error'}'>
<h2><a name="${imagefile}">${results.feature} - ${results.scenario}</a></h2>
<a href="${osmfile}">Download OSM XML file for this test</a><br/>
<a href="${pbffile}">Download OSM PBF file for this test</a><br/>
<a href="${requestfile}">Download request used for this test</a><br/>
<a href="${responsefile}">Download raw response for this test</a>
<table class="row">
<tr>
<td>