Browse Source

added helper variables for readability

pull/274/head
Stephen Hess 9 years ago
parent
commit
8be249b701
  1. 51
      middleware/confidenceScoreReverse.js
  2. 2
      routes/v1.js

51
middleware/confidenceScoreReverse.js

@ -3,16 +3,21 @@ var _ = require('lodash');
// these are subjective terms, but wanted to add shortcuts to denote something // these are subjective terms, but wanted to add shortcuts to denote something
// about importance // about importance
var confidence = { var EXACT = 1.0;
exact: 1.0, var EXCELLENT = 0.9;
excellent: 0.9, var GOOD = 0.8;
good: 0.8, var OKAY = 0.7;
okay: 0.7, var POOR = 0.6;
poor: 0.6, var NONE = 0.5;
none: 0.5 var INVALID = 0.0;
};
var _1_METER = 1;
function setup(peliasConfig) { var _10_METERS = 10;
var _100_METERS = 100;
var _250_METERS = 250;
var _1_KILOMETER = 1000;
function setup() {
return computeScores; return computeScores;
} }
@ -31,26 +36,26 @@ function computeScores(req, res, next) {
function computeConfidenceScore(req, hit) { function computeConfidenceScore(req, hit) {
// non-number or invalid distance should be given confidence 0.0 // non-number or invalid distance should be given confidence 0.0
if (typeof hit.distance !== 'number' || hit.distance < 0) { if (typeof hit.distance !== 'number' || hit.distance < 0) {
hit.confidence = 0.0; hit.confidence = INVALID;
return hit; return hit;
} }
var meters = hit.distance * 1000; var distance = hit.distance * 1000.0;
// figure out which range the distance lies in and assign confidence accordingly // figure out which range the distance lies in and assign confidence accordingly
// TODO: this could probably be made more node-y with a map of function->number // TODO: this could probably be made more node-y with a map of function->number
if (meters < 1.0) { if (distance < _1_METER) {
hit.confidence = confidence.exact; hit.confidence = EXACT;
} else if (_.inRange(meters, 1, 10)) { } else if (_.inRange(distance, _1_METER, _10_METERS)) {
hit.confidence = confidence.excellent; hit.confidence = EXCELLENT;
} else if (_.inRange(meters, 10, 100)) { } else if (_.inRange(distance, _10_METERS, _100_METERS)) {
hit.confidence = confidence.good; hit.confidence = GOOD;
} else if (_.inRange(meters, 100, 250)) { } else if (_.inRange(distance, _100_METERS, _250_METERS)) {
hit.confidence = confidence.okay; hit.confidence = OKAY;
} else if (_.inRange(meters, 250, 1000)) { } else if (_.inRange(distance, _250_METERS, _1_KILOMETER)) {
hit.confidence = confidence.poor; hit.confidence = POOR;
} else { } else {
hit.confidence = confidence.none; hit.confidence = NONE;
} }
return hit; return hit;

2
routes/v1.js

@ -77,7 +77,7 @@ function addRoutes(app, peliasConfig) {
postProc.distances(), postProc.distances(),
// reverse confidence scoring depends on distance from origin // reverse confidence scoring depends on distance from origin
// so it must be calculated first // so it must be calculated first
postProc.confidenceScoresReverse(peliasConfig), postProc.confidenceScoresReverse(),
postProc.renamePlacenames(), postProc.renamePlacenames(),
postProc.geocodeJSON(peliasConfig), postProc.geocodeJSON(peliasConfig),
postProc.sendJSON postProc.sendJSON

Loading…
Cancel
Save