Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Water feature by new user #111

Merged
merged 5 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions comparators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ Reports when any feature in the [osm-landmarks list](https://github.com/osmlab/o

### invalid-tag-combination
Reports when a feature has two uncommon primary tag combinations. Ex: `0.06 %` of features with `building` also have `historic` tag.

### water-feature-by-new-user
Report when a new user creates a new water feature.
54 changes: 54 additions & 0 deletions comparators/water-feature-by-new-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

var request = require('request');

module.exports = waterFeatureByNewUser;

function isWaterFeature(feature) {
var landuse_values = ['pond', 'reservoir', 'salt_pond', 'basin'];

var properties = feature.properties;

if (properties.hasOwnProperty('natural') && properties['natural'] === 'water') return true;
if (properties.hasOwnProperty('water')) return true;
if (properties.hasOwnProperty('landuse') && (landuse_values.indexOf(properties['landuse']) !== -1)) return true;
if (properties.hasOwnProperty('reservoir_type') && properties['reservoir_type'] === 'water_storage') return true;
if (properties.hasOwnProperty('man_made') && properties['man_made'] === 'reservoir_covered') return true;
if (properties.hasOwnProperty('waterway')) return true;

return false;
}

function getUserDetails(user, callback) {
var url = 'https://osm-comments-api.mapbox.com/api/v1/users/name/' + encodeURIComponent(user);

request(url, function (error, response, body) {
// Pass the error back to the callee.
if (error) return callback(error, undefined);
else return callback(null, JSON.parse(body));
});
}

function waterFeatureByNewUser(newVersion, oldVersion, callback) {
// What is the number of changesets of a user to be considered a new user?
var MINIMUM_CHANGESET_COUNT = 10;

if (!newVersion || newVersion.properties['osm:version'] !== 1) return callback(null, {});

if (isWaterFeature(newVersion)) {
var user = newVersion.properties['osm:user'];

getUserDetails(user, function (error, userDetails) {
// Return back from the compare function with no results.
if (error) return callback(null, {});

if (userDetails['changeset_count'] <= MINIMUM_CHANGESET_COUNT) {
return callback(null, {'result:water_feature_by_new_user': true});
} else {
return callback(null, {});
}
});
} else {
return callback(null, {});
}
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
'modified_place_wikidata': require('./comparators/modified-place-wikidata'),
'osm_landmarks': require('./comparators/osm-landmarks'),
'modifiedMonument': require('./comparators/modifiedMonument'),
'invalid_tag_combination': require('./comparators/invalid-tag-combination')
'invalid_tag_combination': require('./comparators/invalid-tag-combination'),
'water_feature_by_new_user': require('./comparators/water-feature-by-new-user')
};
99 changes: 99 additions & 0 deletions tests/fixtures/water-feature-by-new-user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"compareFunction": "water-feature-by-new-user",
"fixtures": [
{
"description": "Test new lake created by a new user",
"expectedResult": {
"result:water_feature_by_new_user": true
},
"newVersion": {
"type": "Feature",
"properties": {
"osm:id": 469253887,
"osm:type": "way",
"osm:version": 1,
"osm:user": "deered",
"natural": "water"
},
"geometry": null
},
"oldVersion": null
},
{
"description": "Test existing lake modified by a new user",
"expectedResult": {},
"newVersion": {
"type": "Feature",
"properties": {
"osm:id": 469253887,
"osm:type": "way",
"osm:version": 2,
"osm:user": "deered",
"name": "nope",
"water": "lake"
},
"geometry": null
},
"oldVersion": {
"type": "Feature",
"properties": {
"osm:id": 469253887,
"osm:type": "way",
"osm:version": 1,
"osm:user": "deered",
"water": "lake"
},
"geometry": null
}
},
{
"description": "Test new not-lake created by a new user",
"expectedResult": {},
"newVersion": {
"type": "Feature",
"properties": {
"osm:id": 469253887,
"osm:type": "way",
"osm:version": 1,
"osm:user": "deered"
},
"geometry": null
},
"oldVersion": null
},
{
"description": "Test new lake created by a not new user",
"expectedResult": {},
"newVersion": {
"type": "Feature",
"properties": {
"osm:id": 469253887,
"osm:type": "way",
"osm:version": 1,
"osm:user": "Canvec_s_longiaru",
"natural": "water"
},
"geometry": null
},
"oldVersion": null
},
{
"description": "Test new pond created by a new user",
"expectedResult": {
"result:water_feature_by_new_user": true
},
"newVersion": {
"type": "Feature",
"properties": {
"osm:id": 469253887,
"osm:type": "way",
"osm:version": 1,
"osm:user": "deered",
"landuse": "pond"
},
"geometry": null
},
"oldVersion": null
}
]
}