From 0934db48dd8393d43ffa6890e2513ed6ffc68ccb Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 5 Feb 2019 09:12:43 -0500 Subject: [PATCH] Don't count vertices toward many deletions warnings Lower threshold for triggering many deletions warnings --- data/core.yaml | 5 ++- dist/locales/en.json | 7 ++++- modules/validations/many_deletions.js | 44 +++++++++++++++++++-------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index fa0151428..825632daf 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1222,7 +1222,10 @@ en: message: '{feature} has the generic name "{name}".' tip: Names should be the official, on-the-ground titles of features. many_deletions: - message: "Deleting {n} features: {p} nodes, {l} lines, {a} areas, and {r} relations." + points-lines-areas: + message: "Deleting {n} features: {p} points, {l} lines, and {a} areas." + points-lines-areas-relations: + message: "Deleting {n} features: {p} points, {l} lines, {a} areas, and {r} relations." tip: Only redundant or nonexistent features should be deleted. missing_tag: message: "{feature} has no descriptive tags." diff --git a/dist/locales/en.json b/dist/locales/en.json index 71e5c09ab..c1a958e4d 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1494,7 +1494,12 @@ "tip": "Names should be the official, on-the-ground titles of features." }, "many_deletions": { - "message": "Deleting {n} features: {p} nodes, {l} lines, {a} areas, and {r} relations.", + "points-lines-areas": { + "message": "Deleting {n} features: {p} points, {l} lines, and {a} areas." + }, + "points-lines-areas-relations": { + "message": "Deleting {n} features: {p} points, {l} lines, {a} areas, and {r} relations." + }, "tip": "Only redundant or nonexistent features should be deleted." }, "missing_tag": { diff --git a/modules/validations/many_deletions.js b/modules/validations/many_deletions.js index a1b2baed2..0e4d1753e 100644 --- a/modules/validations/many_deletions.js +++ b/modules/validations/many_deletions.js @@ -5,30 +5,50 @@ import { export function validationManyDeletions() { - var threshold = 100; + var totalOtherGeomThreshold = 50; + + // relations are less common so use a lower threshold + var relationThreshold = 10; var type = 'many_deletions'; var validation = function(changes, context) { var issues = []; - var nodes = 0, ways = 0, areas = 0, relations = 0; - var graph = context.graph(); - changes.deleted.forEach(function(c) { - if (c.type === 'node') { nodes++; } - else if (c.type === 'way' && c.geometry(graph) === 'line') { ways++; } - else if (c.type === 'way' && c.geometry(graph) === 'area') { areas++; } - else if (c.type === 'relation') { relations++; } + var points = 0, lines = 0, areas = 0, relations = 0; + var base = context.history().base(); + var geometry; + changes.deleted.forEach(function(entity) { + if (entity.type === 'node' && entity.geometry(base) === 'point') { + points++; + } else if (entity.type === 'way') { + geometry = entity.geometry(base); + if (geometry === 'line') { + lines++; + } else if (geometry === 'area') { + areas++; + } + } else if (entity.type === 'relation') { + relations++; + } }); - if (changes.deleted.length > threshold) { + if (points + lines + areas >= totalOtherGeomThreshold || + relations >= relationThreshold) { + + var totalFeatures = points + lines + areas + relations; + + var messageType = 'points-lines-areas'; + if (relations > 0) { + messageType += '-relations'; + } issues.push(new validationIssue({ type: type, severity: 'warning', message: t( - 'issues.many_deletions.message', - { n: changes.deleted.length, p: nodes, l: ways, a:areas, r: relations } + 'issues.many_deletions.'+messageType+'.message', + { n: totalFeatures, p: points, l: lines, a:areas, r: relations } ), tooltip: t('issues.many_deletions.tip'), - hash: [nodes, ways, areas, relations].join() + hash: [points, lines, areas, relations].join() })); }