Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added opening hours validator. #5

Merged
merged 15 commits into from Sep 6, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*.class
pyopening_hours/
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -10,7 +10,7 @@ Quality Assurance Tools script (qat_script) is a script for JOSM (Java OpenStree

[Video on how to use it](http://bit.ly/ZTwj0Z) (webm, 16.8MB)

### Features:
## Features:

* **Errors download** of currently observed area in JOSM, from different error detectors. The type of error can be selected from a menu or a toggle dialog, in the second case, multiple kinds of error can be downloaded at once.
* **Progressive correction** of downloaded errors by clicking on a button (next, next, next...).
Expand All @@ -21,7 +21,7 @@ Quality Assurance Tools script (qat_script) is a script for JOSM (Java OpenStree
* A list of **favourites checks** can be created by selecting different checks belonging to different tools and find them again quickly.
* A **local GPX file** can be opened. Its waypoints will be used as positions that the user can visits in sequence to check for errors (more info on the [Wiki](http://wiki.openstreetmap.org/wiki/Quality_Assurance_Tools_script)).

### Supported QA Tools:
## Supported QA Tools:

* [OSM Inspector](http://tools.geofabrik.de/osmi/) by GEOFABRIK (only some types of errors)
* [KeepRight](http://keepright.ipax.at/) by Harald Kleiner
Expand Down Expand Up @@ -49,7 +49,7 @@ Credits:
* JOSM OpenStreetBugs Plugin
* Translators: Poppei82 (German), operon (French)

To add a new QA tool read the file tools/README.md.
To add a new QA tool read the file [tools/README.md](tools/README.md).

Note: I wrote a Python script, that can be run in JOSM thanks to [JOSM Scripting plugin](http://gubaer.github.io/josm-scripting-plugin/), rathar than a regular JOSM plugin because I just know Python. I would be happy if someone could create a Java plugin with these features.

Expand All @@ -65,4 +65,4 @@ Their names are in CONTRIBUTORS and CHANGES files.
* qat_script logo.png build upon [Openstreetmap_logo.svg](http://commons.wikimedia.org/wiki/File:Openstreetmap_logo.svg) (CC BY-SA 2.0) and [Red_bug.svg](http://commons.wikimedia.org/wiki/File:Red_bug.svg) by Mushii, Anomie (CC BY-SA 3.0)
* icons of buttons build upon [Green_bug.svg](http://commons.wikimedia.org/wiki/File:Green_bug.svg) by Mushii (CC BY-SA 3.0) and [Red_bug.svg](http://commons.wikimedia.org/wiki/File:Red_bug.svg) by Mushii, Anomie (CC BY-SA 3.0)
* favourites tool icon from [candyadams](http://openclipart.org/detail/93169/star-by-candyadams) (Public Domain)
* browser.png from [Internet-web-browser.svg](http://commons.wikimedia.org/wiki/File:Internet-web-browser.svg) by The Tango! Desktop Project (PD)
* browser.png from [Internet-web-browser.svg](http://commons.wikimedia.org/wiki/File:Internet-web-browser.svg) by The Tango! Desktop Project (PD)
118 changes: 59 additions & 59 deletions tools/FakeTool.py
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

"""
This is a fake tool that may be used as a teplate to add a new QA Tool to QATs
This is a fake tool that may be used as a template to add a new QA Tool to QATs.
"""

from java.lang import Thread
Expand All @@ -17,50 +17,50 @@ class FakeToolTool(Tool):
def __init__(self, app):
self.app = app

#Tool title
# Tool title
self.title = tool title string

#Tool url
# Tool url
self.uri = tool website string | ""
#url: web site of the tool
#"": none
# url: web site of the tool
# "": none

#Translations
# Translations
self.isTranslated = True | False
#the translations for a tool are in tool directory/locale
# the translations for a tool are in tool directory/locale


#Additional preferences for this tool
# Additional preferences for this tool
self.prefsGui = None | Java Component
#There are additional preferences for this tool. See Osmose for example
# There are additional preferences for this tool. See Osmose for example

#Marker position
# Marker position
self.markerPosition = (x, y) | None
#x: x position of marker relative to the error
#y: y position of marker relative to the error
#None: the marker's center will be positioned at the error coordinates
# x: x position of marker relative to the error
# y: y position of marker relative to the error
# None: the marker's center will be positioned at the error coordinates
# useful for markers with the shape of a circle or a square

#Corrected errors
# Corrected errors
self.fixedFeedbackMode = "url" | None
#"url": the user can automatically report to the tool admin that an error has been corrected
#(by clicking correctedBtn --> self.sayBugFixed())
#None: the user cannot automatically report to the tool admin when an error has been corrected:
# "url": the user can automatically report to the tool admin that an error has been corrected
# (by clicking correctedBtn --> self.sayBugFixed())
# None: the user cannot automatically report to the tool admin when an error has been corrected:

#False positives
# False positives
self.falseFeedbackMode = "url" | "msg"
#"url": the user can automatically report to the tool admin that an error is not an error
#(by clicking fixeddBtn --> self.sayFalseBug())
#msg: the user can report manually, e.g. by e-mail, to the tool admin that an error is not an error:
#In this case, when the user clicks on the "Not an error" button, current error information
#are collected and shown under the menu "QA Tools" --> "False positives",
#so that the user can copy them and send the info manually to the tool admin.

#Tool checks
#... are listed in toolInfo and grouped in categories (called views)
#(like "Tagging", "Routing..."), which are used to create submenus and
#comboboxes in JOSM.
#{view: [title, name, url, icon, marker], ...}
# "url": the user can automatically report to the tool admin that an error is not an error
# (by clicking fixeddBtn --> self.sayFalseBug())
# msg: the user can report manually, e.g. by e-mail, to the tool admin that an error is not an error:
# In this case, when the user clicks on the "Not an error" button, current error information
# are collected and shown under the menu "QA Tools" --> "False positives",
# so that the user can copy them and send the info manually to the tool admin.

# Tool checks
# ... are listed in toolInfo and grouped in categories (called views)
# (like "Tagging", "Routing..."), which are used to create submenus and
# comboboxes in JOSM.
# {view: [title, name, url, icon, marker], ...}
self.toolInfo = {
"View name" : [
["descriptive title of the check showed in GUI",
Expand All @@ -74,55 +74,55 @@ def __init__(self, app):
]}
Tool.__init__(self, app)

#if there is not an icon for a check in 'tool directory/icons/checks/check name' a red dot is used.
# if there is not an icon for a check in 'tool directory/icons/checks/check name' a red dot is used.

#MANDATORY
# MANDATORY
def download_urls(self, (zoneBbox, checks)):
"""This method accepts a list of checks and returns
a list of {"checks": checks list, "url": url} for each request
that is needed to donwload all the checks.
that is needed to download all the checks.
If the errors from all the checks can be downloaded with just
one url, a list with one dictionary must be returned
one url, a list with one dictionary must be returned.
"""
#Example for KeepRight
# Example for KeepRight
url = "http://keepright.ipax.at/export.php?format=gpx"
url += "&left=%s&right=%s&top=%s&bottom=%s" % (str(zoneBbox[0]), str(zoneBbox[2]), str(zoneBbox[3]), str(zoneBbox[1]))
url += "&ch=0,%s" % ",".join([check.url for check in checks])
return [{"checks": checks, "url": url}]

#optional: if self.fixedFeedbackMode == "url"
# optional: if self.fixedFeedbackMode == "url"
def sayBugFixed(self, error, check):
"""Tell tool the server that the current error is fixed.
Not necessary if the tool does not support automatic report.
"""
#Example for KeepRight
# Example for KeepRight
url = "http://keepright.ipax.at/comment.php?"
url += "st=ignore_t&"
if len(error.other) != 0:
#There is a comment on the error, copy it
# There is a comment on the error, copy it
url += "co=%s&" % error.other[0]
url += "schema=%s&" % error.errorId[:2]
url += "id=%s" % error.errorId[2:]

self.reportToToolServer(url)

#optional: if self.falseFeedbackMode == "url"
# optional: if self.falseFeedbackMode == "url"
def sayFalseBug(self, error, check):
"""Tell the tool server that current error is a false
positive. Not necessary if the tool does not support automatic report.
"""
#Example for KeepRight
# Example for KeepRight
url = "http://keepright.ipax.at/comment.php?"
url += "st=ignore&"
if len(error.other) != 0:
#There is a comment on the error, copy it
# There is a comment on the error, copy it
url += "co=%s&" % error.other[0]
url += "schema=%s&" % error.errorId[:2]
url += "id=%s" % error.errorId[2:]

self.reportToToolServer(url)

#MANDATORY. Return "" if there isn't any web page
# MANDATORY. Return "" if there isn't any web page
def error_url(self, error):
"""Create a url to view an error in the web browser
"""
Expand All @@ -131,66 +131,66 @@ def error_url(self, error):
url += "&error=%s" % error.errorId.split(" ")[1]
return url

#MANDATORY. Return "" if there isn't any web page
# MANDATORY. Return "" if there isn't any web page
def help_url(self, check):
"""Create a url to show some info/help on this check, for example
a webpage on the OSM Wiki about a specific check
a webpage on the OSM Wiki about a specific check.
"""
#Example for Osmose: http://wiki.openstreetmap.org/wiki/Osmose/errors#1040
# Example for Osmose: http://wiki.openstreetmap.org/wiki/Osmose/errors#1040
url = "http://wiki.openstreetmap.org/wiki/Osmose/errors#%s" % check.name
return url

#MANDATORY. A method for error file parsing.
#The error can be a GML (see: OSM Inspector, KeepRight...) or JSON (see Osmose)
def parse_error_file(self, parseTask def parse_error_file(self, parseTask):
# MANDATORY. A method for error file parsing.
# The error can be a GML (see: OSM Inspector, KeepRight...) or JSON (see Osmose)
def parse_error_file(self, parseTask):
"""Extract errors from GPX file
"""
checks = parseTask.checks
#List of features
# List of features
checksWithoutSubs = [int(c.name) // 10 for c in checks if c.name[-1] == "0"]

rootElement = parseTask.extractRootElement()
listOfFeatures = rootElement.getElementsByTagName("wpt")
featuresNumber = listOfFeatures.getLength()
#print "Total number of features: ", featuresNumber
# print "Total number of features: ", featuresNumber
for i in range(featuresNumber):
if Thread.currentThread().isInterrupted():
return False
featureNode = listOfFeatures.item(i)
#errorId
# errorId
schemaNode = featureNode.getElementsByTagName("schema")
schema = str(schemaNode.item(0).getFirstChild().getNodeValue())
errorIdNode = featureNode.getElementsByTagName("id")
errorId = schema + " " + str(errorIdNode.item(0).getFirstChild().getNodeValue())
#desc
# desc
descNode = featureNode.getElementsByTagName("desc")
desc = descNode.item(0).getFirstChild().getNodeValue()
#comment
# comment
commentNode = featureNode.getElementsByTagName("comment")
if commentNode.getLength() != 0:
comment = commentNode.item(0).getFirstChild().getNodeValue()
other = [comment]
desc += "<br>Comment - %s" % comment
else:
other = []
#osmObject
# osmObject
osmObjectNode = featureNode.getElementsByTagName("object_type")
osmObject = str(osmObjectNode.item(0).getFirstChild().getNodeValue())
#osmId
# osmId
osmIdNode = featureNode.getElementsByTagName("object_id")
osmId = osmObject[0] + str(osmIdNode.item(0).getFirstChild().getNodeValue())
#errorType
# errorType
errorTypeNode = featureNode.getElementsByTagName("error_type")
errorType = str(errorTypeNode.item(0).getFirstChild().getNodeValue())
#geo
# geo
lat = float(featureNode.getAttribute("lat"))
lon = float(featureNode.getAttribute("lon"))
bbox = parseTask.build_bbox(lat, lon)

#Append to errors
# Append to errors
if errorType in parseTask.errors:
parseTask.errors[errorType].append((osmId, (lat, lon), bbox, errorId, desc, other))
#check if it is a subtype
# check if it is a subtype
elif int(errorType) // 10 in checksWithoutSubs:
et = str(int(errorType) // 10 * 10)
parseTask.errors[et].append((osmId, (lat, lon), bbox, errorId, desc, other))
Expand Down
13 changes: 5 additions & 8 deletions tools/README.md
Expand Up @@ -2,17 +2,14 @@ Adding a new quality assurance tool to the script
=================================================
New Quality Assurance Tools can be added to the script:

1. create a new directory 'qat_script/tools/data/NameOfTheTool'
2. create a new file 'qat_script/tools/data/NameOfTheTool/NameOfTheTool.py', with a class 'NameOfTheToolTool' in it.<br>Use tools/FakeTool.py as a template
3. add 'NameOfTheTool' to the list of tools in 'qat_script/tools/Tools_list.properties' (not beyond 'Favourites').
1. Create a new directory 'qat_script/tools/data/NameOfTheTool'.
2. Create a new file 'qat_script/tools/data/NameOfTheTool/NameOfTheTool.py', with a class 'NameOfTheToolTool' in it. Use tools/FakeTool.py as a template.
3. Add 'NameOfTheTool' to the list of tools in 'qat_script/tools/tools_list.properties' (not beyond 'Favourites').

The script regularly checks for tools updates from git repository. If you choose to download the updates you must then manually add your tool's name to 'qat_script/tools/Tools_list.properties' again.
The script regularly checks for tools updates from git repository. If you choose to download the updates you must then manually add your tool's name to 'qat_script/tools/tools_list.properties' again.

Using a local file with errors
==============================
If you have found some errors in OSM and you want to review them in sequence with qat_script in JOSM, instead of creating a new tool you may create a GPX file with the errors as waypoints.
If you have found some errors in OSM and you want to review them in sequence with qat_script in JOSM, instead of creating a new tool you may create a GPX file with the errors as way points.

See the [Wiki](http://wiki.openstreetmap.org/wiki/Quality_Assurance_Tools_script#Local_file) for more information.



1 change: 1 addition & 0 deletions tools/data/OpeningHoursValidator/.gitignore
@@ -0,0 +1 @@
i18n-resources.js