예제 #1
0
def handle_main_housenr_percent(
        relation: areas.Relation) -> Tuple[yattag.doc.Doc, str]:
    """Handles the house number percent part of the main page."""
    prefix = config.Config.get_uri_prefix()
    url = prefix + "/missing-housenumbers/" + relation.get_name(
    ) + "/view-result"
    percent = "N/A"
    if os.path.exists(relation.get_files().get_housenumbers_percent_path()):
        percent = util.get_content(
            relation.get_files().get_housenumbers_percent_path()).decode(
                "utf-8")

    doc = yattag.doc.Doc()
    if percent != "N/A":
        date = get_last_modified(
            relation.get_files().get_housenumbers_percent_path())
        with doc.tag("strong"):
            with doc.tag("a", href=url, title=_("updated") + " " + date):
                doc.text(util.format_percent(percent))
        return doc, percent

    with doc.tag("strong"):
        with doc.tag("a", href=url):
            doc.text(_("missing house numbers"))
    return doc, "0"
예제 #2
0
def handle_main_street_percent(
        ctx: context.Context,
        relation: areas.Relation) -> Tuple[yattag.doc.Doc, str]:
    """Handles the street percent part of the main page."""
    prefix = ctx.get_ini().get_uri_prefix()
    url = prefix + "/missing-streets/" + relation.get_name() + "/view-result"
    percent = "N/A"
    if ctx.get_file_system().path_exists(
            relation.get_files().get_streets_percent_path()):
        percent = util.get_content(
            relation.get_files().get_streets_percent_path()).decode("utf-8")

    doc = yattag.doc.Doc()
    if percent != "N/A":
        date = get_last_modified(
            relation.get_files().get_streets_percent_path())
        with doc.tag("strong"):
            with doc.tag("a", href=url, title=tr("updated") + " " + date):
                doc.text(util.format_percent(percent))
        return doc, percent

    with doc.tag("strong"):
        with doc.tag("a", href=url):
            doc.text(tr("missing streets"))
    return doc, "0"
예제 #3
0
def get_missing_housenumbers_html(ctx: context.Context,
                                  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(ctx, relation):
        with relation.get_files().get_housenumbers_htmlcache_stream(
                "rb") as stream:
            doc.asis(util.from_bytes(stream.read()))
        return doc

    ret = relation.write_missing_housenumbers()
    todo_street_count, todo_count, done_count, percent, table = ret

    with doc.tag("p"):
        prefix = ctx.get_ini().get_uri_prefix()
        relation_name = relation.get_name()
        doc.text(
            tr("OpenStreetMap is possibly missing the below {0} house numbers for {1} streets."
               ).format(str(todo_count), str(todo_street_count)))
        doc.text(
            tr(" (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(tr("Filter incorrect information"))
        doc.text(".")
        doc.stag("br")
        with doc.tag(
                "a",
                href=prefix +
                "/missing-housenumbers/{}/view-turbo".format(relation_name)):
            doc.text(tr("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(tr("Plain text format"))
        doc.stag("br")
        with doc.tag("a",
                     href=prefix +
                     "/missing-housenumbers/{}/view-result.chkl".format(
                         relation_name)):
            doc.text(tr("Checklist format"))

    doc.asis(util.html_table_from_list(table).getvalue())
    doc.asis(
        util.invalid_refstreets_to_html(
            relation.get_invalid_refstreets()).getvalue())
    doc.asis(
        util.invalid_filter_keys_to_html(
            relation.get_invalid_filter_keys()).getvalue())

    with relation.get_files().get_housenumbers_htmlcache_stream(
            "wb") as stream:
        stream.write(util.to_bytes(doc.getvalue()))

    return doc
예제 #4
0
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
예제 #5
0
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
예제 #6
0
def handle_stats_cityprogress(relations: areas.Relations) -> yattag.doc.Doc:
    """Expected request_uri: e.g. /osm/housenumber-stats/hungary/cityprogress."""
    doc = yattag.doc.Doc()
    doc.asis(get_toolbar(relations).getvalue())

    ref_citycounts: Dict[str, int] = {}
    with open(config.Config.get_reference_citycounts_path(), "r") as stream:
        first = True
        for line in stream.readlines():
            if first:
                first = False
                continue
            cells = line.strip().split('\t')
            if len(cells) < 2:
                continue
            city = cells[0]
            count = int(cells[1])
            ref_citycounts[city] = count
    today = time.strftime("%Y-%m-%d")
    osm_citycounts: Dict[str, int] = {}
    with open(config.Config.get_workdir() + "/stats/" + today + ".citycount",
              "r") as stream:
        for line in stream.readlines():
            cells = line.strip().split('\t')
            if len(cells) < 2:
                continue
            city = cells[0]
            count = int(cells[1])
            osm_citycounts[city] = count
    cities = util.get_in_both(list(ref_citycounts.keys()),
                              list(osm_citycounts.keys()))
    cities.sort(key=locale.strxfrm)
    table = []
    table.append([
        util.html_escape(_("City name")),
        util.html_escape(_("House number coverage")),
        util.html_escape(_("OSM count")),
        util.html_escape(_("Reference count"))
    ])
    for city in cities:
        percent = "100.00"
        if ref_citycounts[city] > 0 and osm_citycounts[city] < ref_citycounts[
                city]:
            percent = "%.2f" % (osm_citycounts[city] / ref_citycounts[city] *
                                100)
        table.append([
            util.html_escape(city),
            util.html_escape(util.format_percent(percent)),
            util.html_escape(str(osm_citycounts[city])),
            util.html_escape(str(ref_citycounts[city]))
        ])
    doc.asis(util.html_table_from_list(table).getvalue())

    with doc.tag("h2"):
        doc.text(_("Note"))
    with doc.tag("div"):
        doc.text(
            _("""These statistics are estimates, not taking house number filters into account.
Only cities with house numbers in OSM are considered."""))

    doc.asis(get_footer().getvalue())
    return doc