Skip to content

Commit

Permalink
Merge pull request #48 from willemarcel/comments_count-field
Browse files Browse the repository at this point in the history
track changesets' comment_count field
  • Loading branch information
willemarcel authored Sep 28, 2020
2 parents 7a8eacf + 0658119 commit 0907c2b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Change Log
==========

[0.8.0] - 2020-09-28
* Register comments_count field

[0.7.0] - 2020-08-04

* Register changeset arbitrary tags under the metadata field
Expand Down
2 changes: 1 addition & 1 deletion osmcha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# osmcha
__version__ = '0.7.0'
__version__ = '0.8.0'
11 changes: 7 additions & 4 deletions osmcha/changeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
'MAPBOX_USERS_API',
'https://osm-comments-api.mapbox.com/api/v1/users/id/{user_id}?extra=true'
)
MANDATORY_TAGS = ['id', 'user', 'uid', 'bbox', 'created_at']
# information that we get from changeset xml key
MANDATORY_TAGS = ['id', 'user', 'uid', 'bbox', 'created_at', 'comments_count']
# fields that will be removed on the Analyse.get_dict() method
FIELDS_TO_REMOVE = [
'create_threshold', 'modify_threshold', 'illegal_sources',
Expand Down Expand Up @@ -86,8 +87,8 @@ def get_user_details(user_id):


def changeset_info(changeset):
"""Return a dictionary with id, user, user_id, bounds, date of creation
and all the tags of the changeset.
"""Return a dictionary with id, user, user_id, bounds, date of creation,
comments_count and all the tags of the changeset.
Args:
changeset: the XML string of the changeset.
Expand All @@ -97,7 +98,8 @@ def changeset_info(changeset):
values = [tag.attrib.get('v') for tag in changeset]
values += [
changeset.get('id'), changeset.get('user'), changeset.get('uid'),
get_bounds(changeset), changeset.get('created_at')
get_bounds(changeset), changeset.get('created_at'),
changeset.get('comments_count')
]

return dict(zip(keys, values))
Expand Down Expand Up @@ -290,6 +292,7 @@ def set_fields(self, changeset):
self.host = changeset.get('host', 'Not reported')
self.bbox = changeset.get('bbox').wkt
self.comment = changeset.get('comment', 'Not reported')
self.comments_count = int(changeset.get('comments_count', 0))
self.source = changeset.get('source', 'Not reported')
self.imagery_used = changeset.get('imagery_used', 'Not reported')
self.date = datetime.strptime(
Expand Down
40 changes: 37 additions & 3 deletions tests/test_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_changeset_list():
assert c.changesets[0]['user'] == 'GarrettB'
assert c.changesets[0]['uid'] == '352373'
assert c.changesets[0]['comment'] == 'Added Emerald Pool Waterfall'
assert c.changesets[0]['comments_count'] == '0'
assert c.changesets[0]['bbox'] == Polygon([
(-71.0646843, 44.2371354), (-71.0048652, 44.2371354),
(-71.0048652, 44.2430624), (-71.0646843, 44.2430624),
Expand All @@ -66,6 +67,7 @@ def test_analyse_init():
'build': '2.3-650-gad99430',
'version': '2.3',
'comment': 'Put data from Google',
'comments_count': '12',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -79,6 +81,7 @@ def test_analyse_init():
assert ch.id == 1
assert ch.editor == 'Potlatch 2'
assert ch.comment == 'Put data from Google'
assert ch.comments_count == 12
assert ch.user == 'JustTest'
assert ch.uid == '123123'
assert ch.date == datetime(2015, 4, 25, 18, 8, 46)
Expand All @@ -92,6 +95,7 @@ def test_analyse_label_suspicious():
'build': '2.3-650-gad99430',
'version': '2.3',
'comment': 'Put data from Google',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand Down Expand Up @@ -120,6 +124,7 @@ def test_analyse_verify_words():
'build': '2.3-650-gad99430',
'version': '2.3',
'comment': 'Put data from Google',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -140,6 +145,7 @@ def test_analyse_verify_words():
'build': '2.3-650-gad99430',
'version': '2.3',
'source': 'Waze',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -161,6 +167,7 @@ def test_analyse_verify_words():
'version': '2.3',
'imagery_used': 'Custom (http://{switch:a,b,c}.tiles.googlemaps.com/{zoom}/{x}/{y}.png)',
'source': 'Bing',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -181,6 +188,7 @@ def test_analyse_verify_words():
'build': '2.3-650-gad99430',
'version': '2.3',
'comment': 'Somewhere in Brazil',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -200,6 +208,7 @@ def test_analyse_verify_words():
'build': '2.3-650-gad99430',
'version': '2.3',
'comment': 'Somewhere in Brazil',
'comments_count': '1',
'source': 'Yandex Panorama',
'id': '1',
'user': 'JustTest',
Expand All @@ -221,6 +230,7 @@ def test_analyse_verify_editor_josm():
'created_by': 'JOSM/1.5 (8339 en)',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '3',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -241,6 +251,7 @@ def test_analyse_verify_editor_merkaartor():
'created_by': 'Merkaartor 0.18 (de)',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '3',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -261,6 +272,7 @@ def test_analyse_verify_editor_level0():
'created_by': 'Level0 v1.1',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -281,6 +293,7 @@ def test_analyse_verify_editor_qgis():
'created_by': 'QGIS plugin',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -304,6 +317,7 @@ def test_analyse_verify_editor_id_osm():
'host': 'https://www.openstreetmap.org/edit',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -328,6 +342,7 @@ def test_analyse_verify_editor_id_improveosm():
'host': 'http://improveosm.org/',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -352,6 +367,7 @@ def test_analyse_verify_editor_id_strava():
'host': 'https://strava.github.io/iD/',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -374,6 +390,7 @@ def test_analyse_verify_editor_rapid():
'host': 'https://mapwith.ai/rapid',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -396,6 +413,7 @@ def test_analyse_verify_editor_rapid_test():
'host': 'https://mapwith.ai/rapidtest',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '5',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -420,6 +438,7 @@ def test_verify_editor_id_unknown_instance():
'host': 'http://anotherhost.com/iD',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '2',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -445,6 +464,7 @@ def test_verify_editor_id_is_known_instance():
'host': 'https://www.openstreetmap.org/iD',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -470,6 +490,7 @@ def test_verify_editor_netlify_id_is_known_instance():
'host': 'https://ideditor.netlify.app/',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '4',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -495,6 +516,7 @@ def test_verify_hotosm_id_is_known_instance():
'host': 'https://tasks.teachosm.org/projects/23/map/',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -509,6 +531,7 @@ def test_verify_hotosm_id_is_known_instance():
'host': 'https://tasks.hotosm.org/projects/23/map/',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand Down Expand Up @@ -536,6 +559,7 @@ def test_analyse_verify_editor_Potlatch2():
'created_by': 'Potlatch 2',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand Down Expand Up @@ -667,6 +691,7 @@ def test_get_dict():
assert 'bbox' in ch.get_dict().keys()
assert 'date' in ch.get_dict().keys()
assert 'comment' in ch.get_dict().keys()
assert 'comments_count' in ch.get_dict().keys()
assert 'source' in ch.get_dict().keys()
assert 'imagery_used' in ch.get_dict().keys()
assert 'is_suspect' in ch.get_dict().keys()
Expand All @@ -677,7 +702,7 @@ def test_get_dict():
assert 'delete' in ch.get_dict().keys()
assert 'metadata' in ch.get_dict().keys()
assert ch.get_dict()['metadata']['host'] == 'https://www.openstreetmap.org/id'
assert len(ch.get_dict().keys()) == 16
assert len(ch.get_dict().keys()) == 17

# An iD changeset with warnings:
ch = Analyse(72783703)
Expand All @@ -689,6 +714,7 @@ def test_get_dict():
assert 'bbox' in ch.get_dict().keys()
assert 'date' in ch.get_dict().keys()
assert 'comment' in ch.get_dict().keys()
assert 'comments_count' in ch.get_dict().keys()
assert 'source' in ch.get_dict().keys()
assert 'imagery_used' in ch.get_dict().keys()
assert 'is_suspect' in ch.get_dict().keys()
Expand All @@ -702,7 +728,8 @@ def test_get_dict():
assert ch.get_dict()['metadata']['locale'] == 'en-US'
assert ch.get_dict()['metadata']['warnings:crossing_ways'] == 1
assert ch.get_dict()['metadata']['changesets_count'] == 5970
assert len(ch.get_dict().keys()) == 16
assert ch.get_dict()['comments_count'] == 2
assert len(ch.get_dict().keys()) == 17

# A JOSM changeset
ch = Analyse(46315321)
Expand All @@ -714,6 +741,7 @@ def test_get_dict():
assert 'bbox' in ch.get_dict().keys()
assert 'date' in ch.get_dict().keys()
assert 'comment' in ch.get_dict().keys()
assert 'comments_count' in ch.get_dict().keys()
assert 'source' in ch.get_dict().keys()
assert 'imagery_used' in ch.get_dict().keys()
assert 'is_suspect' in ch.get_dict().keys()
Expand All @@ -724,7 +752,7 @@ def test_get_dict():
assert 'delete' in ch.get_dict().keys()
assert 'metadata' in ch.get_dict().keys()
assert ch.get_dict()['metadata'] == {}
assert len(ch.get_dict().keys()) == 16
assert len(ch.get_dict().keys()) == 17


def test_changeset_without_tags():
Expand Down Expand Up @@ -782,6 +810,7 @@ def test_changeset_with_review_requested():
'created_by': 'Potlatch 2',
'created_at': '2015-04-25T18:08:46Z',
'comment': 'add pois',
'comments_count': '1',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -804,6 +833,7 @@ def test_changeset_with_warning_tag_almost_junction():
'created_at': '2019-04-25T18:08:46Z',
'host': 'https://www.openstreetmap.org/edit',
'comment': 'add pois',
'comments_count': '3',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand Down Expand Up @@ -836,6 +866,7 @@ def test_changeset_with_warning_tag_close_nodes():
'created_at': '2019-04-25T18:08:46Z',
'host': 'https://www.openstreetmap.org/edit',
'comment': 'add pois',
'comments_count': '13',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -858,6 +889,7 @@ def test_changeset_with_warning_tag_crossing_ways():
'created_at': '2019-04-25T18:08:46Z',
'host': 'https://www.openstreetmap.org/edit',
'comment': 'add pois',
'comments_count': '0',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand All @@ -880,6 +912,7 @@ def test_changeset_with_warning_tag_disconnected_way():
'created_at': '2019-04-25T18:08:46Z',
'host': 'https://www.openstreetmap.org/edit',
'comment': 'add pois',
'comments_count': '2',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand Down Expand Up @@ -910,6 +943,7 @@ def test_changeset_with_warning_tag_fix_me():
'created_at': '2019-04-25T18:08:46Z',
'host': 'https://www.openstreetmap.org/edit',
'comment': 'add pois',
'comments_count': '3',
'id': '1',
'user': 'JustTest',
'uid': '123123',
Expand Down

0 comments on commit 0907c2b

Please sign in to comment.