def missing_streets_view_result(relations: areas.Relations, request_uri: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/missing-streets/budapest_11/view-result.""" tokens = request_uri.split("/") relation_name = tokens[-2] relation = relations.get_relation(relation_name) doc = yattag.doc.Doc() prefix = config.Config.get_uri_prefix() if not os.path.exists(relation.get_files().get_osm_streets_path()): doc.asis( webframe.handle_no_osm_streets(prefix, relation_name).getvalue()) return doc if not os.path.exists(relation.get_files().get_ref_streets_path()): doc.asis( webframe.handle_no_ref_streets(prefix, relation_name).getvalue()) return doc ret = relation.write_missing_streets() todo_count, done_count, percent, streets = ret streets.sort(key=locale.strxfrm) table = [[util.html_escape(_("Street name"))]] for street in streets: table.append([util.html_escape(street)]) with doc.tag("p"): doc.text( _("OpenStreetMap is possibly missing the below {0} streets."). format(str(todo_count))) doc.text( _(" (existing: {0}, ready: {1}).").format( str(done_count), util.format_percent(str(percent)))) doc.stag("br") with doc.tag("a", href=prefix + "/missing-streets/{}/view-turbo".format(relation_name)): doc.text( _("Overpass turbo query for streets with questionable names")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-streets/" + relation_name + "/view-result.txt"): doc.text(_("Plain text format")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-streets/" + relation_name + "/view-result.chkl"): doc.text(_("Checklist format")) doc.asis(util.html_table_from_list(table).getvalue()) doc.asis( util.invalid_refstreets_to_html( areas.get_invalid_refstreets(relation)).getvalue()) doc.asis( util.invalid_filter_keys_to_html( areas.get_invalid_filter_keys(relation)).getvalue()) return doc
def get_missing_housenumbers_html(relation: areas.Relation) -> yattag.doc.Doc: """Gets the cached HTML of the missing housenumbers for a relation.""" doc = yattag.doc.Doc() if is_missing_housenumbers_html_cached(relation): with relation.get_files().get_housenumbers_htmlcache_stream( "r") as stream: doc.asis(stream.read()) return doc ret = relation.write_missing_housenumbers() todo_street_count, todo_count, done_count, percent, table = ret with doc.tag("p"): prefix = config.Config.get_uri_prefix() relation_name = relation.get_name() doc.text( _("OpenStreetMap is possibly missing the below {0} house numbers for {1} streets." ).format(str(todo_count), str(todo_street_count))) doc.text( _(" (existing: {0}, ready: {1}).").format( str(done_count), util.format_percent(str(percent)))) doc.stag("br") with doc.tag( "a", href="https://github.com/vmiklos/osm-gimmisn/tree/master/doc"): doc.text(_("Filter incorrect information")) doc.text(".") doc.stag("br") with doc.tag( "a", href=prefix + "/missing-housenumbers/{}/view-turbo".format(relation_name)): doc.text(_("Overpass turbo query for the below streets")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-result.txt".format( relation_name)): doc.text(_("Plain text format")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-result.chkl".format( relation_name)): doc.text(_("Checklist format")) doc.asis(util.html_table_from_list(table).getvalue()) doc.asis( util.invalid_refstreets_to_html( areas.get_invalid_refstreets(relation)).getvalue()) doc.asis( util.invalid_filter_keys_to_html( areas.get_invalid_filter_keys(relation)).getvalue()) with relation.get_files().get_housenumbers_htmlcache_stream("w") as stream: stream.write(doc.getvalue()) return doc
def main() -> None: """Commandline interface.""" workdir = config.Config.get_workdir() relations = areas.Relations(workdir) for relation in relations.get_relations(): invalid_refstreets = areas.get_invalid_refstreets(relation) osm_invalids, ref_invalids = invalid_refstreets if not osm_invalids and not ref_invalids: continue print(relation.get_name() + ": " + str(invalid_refstreets))
def handle_invalid_refstreets(relations: areas.Relations) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/housenumber-stats/hungary/invalid-refstreets.""" doc = yattag.doc.Doc() doc.asis(get_toolbar(relations).getvalue()) for relation in relations.get_relations(): invalid_refstreets = areas.get_invalid_refstreets(relation) osm_invalids, ref_invalids = invalid_refstreets if not osm_invalids and not ref_invalids: continue with doc.tag("h1"): doc.text(relation.get_name()) doc.asis( util.invalid_refstreets_to_html(invalid_refstreets).getvalue()) doc.asis(get_footer().getvalue()) return doc
def missing_housenumbers_view_res(relations: areas.Relations, request_uri: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/missing-housenumbers/ormezo/view-result.""" tokens = request_uri.split("/") relation_name = tokens[-2] doc = yattag.doc.Doc() relation = relations.get_relation(relation_name) prefix = config.Config.get_uri_prefix() if not os.path.exists(relation.get_files().get_osm_streets_path()): doc.asis(webframe.handle_no_osm_streets(prefix, relation_name).getvalue()) elif not os.path.exists(relation.get_files().get_osm_housenumbers_path()): doc.asis(webframe.handle_no_osm_housenumbers(prefix, relation_name).getvalue()) elif not os.path.exists(relation.get_files().get_ref_housenumbers_path()): doc.asis(webframe.handle_no_ref_housenumbers(prefix, relation_name).getvalue()) else: ret = relation.write_missing_housenumbers() todo_street_count, todo_count, done_count, percent, table = ret with doc.tag("p"): doc.text(_("OpenStreetMap is possibly missing the below {0} house numbers for {1} streets.") .format(str(todo_count), str(todo_street_count))) doc.text(_(" (existing: {0}, ready: {1}).").format(str(done_count), util.format_percent(str(percent)))) doc.stag("br") with doc.tag("a", href="https://github.com/vmiklos/osm-gimmisn/tree/master/doc"): doc.text(_("Filter incorrect information")) doc.text(".") doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-turbo".format(relation_name)): doc.text(_("Overpass turbo query for the below streets")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-result.txt".format(relation_name)): doc.text(_("Plain text format")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-result.chkl".format(relation_name)): doc.text(_("Checklist format")) doc.asis(util.html_table_from_list(table).getvalue()) doc.asis(util.invalid_refstreets_to_html(areas.get_invalid_refstreets(relation)).getvalue()) doc.asis(util.invalid_filter_keys_to_html(areas.get_invalid_filter_keys(relation)).getvalue()) return doc
def handle_invalid_refstreets(relations: areas.Relations) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/housenumber-stats/hungary/invalid-relations.""" doc = yattag.doc.Doc() doc.asis(get_toolbar(relations).getvalue()) prefix = config.Config.get_uri_prefix() for relation in relations.get_relations(): invalid_refstreets = areas.get_invalid_refstreets(relation) osm_invalids, ref_invalids = invalid_refstreets key_invalids = areas.get_invalid_filter_keys(relation) if not osm_invalids and not ref_invalids and not key_invalids: continue with doc.tag("h1"): relation_name = relation.get_name() with doc.tag("a", href=prefix + "/streets/" + relation_name + "/view-result"): doc.text(relation_name) doc.asis( util.invalid_refstreets_to_html(invalid_refstreets).getvalue()) doc.asis(util.invalid_filter_keys_to_html(key_invalids).getvalue()) doc.asis(get_footer().getvalue()) return doc
def additional_streets_view_result(relations: areas.Relations, request_uri: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/additional-streets/budapest_11/view-result.""" tokens = request_uri.split("/") relation_name = tokens[-2] relation = relations.get_relation(relation_name) doc = yattag.doc.Doc() prefix = config.Config.get_uri_prefix() if not os.path.exists(relation.get_files().get_osm_streets_path()): doc.asis( webframe.handle_no_osm_streets(prefix, relation_name).getvalue()) elif not os.path.exists(relation.get_files().get_ref_streets_path()): doc.asis( webframe.handle_no_ref_streets(prefix, relation_name).getvalue()) else: # Get "only in OSM" streets. streets = relation.write_additional_streets() count = len(streets) streets.sort(key=lambda street: locale.strxfrm(street.get_osm_name())) table = [[ util.html_escape(_("Identifier")), util.html_escape(_("Type")), util.html_escape(_("Source")), util.html_escape(_("Street name")) ]] for street in streets: cell = yattag.doc.Doc() href = "https://www.openstreetmap.org/{}/{}".format( street.get_osm_type(), street.get_osm_id()) with cell.tag("a", href=href, target="_blank"): cell.text(str(street.get_osm_id())) cells = [ cell, util.html_escape(street.get_osm_type()), util.html_escape(street.get_source()), util.html_escape(street.get_osm_name()), ] table.append(cells) with doc.tag("p"): doc.text( _("OpenStreetMap additionally has the below {0} streets."). format(str(count))) doc.stag("br") with doc.tag("a", href=prefix + "/additional-streets/" + relation_name + "/view-result.txt"): doc.text(_("Plain text format")) doc.stag("br") with doc.tag("a", href=prefix + "/additional-streets/" + relation_name + "/view-result.chkl"): doc.text(_("Checklist format")) doc.stag("br") with doc.tag( "a", href=prefix + "/additional-streets/{}/view-turbo".format(relation_name)): doc.text(_("Overpass turbo query for the below streets")) doc.asis(util.html_table_from_list(table).getvalue()) doc.asis( util.invalid_refstreets_to_html( areas.get_invalid_refstreets(relation)).getvalue()) return doc