2016-03-04 15:11:05 -05:00
|
|
|
var util = require('util');
|
|
|
|
|
2019-08-26 07:03:29 -04:00
|
|
|
var flatbuffers = require('../support/flatbuffers').flatbuffers;
|
|
|
|
var FBResult = require('../support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
|
|
|
|
|
2016-03-04 15:11:05 -05:00
|
|
|
module.exports = function () {
|
|
|
|
this.When(/^I request nearest I should get$/, (table, callback) => {
|
2016-08-05 18:11:12 -04:00
|
|
|
this.reprocessAndLoadData((e) => {
|
|
|
|
if (e) return callback(e);
|
2016-03-04 15:11:05 -05:00
|
|
|
var testRow = (row, ri, cb) => {
|
2022-08-22 15:07:32 -04:00
|
|
|
|
2016-03-04 15:11:05 -05:00
|
|
|
var inNode = this.findNodeByName(row.in);
|
2017-04-28 10:25:41 -04:00
|
|
|
if (!inNode) throw new Error(util.format('*** unknown in-node "%s"', row.in));
|
2016-03-04 15:11:05 -05:00
|
|
|
|
|
|
|
this.requestNearest(inNode, this.queryParams, (err, response) => {
|
|
|
|
if (err) return cb(err);
|
|
|
|
var coord;
|
2022-08-22 15:07:32 -04:00
|
|
|
var headers = new Set(table.raw()[0]);
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
var got = { in: row.in};
|
|
|
|
|
|
|
|
if (response.body.length) {
|
2016-03-04 15:11:05 -05:00
|
|
|
var json = JSON.parse(response.body);
|
2023-08-04 13:43:37 -04:00
|
|
|
got.code = json.code;
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
if (response.statusCode === 200) {
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
if (headers.has('data_version')) {
|
|
|
|
got.data_version = json.data_version || '';
|
|
|
|
}
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
if (json.waypoints && json.waypoints.length && row.out) {
|
|
|
|
coord = json.waypoints[0].location;
|
2022-08-22 15:07:32 -04:00
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
got.out = row.out;
|
|
|
|
|
|
|
|
var outNode = this.findNodeByName(row.out);
|
|
|
|
if (!outNode) throw new Error(util.format('*** unknown out-node "%s"', row.out));
|
|
|
|
|
|
|
|
Object.keys(row).forEach((key) => {
|
|
|
|
if (key === 'out') {
|
|
|
|
if (this.FuzzyMatch.matchLocation(coord, outNode)) {
|
|
|
|
got[key] = row[key];
|
|
|
|
} else {
|
|
|
|
row[key] = util.format('%s [%d,%d]', row[key], outNode.lat, outNode.lon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 15:11:05 -05:00
|
|
|
}
|
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
}
|
2016-03-04 15:11:05 -05:00
|
|
|
cb(null, got);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.processRowsAndDiff(table, testRow, callback);
|
|
|
|
});
|
|
|
|
});
|
2019-08-26 07:03:29 -04:00
|
|
|
|
|
|
|
this.When(/^I request nearest with flatbuffers I should get$/, (table, callback) => {
|
|
|
|
this.reprocessAndLoadData((e) => {
|
|
|
|
if (e) return callback(e);
|
|
|
|
var testRow = (row, ri, cb) => {
|
|
|
|
var inNode = this.findNodeByName(row.in);
|
|
|
|
if (!inNode) throw new Error(util.format('*** unknown in-node "%s"', row.in));
|
|
|
|
|
|
|
|
var outNode = this.findNodeByName(row.out);
|
|
|
|
if (!outNode) throw new Error(util.format('*** unknown out-node "%s"', row.out));
|
|
|
|
|
|
|
|
this.queryParams.output = 'flatbuffers';
|
|
|
|
this.requestNearest(inNode, this.queryParams, (err, response) => {
|
|
|
|
if (err) return cb(err);
|
|
|
|
var coord;
|
|
|
|
|
|
|
|
if (response.statusCode === 200 && response.body.length) {
|
|
|
|
var body = response.body;
|
|
|
|
var bytes = new Uint8Array(body.length);
|
|
|
|
for (var indx = 0; indx < body.length; ++indx) {
|
|
|
|
bytes[indx] = body.charCodeAt(indx);
|
|
|
|
}
|
|
|
|
var buf = new flatbuffers.ByteBuffer(bytes);
|
|
|
|
var fb = FBResult.getRootAsFBResult(buf);
|
|
|
|
var location = fb.waypoints(0).location();
|
|
|
|
|
2019-08-26 07:31:51 -04:00
|
|
|
coord = [location.longitude(), location.latitude()];
|
2019-08-26 07:03:29 -04:00
|
|
|
|
|
|
|
var got = { in: row.in, out: row.out };
|
|
|
|
|
|
|
|
Object.keys(row).forEach((key) => {
|
|
|
|
if (key === 'out') {
|
|
|
|
if (this.FuzzyMatch.matchLocation(coord, outNode)) {
|
|
|
|
got[key] = row[key];
|
|
|
|
} else {
|
|
|
|
row[key] = util.format('%s [%d,%d]', row[key], outNode.lat, outNode.lon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cb(null, got);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.processRowsAndDiff(table, testRow, callback);
|
|
|
|
});
|
|
|
|
});
|
2016-03-04 15:11:05 -05:00
|
|
|
};
|