Ejemplo n.º 1
0
def test_diff():
    diff: AddressDiff = create_diff()

    assert len(diff.matches) == 3
    assert len(diff.missing) == 2
    assert len(diff.surplus) == 2
    assert diff.num_matches == 3
    assert diff.num_missing_not_ignored == 1
    assert diff.num_surplus_not_ignored == 1
    assert round(abs(diff.coverage_in_percent - 75.0), 1) == 0

    assert diff.matches[Address('Identical Street', '1')] == MatchInformation(
        OsmPrimitive('way', 1), Coordinate(1.1, 1.2))
    assert diff.matches[Address('Identical Street', '7')] == MatchInformation(
        OsmPrimitive('way', 7), Coordinate(7.1, 7.2))
    assert diff.matches[Address('Identical Street', '13')] == MatchInformation(
        OsmPrimitive('way', 13), Coordinate(13.1, 13.2))
    assert diff.missing[Address('Missing Street',
                                '2')] == MissingAddressInformation(
                                    Coordinate(2.1, 2.2), None)
    assert diff.missing[Address('Missing Street', '3')] == \
           MissingAddressInformation(Coordinate(3.1, 3.2), IgnoredAddressInformation(False, 'building does not exist', ignore_date))
    assert diff.surplus[0] == (Address('Surplus Street', '4'),
                               SurplusInformation(
                                   OsmPrimitive('node', 31),
                                   IgnoredAddressInformation(
                                       True, 'building does exist',
                                       ignore_date)))
    assert diff.surplus[1] == (Address('Surplus Street', '3'),
                               SurplusInformation(OsmPrimitive('way', 32),
                                                  None))

    return diff
Ejemplo n.º 2
0
def create_diff():
    address_diff = AddressDiffComputation()
    reference = {
        Address('Identical Street', '1'): Coordinate(1.1, 1.2),
        Address('Identical Street', '7'): Coordinate(7.1, 7.2),
        Address('Identical Street', '13'): Coordinate(13.1, 13.2),
        Address('Missing Street', '2'): Coordinate(2.1, 2.2),
        Address('Missing Street', '2'):
        Coordinate(2.1, 2.2),  # duplicate in reference set
        Address('Missing Street', '3'): Coordinate(3.1, 3.2)
    }
    actual = [(Address('Identical Street', '1'), OsmPrimitive('way', 1)),
              (Address('Identical Street', '7'), OsmPrimitive('way', 7)),
              (Address('Identical Street', '13'), OsmPrimitive('way', 13)),
              (Address('Surplus Street', '4'), OsmPrimitive('node', 31)),
              (Address('Surplus Street', '3'), OsmPrimitive('way', 32))
              ]  # way and node with same address, to be reported twice
    ignored = {
        Address('Missing Street', '3'):
        IgnoredAddressInformation(False, 'building does not exist',
                                  ignore_date),
        Address('Surplus Street', '4'):
        IgnoredAddressInformation(True, 'building does exist', ignore_date)
    }

    diff: AddressDiff = address_diff.compute(reference, actual, ignored)
    return diff
Ejemplo n.º 3
0
def test_add():
    file_path, keeper = create_keeper('keeper_addresses_to_be_ignored.csv')
    keeper.add_ignored(
        Address('Ignored Street', '1'),
        IgnoredAddressInformation(False, "building does not exist",
                                  ignore_date))

    ignored = CsvAddressListImport.read_to_be_ignored(file_path)
    assert len(ignored) == 1
    assert ignored[Address('Ignored Street',
                           '1')] == IgnoredAddressInformation(
                               False, "building does not exist", ignore_date)
Ejemplo n.º 4
0
def test_remove():
    file_path, keeper = create_keeper(
        'keeper_addresses_to_be_ignored_not_anymore.csv')
    address = Address('Ignored Street', '1')
    keeper.add_ignored(
        address,
        IgnoredAddressInformation(False, "building does not exist",
                                  ignore_date))
    keeper.remove_ignored(address)

    ignored = CsvAddressListImport.read_to_be_ignored(file_path)
    assert len(ignored) == 0
    def read_to_be_ignored(
            file_path_or_buffer) -> Dict[Address, IgnoredAddressInformation]:
        csv_file = pandas.read_csv(file_path_or_buffer)
        addresses = {}
        for index, row in csv_file.iterrows():
            ignore_date_string: str = row.get('ignore_date')
            try:
                ignore_date = IgnoredAddressInformation.parse_ignore_date(
                    ignore_date_string)
            except (ValueError, TypeError):
                print(
                    f'To be ignored address has invalid ignore date "{ignore_date_string}", so we assume 2020-05-01'
                )
                ignore_date = IgnoredAddressInformation.parse_ignore_date(
                    '2020-05-01')
            try:
                addresses[CsvAddressListImport.get_address(row)] = \
                    IgnoredAddressInformation(bool(row.get('exists')), row.get('reason'), ignore_date)
            except InvalidHousenumber as i:
                print(f'Invalid housenumber "{i.input_string}": {i.message}"')
                # skip this address, continue with others

        return addresses
Ejemplo n.º 6
0
from missing_addresses import Address, MissingAddressInformation, SurplusInformation, Coordinate, IgnoredAddressInformation, MatchInformation, \
    OsmPrimitive, AddressDiffComputation, AddressDiff

ignore_date = IgnoredAddressInformation.parse_ignore_date('2020-05-13')


def create_diff():
    address_diff = AddressDiffComputation()
    reference = {
        Address('Identical Street', '1'): Coordinate(1.1, 1.2),
        Address('Identical Street', '7'): Coordinate(7.1, 7.2),
        Address('Identical Street', '13'): Coordinate(13.1, 13.2),
        Address('Missing Street', '2'): Coordinate(2.1, 2.2),
        Address('Missing Street', '2'):
        Coordinate(2.1, 2.2),  # duplicate in reference set
        Address('Missing Street', '3'): Coordinate(3.1, 3.2)
    }
    actual = [(Address('Identical Street', '1'), OsmPrimitive('way', 1)),
              (Address('Identical Street', '7'), OsmPrimitive('way', 7)),
              (Address('Identical Street', '13'), OsmPrimitive('way', 13)),
              (Address('Surplus Street', '4'), OsmPrimitive('node', 31)),
              (Address('Surplus Street', '3'), OsmPrimitive('way', 32))
              ]  # way and node with same address, to be reported twice
    ignored = {
        Address('Missing Street', '3'):
        IgnoredAddressInformation(False, 'building does not exist',
                                  ignore_date),
        Address('Surplus Street', '4'):
        IgnoredAddressInformation(True, 'building does exist', ignore_date)
    }
 def save_ignored(self, addresses: Dict[Address, IgnoredAddressInformation]):
     with open(self.file_path, 'w', newline='', encoding='UTF-8') as csvfile:
         w = writer(csvfile)
         w.writerow(('addr:street', 'addr:housenumber', 'exists', 'reason', 'ignore_date'))
         for (a, i) in addresses.items():
             w.writerow([a.street, str(a.housenumber), i.exists, i.reason, i.ignore_date.strftime(IgnoredAddressInformation.get_date_format())])