From 117c6b77aabd40e790835d71e333c50b2b5b8e94 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 2 Nov 2016 18:57:11 +0000 Subject: [PATCH] Messed up merged of matching.js --- features/step_definitions/matching.js | 97 ++++++++++++++------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/features/step_definitions/matching.js b/features/step_definitions/matching.js index d210b5186..3fe3f3932 100644 --- a/features/step_definitions/matching.js +++ b/features/step_definitions/matching.js @@ -1,5 +1,6 @@ +'use strict'; + var util = require('util'); -var d3 = require('d3-queue'); var polyline = require('polyline'); module.exports = function () { @@ -44,14 +45,25 @@ module.exports = function () { if (res.statusCode === 200) { if (headers.has('matchings')) { subMatchings = []; - var sub = [json.tracepoints[0].location]; - for(var i = 1; i < json.tracepoints.length; i++){ - if(json.tracepoints[i-1].matchings_index === json.tracepoints[i].matchings_index) { - sub.push(json.tracepoints[i].location); - } else { - subMatchings.push(sub); - sub = [json.tracepoints[i].location]; + + // find the first matched + let start_index = 0; + while (start_index < json.tracepoints.length && json.tracepoints[start_index] === null) start_index++; + + var sub = []; + let prev_index = null; + for(var i = start_index; i < json.tracepoints.length; i++){ + if (json.tracepoints[i] === null) continue; + + let current_index = json.tracepoints[i].matchings_index; + + if(prev_index !== current_index) { + if (sub.length > 0) subMatchings.push(sub); + sub = []; + prev_index = current_index; } + + sub.push(json.tracepoints[i].location); } subMatchings.push(sub); } @@ -82,7 +94,7 @@ module.exports = function () { } if (headers.has('OSM IDs')) { - if (json.matchings.length != 1) throw new Error('*** CHecking annotation only supported for matchings with one subtrace'); + if (json.matchings.length != 1) throw new Error('*** Checking annotation only supported for matchings with one subtrace'); OSMIDs = this.OSMIDList(json.matchings[0]); } } @@ -118,36 +130,27 @@ module.exports = function () { var encodedResult = '', extendedTarget = ''; - var q = d3.queue(); + var testSubMatching = (sub, si) => { + var testSubNode = (ni) => { + var node = this.findNodeByName(sub[ni]), + outNode = subMatchings[si][ni]; - var testSubMatching = (sub, si, scb) => { - if (si >= subMatchings.length) { - ok = false; - q.abort(); - scb(); - } else { - var sq = d3.queue(); - - var testSubNode = (ni, ncb) => { - var node = this.findNodeByName(sub[ni]), - outNode = subMatchings[si][ni]; - - if (this.FuzzyMatch.matchLocation(outNode, node)) { - encodedResult += sub[ni]; - extendedTarget += sub[ni]; - } else { + if (this.FuzzyMatch.matchLocation(outNode, node)) { + encodedResult += sub[ni]; + extendedTarget += sub[ni]; + } else { + if (outNode != null) { encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]); - extendedTarget += util.format('%s [%d,%d]', node.lat, node.lon); - ok = false; + } else { + encodedResult += '?'; } - ncb(); - }; - - for (var i=0; i { - if (ok) { - if (headers.has('matchings')) { - got.matchings = row.matchings; - } - - if (headers.has('timestamps')) { - got.timestamps = row.timestamps; - } - } else { - got.matchings = encodedResult; - row.matchings = extendedTarget; + if (ok) { + if (headers.has('matchings')) { + got.matchings = row.matchings; } - cb(null, got); - }); + if (headers.has('timestamps')) { + got.timestamps = row.timestamps; + } + } else { + got.matchings = encodedResult; + row.matchings = extendedTarget; + } + + cb(null, got); }; if (row.request) {