prefer first result

This commit is contained in:
Moritz Kobitzsch
2016-09-22 12:27:55 +02:00
parent d1f555dcef
commit 0abd32fca3
4 changed files with 29 additions and 13 deletions
+14 -2
View File
@@ -1,6 +1,10 @@
var util = require('util');
module.exports = function () {
function add(a, b) {
return a + b;
}
this.When(/^I plan a trip I should get$/, (table, callback) => {
var got;
@@ -43,6 +47,7 @@ module.exports = function () {
}
var subTrips;
var trip_durations;
if (res.statusCode === 200) {
if (headers.has('trips')) {
subTrips = json.trips.filter(t => !!t).map(t => t.legs).map(tl => Array.prototype.concat.apply([], tl.map((sl, i) => {
@@ -52,6 +57,12 @@ module.exports = function () {
return toAdd;
})));
}
if(headers.has('durations')) {
var all_durations = json.trips.filter(t => !!t).map(t => t.legs).map(tl => Array.prototype.concat.apply([], tl.map(sl => {
return sl.duration;
})));
trip_durations = all_durations.map( a => a.reduce(add, 0));
}
}
var ok = true,
@@ -62,7 +73,6 @@ module.exports = function () {
if (si >= subTrips.length) {
ok = false;
} else {
ok = false;
// TODO: Check all rotations of the round trip
for (var ni=0; ni<sub.length; ni++) {
var node = this.findNodeByName(sub[ni]),
@@ -70,8 +80,8 @@ module.exports = function () {
if (this.FuzzyMatch.matchLocation(outNode, node)) {
encodedResult += sub[ni];
extendedTarget += sub[ni];
ok = true;
} else {
ok = false;
encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]);
extendedTarget += util.format('%s [%d,%d]', sub[ni], node.lat, node.lon);
}
@@ -87,6 +97,8 @@ module.exports = function () {
got.trips = extendedTarget;
}
got.durations = trip_durations;
for (var key in row) {
if (this.FuzzyMatch.match(got[key], row[key])) {
got[key] = row[key];