This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Invalid tag modification v2 #149
Open
bkowshik
wants to merge
6
commits into
master
Choose a base branch
from
invalid-tag-modification-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,824
−4
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed56730
Analysis for v2 of invalid-tag-modification
8107648
Graph frequency of primary keys deleted
199099d
Cleaned up modification analysis
a6ae322
Script to scrape osmcha for feature details
8d802b6
Do not flag when all properties are removed
0c32e37
Deletion of one primary tag is OK when there are two or more
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from bs4 import BeautifulSoup | ||
import requests | ||
import csv | ||
import json | ||
|
||
def parse_changeset_page(changeset_id): | ||
"""Parse changeset page to extract feature URLs""" | ||
url = 'http://osmcha.mapbox.com/{}/'.format(changeset_id) | ||
r = requests.get(url) | ||
|
||
# Using BeautifulSoup to parse and scrape feature URLs. | ||
soup = BeautifulSoup(r.text, 'html.parser') | ||
|
||
# Filter by the ID of the collapsible feature. | ||
div = soup.find(id='collapseOne') | ||
table = div.find('table') | ||
|
||
feature_urls = [] | ||
# Skip header row of the table. | ||
for row in table.find_all('tr')[1:]: | ||
reasons = row.find_all('td')[-1].text.strip() | ||
# Not interested in fetures not flagged by the invalid_tag_modification comparator. | ||
if 'modification' not in reasons: continue | ||
feature_url = 'http://osmcha.mapbox.com{}'.format(row.find_all('td')[0].find('a')['href']) | ||
feature_urls.append(feature_url) | ||
return feature_urls | ||
|
||
def parse_feature_page(feature_url): | ||
"""Parse feature page to extract feature details.""" | ||
primaryTags = [ | ||
'aerialway', 'aeroway', 'amenity', 'barrier', 'boundary', 'building', 'craft', 'emergency', | ||
'geological', 'highway', 'historic', 'landuse', 'leisure', 'man_made', 'military', 'natural', | ||
'office', 'places', 'power', 'public_transport', 'railway', 'route', 'shop', 'sport', 'tourism', 'waterway' | ||
] | ||
details = {'created': '', 'deleted': ''} | ||
|
||
r = requests.get(feature_url) | ||
# Using BeautifulSoup to parse and scrape feature details. | ||
soup = BeautifulSoup(r.text, 'html.parser') | ||
|
||
# NOTE: Assuming that the page has only one table. | ||
table = soup.find('table') | ||
|
||
# Skip header row of the table. | ||
for row in table.find_all('tr')[1:]: | ||
tds = [item.text.strip() for item in row.find_all('td')] | ||
# We are only interested in primary feature tags. | ||
if tds[0] not in primaryTags: continue | ||
|
||
if tds[-1] == 'ADDED': details['created'] = tds[0] | ||
elif tds[-1] == 'DELETED': details['deleted'] = tds[0] | ||
return [details['created'], details['deleted']] | ||
|
||
with open('sample.csv') as f: | ||
reader = csv.reader(f) | ||
for row in reader: | ||
try: | ||
changeset_id = str(int(row[0])) | ||
except ValueError: | ||
# For the header of the csv file. | ||
pass | ||
else: | ||
feature_urls = parse_changeset_page(changeset_id) | ||
for feature_url in feature_urls: | ||
# Is the changeset harmful or not in the 15th column. | ||
changeset_details = [changeset_id, row[15], feature_url] | ||
feature_details = parse_feature_page(feature_url) | ||
changeset_details.extend(feature_details) | ||
print(','.join([str(item) for item in changeset_details])) |
1,731 changes: 1,731 additions & 0 deletions
1,731
analysis/invalid-tag-modification/invalid-tag-modification-v2.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,14 @@ function invalidTagModification(newVersion, oldVersion, callback) { | |
var result = {}; | ||
if (!newVersion || !oldVersion) return callback(null, result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we assume that newVersion will always be present in a geojson. And if a feature is deleted, we will check for So |
||
|
||
// If all properties of feature are removed, assume feature is being moved into a relation. | ||
if (Object.keys(newVersion.properties).length === 0) return callback(null, {}); | ||
|
||
var primaryTags = getPrimaryTags(oldVersion.properties); | ||
// Check if all primary tags are retained in newVersion. | ||
for (var i = 0; i < primaryTags.length; i++) { | ||
if (!(primaryTags[i] in newVersion.properties)) return callback(null, {'result:invalid_tag_modification': true}); | ||
// Check if all primary tags are retained in newVersion. | ||
// If not retained, check if there were two primary tags to start with. | ||
if (!(primaryTags[i] in newVersion.properties) && (primaryTags.length < 2)) return callback(null, {'result:invalid_tag_modification': true}); | ||
} | ||
|
||
return callback(null, {}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkowshik 👋 ,instead of returning {} for a false result, we are now following convention to send false value itself. Ref commit: 756c5cb