forked from pelias/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccuracy.js
56 lines (45 loc) · 1.18 KB
/
accuracy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
*
* Accuracy level should be set for each item in the results.
* The level can be any of the following:
* - point
* - interpolated (not currently used)
* - centroid
*/
const _ = require('lodash');
const accuracyLevelPoint = 'point';
// const accuracyLevelInterpolated = 'interpolated';
const accuracyLevelCentroid = 'centroid';
function setup() {
return computeAccuracy;
}
function computeAccuracy(req, res, next) {
// do nothing if no result data set
if (_.isUndefined(res) || _.isUndefined(res.data)) {
return next();
}
// loop through data items and determine accuracy levels
res.data = res.data.map(computeAccuracyLevelForResult);
next();
}
/**
* Determine accuracy level based on the type of result being returned.
*
* @param {object} hit
* @returns {object}
*/
function computeAccuracyLevelForResult(hit) {
// TODO: add a check for interpolated addresses when that feature lands
switch (hit.layer) {
case 'venue':
case 'address':
hit.accuracy = accuracyLevelPoint;
break;
// this means it's a street or admin area
default:
hit.accuracy = accuracyLevelCentroid;
break;
}
return hit;
}
module.exports = setup;