Messed up merged of matching.js
This commit is contained in:
parent
5f5675d361
commit
117c6b77aa
@ -1,5 +1,6 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var d3 = require('d3-queue');
|
|
||||||
var polyline = require('polyline');
|
var polyline = require('polyline');
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
@ -44,14 +45,25 @@ module.exports = function () {
|
|||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
if (headers.has('matchings')) {
|
if (headers.has('matchings')) {
|
||||||
subMatchings = [];
|
subMatchings = [];
|
||||||
var sub = [json.tracepoints[0].location];
|
|
||||||
for(var i = 1; i < json.tracepoints.length; i++){
|
// find the first matched
|
||||||
if(json.tracepoints[i-1].matchings_index === json.tracepoints[i].matchings_index) {
|
let start_index = 0;
|
||||||
sub.push(json.tracepoints[i].location);
|
while (start_index < json.tracepoints.length && json.tracepoints[start_index] === null) start_index++;
|
||||||
} else {
|
|
||||||
subMatchings.push(sub);
|
var sub = [];
|
||||||
sub = [json.tracepoints[i].location];
|
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);
|
subMatchings.push(sub);
|
||||||
}
|
}
|
||||||
@ -82,7 +94,7 @@ module.exports = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (headers.has('OSM IDs')) {
|
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]);
|
OSMIDs = this.OSMIDList(json.matchings[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,36 +130,27 @@ module.exports = function () {
|
|||||||
var encodedResult = '',
|
var encodedResult = '',
|
||||||
extendedTarget = '';
|
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 (this.FuzzyMatch.matchLocation(outNode, node)) {
|
||||||
if (si >= subMatchings.length) {
|
encodedResult += sub[ni];
|
||||||
ok = false;
|
extendedTarget += sub[ni];
|
||||||
q.abort();
|
} else {
|
||||||
scb();
|
if (outNode != null) {
|
||||||
} 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 {
|
|
||||||
encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]);
|
encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]);
|
||||||
extendedTarget += util.format('%s [%d,%d]', node.lat, node.lon);
|
} else {
|
||||||
ok = false;
|
encodedResult += '?';
|
||||||
}
|
}
|
||||||
ncb();
|
extendedTarget += util.format('%s [%d,%d]', node.lat, node.lon);
|
||||||
};
|
ok = false;
|
||||||
|
|
||||||
for (var i=0; i<sub.length; i++) {
|
|
||||||
sq.defer(testSubNode, i);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
sq.awaitAll(scb);
|
for (var i=0; i<sub.length; i++) {
|
||||||
|
testSubNode(i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -162,22 +165,20 @@ module.exports = function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
q.awaitAll(() => {
|
if (ok) {
|
||||||
if (ok) {
|
if (headers.has('matchings')) {
|
||||||
if (headers.has('matchings')) {
|
got.matchings = row.matchings;
|
||||||
got.matchings = row.matchings;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (headers.has('timestamps')) {
|
|
||||||
got.timestamps = row.timestamps;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
got.matchings = encodedResult;
|
|
||||||
row.matchings = extendedTarget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cb(null, got);
|
if (headers.has('timestamps')) {
|
||||||
});
|
got.timestamps = row.timestamps;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
got.matchings = encodedResult;
|
||||||
|
row.matchings = extendedTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(null, got);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (row.request) {
|
if (row.request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user