def is_missing_housenumbers_html_cached(relation: areas.Relation) -> bool: """Decides if we have an up to date cache entry or not.""" cache_path = relation.get_files().get_housenumbers_htmlcache_path() if not os.path.exists(cache_path): return False cache_mtime = os.path.getmtime(cache_path) osm_streets_path = relation.get_files().get_osm_streets_path() osm_streets_mtime = os.path.getmtime(osm_streets_path) if osm_streets_mtime > cache_mtime: return False osm_housenumbers_path = relation.get_files().get_osm_housenumbers_path() osm_housenumbers_mtime = os.path.getmtime(osm_housenumbers_path) if osm_housenumbers_mtime > cache_mtime: return False ref_housenumbers_path = relation.get_files().get_ref_housenumbers_path() ref_housenumbers_mtime = os.path.getmtime(ref_housenumbers_path) if ref_housenumbers_mtime > cache_mtime: return False datadir = config.get_abspath("data") relation_path = os.path.join(datadir, "relation-%s.yaml" % relation.get_name()) relation_mtime = os.path.getmtime(relation_path) if relation_mtime > cache_mtime: return False return True
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"
def handle_main_street_additional_count( relation: areas.Relation) -> yattag.doc.Doc: """Handles the street additional count part of the main page.""" prefix = config.Config.get_uri_prefix() url = prefix + "/additional-streets/" + relation.get_name( ) + "/view-result" additional_count = "" if os.path.exists( relation.get_files().get_streets_additional_count_path()): additional_count = util.get_content( relation.get_files().get_streets_additional_count_path()).decode( "utf-8") doc = yattag.doc.Doc() if additional_count: date = get_last_modified( relation.get_files().get_streets_additional_count_path()) with doc.tag("strong"): with doc.tag("a", href=url, title=_("updated") + " " + date): doc.text(_("{} streets").format(additional_count)) return doc with doc.tag("strong"): with doc.tag("a", href=url): doc.text(_("additional streets")) return doc
def handle_main_housenr_additional_count( ctx: context.Context, relation: areas.Relation) -> yattag.doc.Doc: """Handles the housenumber additional count part of the main page.""" if not relation.get_config().should_check_additional_housenumbers(): return yattag.doc.Doc() prefix = ctx.get_ini().get_uri_prefix() url = prefix + "/additional-housenumbers/" + relation.get_name( ) + "/view-result" additional_count = "" if ctx.get_file_system().path_exists( relation.get_files().get_housenumbers_additional_count_path()): path = relation.get_files().get_housenumbers_additional_count_path() additional_count = util.get_content(path).decode("utf-8").strip() doc = yattag.doc.Doc() if additional_count: date = get_last_modified( relation.get_files().get_housenumbers_additional_count_path()) with doc.tag("strong"): with doc.tag("a", href=url, title=tr("updated") + " " + date): doc.text(tr("{} house numbers").format(additional_count)) return doc with doc.tag("strong"): with doc.tag("a", href=url): doc.text(tr("additional house numbers")) return doc
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"
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
def is_missing_housenumbers_html_cached(ctx: context.Context, relation: areas.Relation) -> bool: """Decides if we have an up to date HTML cache entry or not.""" cache_path = relation.get_files().get_housenumbers_htmlcache_path() datadir = ctx.get_abspath("data") relation_path = os.path.join(datadir, "relation-%s.yaml" % relation.get_name()) dependencies = [ relation.get_files().get_osm_streets_path(), relation.get_files().get_osm_housenumbers_path(), relation.get_files().get_ref_housenumbers_path(), relation_path ] return is_cache_outdated(ctx, cache_path, dependencies)
def handle_main_street_percent(relation: areas.Relation) -> Tuple[yattag.doc.Doc, str]: """Handles the street percent part of the main page.""" url = "/osm/missing-streets/" + relation.get_name() + "/view-result" percent = "N/A" if os.path.exists(relation.get_files().get_streets_percent_path()): percent = util.get_content(relation.get_files().get_streets_percent_path()) 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=_("updated") + " " + date): doc.text(percent + "%") return doc, percent with doc.tag("strong"): with doc.tag("a", href=url): doc.text(_("missing streets")) return doc, "0"