Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.
Open
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
30 changes: 0 additions & 30 deletions comparators/added_place.js

This file was deleted.

26 changes: 26 additions & 0 deletions comparators/important_place.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const welltagged = require('../lib/welltagged');
module.exports = importantPlace;
module.exports.checkPlaceType = checkPlaceType;

function importantPlace(newVersion, oldVersion) {
const newType = checkPlaceType(newVersion);
const oldType = checkPlaceType(oldVersion);
return oldType || newType;
}

function checkPlaceType(feature) {
if (!feature) return false;
if (feature && feature.geometry && feature.geometry.type !== 'Point') {
return false;
}
const tags = feature.properties;
if (tags && tags.place) {
if (tags.place === 'country') return tags.place;
if (tags.place === 'city') return tags.place;
if (tags.place === 'town' && welltagged.hasWikiTags(tags)) {
return 'town';
}
}
return false;
}
22 changes: 22 additions & 0 deletions comparators/place_created.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
const importantPlace = require('./important_place');

module.exports = createPlace;

/**
* Detects whether a feature was or is a park
@param {geojson} newVersion - New version of feature
@param {geojson} oldVersion - Previous version of feature
@returns {object|false} returns the detected incident or false
*/
function createPlace(newVersion, oldVersion) {
const isNew = newVersion.properties['osm:version'] === 1 || !oldVersion;
const isImportant = importantPlace(newVersion, oldVersion);

if (isNew && isImportant) {
return {
message: `Important place=${newVersion.properties.place} created`
};
}
return false;
}
22 changes: 22 additions & 0 deletions comparators/place_deleted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
const importantPlace = require('./important_place');

module.exports = deletePlace;

/**
* Detects whether a feature was or is a park
@param {geojson} newVersion - New version of feature
@param {geojson} oldVersion - Previous version of feature
@returns {object|false} returns the detected incident or false
*/
function deletePlace(newVersion, oldVersion) {
const isDeleted = !!newVersion.deleted;
const isImportant = importantPlace(newVersion, oldVersion);

if (isDeleted && isImportant) {
return {
message: `Important place=${newVersion.properties.place} deleted`
};
}
return false;
}
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = {
require('./comparators/modified_place_wikidata')
),
modified_monument: wrapsync(require('./comparators/modified_monument')),
place_created: wrapsync(require('./comparators/place_created')),
place_deleted: wrapsync(require('./comparators/place_deleted')),
invalid_tag_combination: require('./comparators/invalid_tag_combination'),
water_feature_by_new_user: require('./comparators/water_feature_by_new_user'),
common_tag_values: wrapsync(require('./comparators/common_tag_values.js')),
Expand Down
60 changes: 60 additions & 0 deletions lib/welltagged.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';
const namePattern = /^(int_|loc_|nat_|official_|reg_|short_|sorting_)?name(:.*)?$/;
module.exports = wellMaintained;
module.exports.hasTranslations = hasTranslations;
module.exports.hasWikiTags = hasWikiTags;
module.exports.hasPlaceMetadata = hasPlaceMetadata;

function hasWikiTags(tags) {
return tags && (tags.wikipedia || tags.wikidata);
}

function hasTranslations(tags) {
const translations = Object.keys(tags)
.map(key => namePattern.test(key))
.filter(k => !!k).length;
return translations > 1;
}

function hasAddr(tags) {
const addrs = Object.keys(tags)
.map(key => /^addr/.test(key))
.filter(k => !!k).length;
return addrs > 0;
}

function hasRefs(tags) {
const refs = Object.keys(tags)
.map(key => /^ref/.test(key))
.filter(k => !!k).length;
return refs > 0;
}

function hasContact(tags) {
return tags.website ||
tags.phone ||
tags['contact:phone'] ||
tags['contact:website'];
}

function hasPlaceMetadata(tags) {
return tags.population || tags.ele || tags.postal_code || tags.is_in;
}

function hasMetadataTags(tags) {
return hasAddr(tags) ||
hasContact(tags) ||
hasRefs(tags) ||
hasTranslations(tags) ||
hasWikiTags(tags) ||
hasPlaceMetadata(tags);
}

function wellMaintained(newVersion, oldVersion) {
if (hasMetadataTags(newVersion.properties)) {
return true;
} else if (oldVersion && hasMetadataTags(oldVersion.properties)) {
return true;
}
return false;
}
112 changes: 0 additions & 112 deletions tests/fixtures/added_place.json

This file was deleted.

47 changes: 47 additions & 0 deletions tests/fixtures/place_created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"compareFunction": "place_created",
"fixtures": [
{
"description": "Italy created",
"newVersion": {
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"osm:version": 1,
"osm:type": "node",
"place": "country",
"name": "Italia"
}
},
"expectedResult": {
"message": "Important place=country created"
}
},
{
"description": "London created",
"newVersion": {
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"osm:version": 1,
"osm:type": "node",
"place": "city",
"name": "London"
}
},
"expectedResult": {
"message": "Important place=city created"
}
}
]
}
31 changes: 31 additions & 0 deletions tests/fixtures/place_deleted.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compareFunction": "place_deleted",
"fixtures": [
{
"description": "London deleted",
"oldVersion": {
"properties": {
"osm:version": 1,
"osm:type": "node",
"place": "city",
"name": "London"
}
},
"newVersion": {
"properties": {
"osm:version": 2,
"osm:type": "node",
"place": "city",
"name": "London"
},
"geometry": {
"type": "Point"
},
"deleted": true
},
"expectedResult": {
"message": "Important place=city deleted"
}
}
]
}