Ejemplo n.º 1
0
    def get_missing_housenumbers(
        self
    ) -> Tuple[List[Tuple[util.Street, List[util.HouseNumber]]], List[Tuple[
            util.Street, List[util.HouseNumber]]]]:
        """
        Compares ref and osm house numbers, prints the ones which are in ref, but not in osm.
        Return value is a pair of ongoing and done streets.
        Each of of these is a pair of a street name and a house number list.
        """
        ongoing_streets = []
        done_streets = []

        osm_street_names = self.get_osm_streets()
        all_ref_house_numbers = self.__get_ref_housenumbers()
        for osm_street in osm_street_names:
            osm_street_name = osm_street.get_osm_name()
            ref_house_numbers = all_ref_house_numbers[osm_street_name]
            osm_house_numbers = self.get_osm_housenumbers(osm_street_name)
            only_in_reference = util.get_only_in_first(ref_house_numbers,
                                                       osm_house_numbers)
            in_both = util.get_in_both(ref_house_numbers, osm_house_numbers)
            ref_street_name = get_ref_street_from_osm_street(
                self.get_config(), osm_street_name)
            street = util.Street(osm_street_name, ref_street_name,
                                 self.should_show_ref_street(osm_street_name))
            if only_in_reference:
                ongoing_streets.append((street, only_in_reference))
            if in_both:
                done_streets.append((street, in_both))
        # Sort by length.
        ongoing_streets.sort(key=lambda result: len(result[1]), reverse=True)

        return ongoing_streets, done_streets
Ejemplo n.º 2
0
    def get_missing_streets(self) -> Tuple[List[str], List[str]]:
        """Tries to find missing streets in a relation."""
        reference_streets = self.get_ref_streets()
        street_blacklist = self.get_config().get_street_filters()
        osm_streets = [self.get_ref_street_from_osm_street(street) for street in self.get_osm_streets()]

        only_in_reference = util.get_only_in_first(reference_streets, osm_streets)
        only_in_reference = [i for i in only_in_reference if i not in street_blacklist]
        in_both = util.get_in_both(reference_streets, osm_streets)

        return only_in_reference, in_both
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def test_happy(self) -> None:
     """Tests that happy path."""
     self.assertEqual(util.get_in_both(["1", "2", "3"], ["2", "3", "4"]),
                      ["2", "3"])