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 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_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_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 housenumbers_diff_last_modified(relation: areas.Relation) -> str: """Gets the update date for missing/additional housenumbers.""" t_ref = util.get_timestamp( relation.get_files().get_ref_housenumbers_path()) t_osm = util.get_timestamp( relation.get_files().get_osm_housenumbers_path()) return webframe.format_timestamp(max(t_ref, t_osm))
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_txt(ctx: context.Context, relation: areas.Relation) -> str: """Gets the cached plain text of the missing housenumbers for a relation.""" output = "" if is_missing_housenumbers_txt_cached(ctx, relation): with relation.get_files().get_housenumbers_txtcache_stream( "rb") as stream: output = util.from_bytes(stream.read()) return output ongoing_streets, _ignore = relation.get_missing_housenumbers() table = [] for result in ongoing_streets: range_list = util.get_housenumber_ranges(result[1]) range_strings = [i.get_number() for i in range_list] # Street name, only_in_reference items. if not relation.get_config().get_street_is_even_odd( result[0].get_osm_name()): result_sorted = sorted(range_strings, key=util.split_house_number) row = result[0].get_osm_name() + "\t[" + ", ".join( result_sorted) + "]" else: elements = util.format_even_odd(range_list, doc=None) row = result[0].get_osm_name() + "\t[" + "], [".join( elements) + "]" table.append(row) table.sort(key=util.get_lexical_sort_key()) output += "\n".join(table) with relation.get_files().get_housenumbers_txtcache_stream("wb") as stream: stream.write(util.to_bytes(output)) return output
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 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"
def get_additional_housenumbers_html( ctx: context.Context, relation: areas.Relation) -> yattag.doc.Doc: """Gets the cached HTML of the additional housenumbers for a relation.""" doc = yattag.doc.Doc() if is_additional_housenumbers_html_cached(ctx, relation): with relation.get_files().get_additional_housenumbers_htmlcache_stream( "rb") as stream: doc.asis(util.from_bytes(stream.read())) return doc ret = relation.write_additional_housenumbers() todo_street_count, todo_count, table = ret with doc.tag("p"): doc.text( tr("OpenStreetMap additionally has the below {0} house numbers for {1} streets." ).format(str(todo_count), str(todo_street_count))) doc.stag("br") with doc.tag( "a", href="https://github.com/vmiklos/osm-gimmisn/tree/master/doc"): doc.text(tr("Filter incorrect information")) 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_additional_housenumbers_htmlcache_stream( "wb") as stream: stream.write(util.to_bytes(doc.getvalue())) return doc
def filter_for(_complete: bool, relation: areas.Relation) -> bool: r_config = relation.get_config() return r_config.get_refcounty( ) == refcounty_filter and r_config.get_refsettlement( ) == refsettlement_filter
def get_streets_last_modified(relation: areas.Relation) -> str: """Gets the update date of streets for a relation.""" return get_last_modified(relation.get_files().get_osm_streets_path())
def get_housenumbers_last_modified(relation: areas.Relation) -> str: """Gets the update date of house numbers for a relation.""" return get_last_modified(relation.get_files().get_osm_housenumbers_path())
def ref_streets_last_modified(relation: areas.Relation) -> str: """Gets the update date for missing streets.""" t_ref = get_timestamp(relation.get_files().get_ref_streets_path()) t_osm = get_timestamp(relation.get_files().get_osm_streets_path()) return webframe.format_timestamp(max(t_ref, t_osm))
def filter_for(_complete: bool, relation: areas.Relation) -> bool: config = relation.get_config() return config.get_refmegye() == refmegye_filter and config.get_reftelepules() == reftelepules_filter