prefer first result
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user