Make the poly2req script work with 4.9 and 5.0 and add modes

This commit is contained in:
Patrick Niklaus 2016-04-09 00:40:10 +02:00
parent 4886d46d91
commit 9a617f5d41

View File

@ -4,32 +4,79 @@
let fs = require('fs'); let fs = require('fs');
let VERSION = "route_5.0";
let SAMPLE_SIZE = 20;
let NUM_REQUEST = 1000; let NUM_REQUEST = 1000;
let NUM_COORDS = 2; let NUM_COORDS = 2;
let url_template = "http://127.0.0.1:5000/route/v1/driving/{coords}?steps=false&alternatives=false"; let PORT = 5000;
let coord_template = "{lon},{lat}"; let url_templates = {
let coords_separator = ";"; "route_5.0": "http://127.0.0.1:{port}/route/v1/driving/{coords}?steps=false&alternatives=false",
"route_4.9": "http://127.0.0.1:{port}/viaroute?{coords}&instructions=false&alt=false",
"table_5.0": "http://127.0.0.1:{port}/table/v1/driving/{coords}",
"table_4.9": "http://127.0.0.1:{port}/table?{coords}"
};
let monaco_poly_path = process.argv[2]; let coord_templates = {
let poly_data = fs.readFileSync(monaco_poly_path, 'utf-8'); "route_5.0": "{lon},{lat}",
"route_4.9": "loc={lat},{lon}",
"table_5.0": "{lon},{lat}",
"table_4.9": "loc={lat},{lon}"
};
// lets assume there is only one ring let coords_separators = {
// cut of name and ring number and the two END statements "route_5.0": ";",
let coordinates = poly_data.split('\n') "route_4.9": "&",
.filter((l) => l != '') "table_5.0": ";",
.slice(2, -2).map((coord_line) => coord_line.split(' ') "table_4.9": "&"
.filter((elem) => elem != '')) };
.map((coord) => [parseFloat(coord[0]), parseFloat(coord[1])]); var axis = "distance";
var sw = [Number.MAX_VALUE, Number.MAX_VALUE]; var sw = [Number.MAX_VALUE, Number.MAX_VALUE];
var ne = [Number.MIN_VALUE, Number.MIN_VALUE]; var ne = [Number.MIN_VALUE, Number.MIN_VALUE];
coordinates.forEach((c) => { if (process.argv.length > 2 && process.argv[2] == "planet")
sw[0] = Math.min(sw[0], c[0]); {
sw[1] = Math.min(sw[1], c[1]); sw = [-180., -85.];
ne[0] = Math.max(ne[0], c[0]); ne = [180., 85.];
ne[1] = Math.max(ne[1], c[1]); }
}); if (process.argv.length > 2 && process.argv[2] == "us")
{
sw = [-127., 24.];
ne = [-67., 48.];
}
else if (process.argv.length > 2 && process.argv[2] == "dc")
{
sw = [-77.138, 38.808];
ne = [-76.909, 38.974];
}
else if (process.argv.length > 2)
{
let monaco_poly_path = process.argv[2];
let poly_data = fs.readFileSync(monaco_poly_path, 'utf-8');
// lets assume there is only one ring
// cut of name and ring number and the two END statements
let coordinates = poly_data.split('\n')
.filter((l) => l != '')
.slice(2, -2).map((coord_line) => coord_line.split(' ')
.filter((elem) => elem != ''))
.map((coord) => [parseFloat(coord[0]), parseFloat(coord[1])]);
coordinates.forEach((c) => {
sw[0] = Math.min(sw[0], c[0]);
sw[1] = Math.min(sw[1], c[1]);
ne[0] = Math.max(ne[0], c[0]);
ne[1] = Math.max(ne[1], c[1]);
});
}
if (process.argv.length > 3)
{
axis = process.argv[3];
}
console.error(sw);
console.error(ne);
// Yes this an own seeded random number generator because its only a few lines // Yes this an own seeded random number generator because its only a few lines
var seed = 0x1337; var seed = 0x1337;
@ -45,14 +92,41 @@ function getRandomCoordinate() {
return [lon, lat]; return [lon, lat];
} }
for (var i = 0; i < NUM_REQUEST; ++i) function makeQuery(coords) {
{ let coords_string = coords.map((c) => coord_templates[VERSION].replace("{lon}", c[0]).replace("{lat}", c[1])).join(coords_separators[VERSION]);
var coords = []; return url_templates[VERSION].replace("{coords}", coords_string).replace("{port}", PORT);
for (var j = 0; j < NUM_COORDS; ++j) }
{
coords.push(getRandomCoordinate()); if (axis == "distance")
} {
let coords_string = coords.map((c) => coord_template.replace("{lon}", c[0]).replace("{lat}", c[1])).join(coords_separator); for (var i = 0; i < NUM_REQUEST; ++i)
console.log(url_template.replace("{coords}", coords_string)); {
var coords = [];
for (var j = 0; j < NUM_COORDS; ++j)
{
coords.push(getRandomCoordinate());
}
console.log(makeQuery(coords));
}
}
else if (axis == "waypoints")
{
for (var power = 0; power <= 1; ++power)
{
for (var factor = 1; factor <= 10; ++factor)
{
let num_coords = factor*Math.pow(10, power);
console.error(num_coords);
for (var i = 0; i < SAMPLE_SIZE; ++i)
{
var coords = [];
for (var j = 0; j < num_coords; ++j)
{
coords.push(getRandomCoordinate());
}
console.log(makeQuery(coords));
}
}
}
} }