Added profile files per test generation

This commit is contained in:
Michael Krasnyk
2016-09-26 22:25:54 +02:00
committed by Moritz Kobitzsch
parent 89264eb89b
commit 3f3c85ba72
6 changed files with 87 additions and 83 deletions
+50 -34
View File
@@ -1,3 +1,5 @@
'use strict';
var util = require('util');
var path = require('path');
var fs = require('fs');
@@ -32,9 +34,9 @@ module.exports = function () {
});
this.Given(/^the shortcuts$/, (table, callback) => {
var q = d3.queue();
let q = d3.queue();
var addShortcut = (row, cb) => {
let addShortcut = (row, cb) => {
this.shortcutsHash[row.key] = row.value;
cb();
};
@@ -47,29 +49,28 @@ module.exports = function () {
});
this.Given(/^the node map$/, (table, callback) => {
var q = d3.queue();
let q = d3.queue();
var addNode = (name, ri, ci, cb) => {
let addNode = (name, ri, ci, cb) => {
if (name) {
var nodeWithID = name.match(/([a-z])\:([0-9]*)/);
let nodeWithID = name.match(/([a-z])\:([0-9]*)/);
if (nodeWithID) {
var nodeName = nodeWithID[1],
let nodeName = nodeWithID[1],
nodeID = nodeWithID[2];
if (this.nameNodeHash[nodeName]) throw new Error(util.format('*** duplicate node %s', name));
lonLat = this.tableCoordToLonLat(ci, ri);
let lonLat = this.tableCoordToLonLat(ci, ri);
this.addOSMNode(nodeName, lonLat[0], lonLat[1], nodeID);
} else {
if (name.length !== 1) throw new Error(util.format('*** node invalid name %s, must be single characters', name));
if (!name.match(/[a-z0-9]/)) throw new Error(util.format('*** invalid node name %s, must me alphanumeric', name));
var lonLat;
if (name.match(/[a-z]/)) {
if (this.nameNodeHash[name]) throw new Error(util.format('*** duplicate node %s', name));
lonLat = this.tableCoordToLonLat(ci, ri);
let lonLat = this.tableCoordToLonLat(ci, ri);
this.addOSMNode(name, lonLat[0], lonLat[1], null);
} else {
if (this.locationHash[name]) throw new Error(util.format('*** duplicate node %s'), name);
lonLat = this.tableCoordToLonLat(ci, ri);
let lonLat = this.tableCoordToLonLat(ci, ri);
this.addLocation(name, lonLat[0], lonLat[1], null);
}
}
@@ -89,14 +90,14 @@ module.exports = function () {
});
this.Given(/^the node locations$/, (table, callback) => {
var q = d3.queue();
let q = d3.queue();
var addNodeLocations = (row, cb) => {
var name = row.node;
let addNodeLocations = (row, cb) => {
let name = row.node;
if (this.findNodeByName(name)) throw new Error(util.format('*** duplicate node %s'), name);
if (name.match(/[a-z]/)) {
var id = row.id && parseInt(row.id);
let id = row.id && parseInt(row.id);
this.addOSMNode(name, row.lon, row.lat, id);
} else {
this.addLocation(name, row.lon, row.lat);
@@ -111,14 +112,14 @@ module.exports = function () {
});
this.Given(/^the nodes$/, (table, callback) => {
var q = d3.queue();
let q = d3.queue();
var addNode = (row, cb) => {
var name = row.node,
let addNode = (row, cb) => {
let name = row.node,
node = this.findNodeByName(name);
delete row.node;
if (!node) throw new Error(util.format('*** unknown node %s'), name);
for (var key in row) {
for (let key in row) {
node.addTag(key, row[key]);
}
cb();
@@ -132,27 +133,27 @@ module.exports = function () {
this.Given(/^the ways$/, (table, callback) => {
if (this.osm_str) throw new Error('*** Map data already defined - did you pass an input file in this scenario?');
var q = d3.queue();
let q = d3.queue();
var addWay = (row, cb) => {
var way = new OSM.Way(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
let addWay = (row, cb) => {
let way = new OSM.Way(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
var nodes = row.nodes;
let nodes = row.nodes;
if (this.nameWayHash.nodes) throw new Error(util.format('*** duplicate way %s', nodes));
for (var i=0; i<nodes.length; i++) {
var c = nodes[i];
for (let i=0; i<nodes.length; i++) {
let c = nodes[i];
if (!c.match(/[a-z]/)) throw new Error(util.format('*** ways can only use names a-z (%s)', c));
var node = this.findNodeByName(c);
let node = this.findNodeByName(c);
if (!node) throw new Error(util.format('*** unknown node %s', c));
way.addNode(node);
}
var tags = {
let tags = {
highway: 'primary'
};
for (var key in row) {
for (let key in row) {
tags[key] = row[key];
}
@@ -183,25 +184,25 @@ module.exports = function () {
this.Given(/^the relations$/, (table, callback) => {
if (this.osm_str) throw new Error('*** Map data already defined - did you pass an input file in this scenario?');
var q = d3.queue();
let q = d3.queue();
var addRelation = (row, cb) => {
var relation = new OSM.Relation(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
let addRelation = (row, cb) => {
let relation = new OSM.Relation(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
for (var key in row) {
var isNode = key.match(/^node:(.*)/),
for (let key in row) {
let isNode = key.match(/^node:(.*)/),
isWay = key.match(/^way:(.*)/),
isColonSeparated = key.match(/^(.*):(.*)/);
if (isNode) {
row[key].split(',').map(function(v) { return v.trim(); }).forEach((nodeName) => {
if (nodeName.length !== 1) throw new Error(util.format('*** invalid relation node member "%s"'), nodeName);
var node = this.findNodeByName(nodeName);
let node = this.findNodeByName(nodeName);
if (!node) throw new Error(util.format('*** unknown relation node member "%s"'), nodeName);
relation.addMember('node', node.id, isNode[1]);
});
} else if (isWay) {
row[key].split(',').map(function(v) { return v.trim(); }).forEach((wayName) => {
var way = this.findWayByName(wayName);
let way = this.findWayByName(wayName);
if (!way) throw new Error(util.format('*** unknown relation way member "%s"'), wayName);
relation.addMember('way', way.id, isWay[1]);
});
@@ -248,6 +249,21 @@ module.exports = function () {
fs.writeFile(this.penaltiesCacheFile, data, callback);
});
this.Given(/^the profile file(?: "([^"]*)" extended with)?$/, (profile, data, callback) => {
let text = 'package.path = "' + this.PROFILES_PATH + '/?.lua;" .. package.path\n';
if (profile == null) {
text += data + '\n';
} else {
text += 'local f = assert(io.open("' + this.PROFILES_PATH + '/' + profile + '.lua", "r"))\n';
text += 'local m = assert(loadstring(f:read("*all") .. [[\n' + data + '\n]]))\n';
text += 'f:close()\n';
text += 'm()\n';
}
this.profileFile = this.profileCacheFile;
// TODO: Don't overwrite if it exists
fs.writeFile(this.profileCacheFile, text, callback);
});
this.Given(/^the data has been saved to disk$/, (callback) => {
this.reprocess(callback);
});