Skip to content

Commit

Permalink
fix(venue_popularity): fix handling of disused & abandoned places
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Jun 13, 2019
1 parent 913ae4e commit d496230
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
15 changes: 5 additions & 10 deletions stream/popularity_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ module.exports = function(){
}
}

// set document popularity when it is a non-zero value
if( !!popularity ){
doc.setPopularity( popularity );
}
// set document popularity if it is greater than zero
if( popularity > 0 ){ doc.setPopularity( popularity ); }

// discard places with a negative popularity
else if( popularity < 0 ){ return next(); }
}

catch( e ){
Expand All @@ -202,13 +203,7 @@ module.exports = function(){
peliasLogger.error( JSON.stringify( doc, null, 2 ) );
}

// discard disused and abandoned places with a negative popularity
if(( doc.getPopularity() || 0 ) < 0 ){
return next();
}

return next( null, doc );

});

};
22 changes: 16 additions & 6 deletions test/stream/popularity_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,32 +197,42 @@ module.exports.tests.nonvenue = function (test, common) {
// ===================== discard disused places ======================

module.exports.tests.disused = function (test, common) {
var doc = new Document('osm', 'address', 1);
var doc = new Document('osm', 'venue', 1);
doc.setMeta('tags', { 'disused:amenity': 'yes' });
test('does not map - disused', t => {
var stream = mapper();
var counter = 0;
stream.pipe(through.obj((doc, enc, next) => {
t.false(doc.getPopularity(), 'no mapping performed');
t.end(); // test will fail if not called (or called twice).
counter++;
next();
}, (done) => {
t.equal(counter, 0, 'document discarded');
t.end(); // test will fail if not called (or called twice).
done();
}));
stream.write(doc);
stream.end();
});
};

// ===================== discard abandoned places ======================

module.exports.tests.abandoned = function (test, common) {
var doc = new Document('osm', 'address', 1);
var doc = new Document('osm', 'venue', 1);
doc.setMeta('tags', { 'abandoned:amenity': 'yes' });
test('does not map - abandoned', t => {
var stream = mapper();
var counter = 0;
stream.pipe(through.obj((doc, enc, next) => {
t.false(doc.getPopularity(), 'no mapping performed');
t.end(); // test will fail if not called (or called twice).
counter++;
next();
}, (done) => {
t.equal(counter, 0, 'document discarded');
t.end(); // test will fail if not called (or called twice).
done();
}));
stream.write(doc);
stream.end();
});
};

Expand Down

0 comments on commit d496230

Please sign in to comment.