Ejemplo n.º 1
0
def add_housenumber(parent, id, metadata, postcode):
    number, *ordinal = id.split(' ')
    ordinal = ordinal[0] if ordinal else ''
    center = [metadata['lon'], metadata['lat']]
    ign = metadata.get('id')
    data = dict(number=number, ordinal=ordinal, version=1, parent=parent.pk,
                ign=ign)
    if postcode:
        data['postcodes'] = [postcode]

    validator = HouseNumber.validator(**data)

    if not validator.errors:
        housenumber = validator.save()
        validator = Position.validator(center=center, version=1,
                                       kind=Position.ENTRANCE,
                                       housenumber=housenumber.pk)
        if not validator.errors:
            validator.save()
            report('Position', validator.instance, report.NOTICE)
        else:
            report('Position error', validator.errors, report.ERROR)
        report('Housenumber', housenumber, report.NOTICE)
    else:
        report('Housenumber error', validator.errors, report.ERROR)
Ejemplo n.º 2
0
def add_housenumber(parent, id, metadata, postcode):
    number, *ordinal = id.split(' ')
    ordinal = ordinal[0] if ordinal else ''
    center = [metadata['lon'], metadata['lat']]
    ign = metadata.get('id')
    data = dict(number=number,
                ordinal=ordinal,
                version=1,
                parent=parent.id,
                ign=ign)
    if postcode:
        data['ancestors'] = [postcode]

    validator = HouseNumber.validator(**data)

    if not validator.errors:
        housenumber = validator.save()
        validator = Position.validator(center=center,
                                       version=1,
                                       kind=Position.ENTRANCE,
                                       housenumber=housenumber.id)
        if not validator.errors:
            validator.save()
            report('Position', validator.instance, report.NOTICE)
        else:
            report('Position error', validator.errors, report.ERROR)
        report('Housenumber', housenumber, report.NOTICE)
    else:
        report('Housenumber error', validator.errors, report.ERROR)
Ejemplo n.º 3
0
Archivo: init.py Proyecto: odorie/ban
def process_position(row):
    kind = row.get('kind')
    if not hasattr(Position, kind.upper()):
        kind = Position.UNKNOWN
    positioning = row.get('positionning')  # two "n" in the data.
    if not positioning or not hasattr(Position, positioning.upper()):
        positioning = Position.OTHER
    source = row.get('source')
    cia = row.get('housenumber:cia').upper()
    center = row.get('geometry')
    housenumber = HouseNumber.first(HouseNumber.cia == cia)
    if not housenumber:
        reporter.error('Position housenumber does not exist', cia)
        return
    instance = Position.first(Position.housenumber == housenumber,
                              Position.kind == kind, Position.source == source)
    version = instance.version + 1 if instance else 1
    data = dict(kind=kind, source=source, housenumber=housenumber,
                center=center, positioning=positioning, version=version)
    if 'ref:ign' in row:
        data['ign'] = row.get('ref:ign')
    validator = Position.validator(instance=instance, **data)
    if validator.errors:
        reporter.error('Position error', validator.errors)
    else:
        try:
            position = validator.save()
        except peewee.IntegrityError:
            reporter.error('Integrity error', row)
        else:
            msg = 'Position updated' if instance else 'Position created'
            reporter.notice(msg, position.id)
Ejemplo n.º 4
0
def add_housenumber(parent, id, metadata, postcode):
    number, *ordinal = id.split(' ')
    ordinal = ordinal[0] if ordinal else ''
    center = [metadata['lon'], metadata['lat']]
    ign = metadata.get('id')
    data = dict(number=number, ordinal=ordinal, version=1, parent=parent.pk,
                ign=ign)
    if postcode:
        data['postcode'] = postcode

    validator = HouseNumber.validator(**data)

    if not validator.errors:
        housenumber = validator.save()
        validator = Position.validator(center=center, version=1,
                                       kind=Position.ENTRANCE,
                                       positioning=Position.OTHER,
                                       housenumber=housenumber.pk)
        if not validator.errors:
            validator.save()
            reporter.notice('Position', validator.instance)
        else:
            reporter.error('Position error', validator.errors)
        reporter.notice('Housenumber created', housenumber)
    else:
        reporter.error('Housenumber error', validator.errors)
Ejemplo n.º 5
0
def process_position(row):
    positioning = row.get('positioning')
    if not positioning or not hasattr(Position, positioning.upper()):
        positioning = Position.OTHER
    source = row.get('source')
    cia = row.get('housenumber:cia')
    housenumber_ign = row.get('housenumber:ign')
    housenumber = None
    if cia:
        cia = cia.upper()
        housenumber = HouseNumber.first(HouseNumber.cia == cia)
    elif housenumber_ign:
        housenumber = HouseNumber.first(HouseNumber.ign == housenumber_ign)
    if not housenumber:
        reporter.error('Unable to find parent housenumber', row)
        return
    instance = None
    if 'ign' in row:
        # The only situation where we want to avoid creating new position is
        # when we have the ign identifier.
        instance = Position.first(Position.ign == row['ign'])
    version = instance.version + 1 if instance else 1
    data = dict(source=source,
                housenumber=housenumber,
                positioning=positioning,
                version=version)
    kind = row.get('kind', '')
    data['attributes'] = row.get('attributes', {})
    if hasattr(Position, kind.upper()):
        data['kind'] = kind
    elif not instance:
        # We are creating a new position (not updating), kind is mandatory.
        kind = Position.UNKNOWN
    if kind:
        data['kind'] = kind
    populate(['ign', 'name', ('geometry', 'center')], row, data)
    validator = Position.validator(instance=instance,
                                   update=bool(instance),
                                   **data)
    if validator.errors:
        reporter.error('Position error', validator.errors)
    else:
        try:
            position = validator.save()
        except peewee.IntegrityError as e:
            reporter.error('Integrity error', (str(e), data))
        else:
            msg = 'Position updated' if instance else 'Position created'
            reporter.notice(msg, position.id)
Ejemplo n.º 6
0
def process_position(housenumber, center, kind):
    kind = KIND_MAPPING.get(kind, kind)
    instance = Position.where(Position.housenumber == housenumber,
                              Position.kind == kind).first()
    version = instance.version + 1 if instance else 1
    validator = Position.validator(housenumber=housenumber, center=center,
                                   source='BAL',  # Use siren from filename?
                                   positioning=Position.IMAGERY,
                                   kind=kind, instance=instance,
                                   version=version)
    if validator.errors:
        reporter.error('Position error', validator.errors)
    else:
        position = validator.save()
        msg = 'Position updated' if instance else 'Position created'
        reporter.notice(msg, position.id)
Ejemplo n.º 7
0
def process_position(housenumber, center, localisation_type, attributes):
    if localisation_type == 'Interpolée':
        positioning = Position.INTERPOLATION
    elif localisation_type == 'Projetée du centre parcelle':
        positioning = Position.PROJECTION
    else:
        positioning = Position.OTHER
    validator = Position.validator(housenumber=housenumber, center=center,
                                   attributes=attributes, source='IGN',
                                   positioning=positioning,
                                   kind=Position.ENTRANCE)
    if validator.errors:
        reporter.error('Position error', validator.errors)
    else:
        validator.save()
        reporter.notice('Position created', center)
Ejemplo n.º 8
0
def process_position(housenumber, center, kind):
    kind = KIND_MAPPING.get(kind, kind)
    instance = Position.where(Position.housenumber == housenumber,
                              Position.kind == kind).first()
    version = instance.version + 1 if instance else 1
    validator = Position.validator(housenumber=housenumber, center=center,
                                   source='BAL',  # Use siren from filename?
                                   positioning=Position.IMAGERY,
                                   kind=kind, instance=instance,
                                   version=version)
    if validator.errors:
        reporter.error('Position error', validator.errors)
    else:
        position = validator.save()
        msg = 'Position updated' if instance else 'Position created'
        reporter.notice(msg, position.id)
Ejemplo n.º 9
0
def add_housenumber(parent, id, metadata):
    number, *ordinal = id.split(' ')
    ordinal = ordinal[0] if ordinal else ''
    center = [metadata['lon'], metadata['lat']]
    data = dict(number=number, ordinal=ordinal, version=1)
    data[parent.__class__.__name__.lower()] = parent.id
    validator = HouseNumber.validator(**data)

    if not validator.errors:
        housenumber = validator.save()
        validator = Position.validator(center=center, version=1,
                                       housenumber=housenumber.id)
        if not validator.errors:
            validator.save()
        report('Housenumber', housenumber, report.NOTICE)
    else:
        report('Housenumber error', validator.errors, report.ERROR)
Ejemplo n.º 10
0
def process_position(row):
    positioning = row.get('positionning')  # two "n" in the data.
    if not positioning or not hasattr(Position, positioning.upper()):
        positioning = Position.OTHER
    source = row.get('source')
    cia = row.get('housenumber:cia')
    housenumber_ign = row.get('housenumber:ign')
    housenumber = None
    if cia:
        cia = cia.upper()
        housenumber = HouseNumber.first(HouseNumber.cia == cia)
    elif housenumber_ign:
        housenumber = HouseNumber.first(HouseNumber.ign == housenumber_ign)
    if not housenumber:
        reporter.error('Unable to find parent housenumber', row)
        return
    instance = None
    if 'ign' in row:
        # The only situation where we want to avoid creating new position is
        # when we have the ign identifier.
        instance = Position.first(Position.ign == row['ign'])
    version = instance.version + 1 if instance else 1
    data = dict(source=source, housenumber=housenumber,
                positioning=positioning, version=version)
    kind = row.get('kind', '')
    if hasattr(Position, kind.upper()):
        data['kind'] = kind
    elif not instance:
        # We are creating a new position (not updating), kind is mandatory.
        kind = Position.UNKNOWN
    if kind:
        data['kind'] = kind
    populate(['ign', 'name', ('geometry', 'center')], row, data)
    validator = Position.validator(instance=instance, update=bool(instance),
                                   **data)
    if validator.errors:
        reporter.error('Position error', validator.errors)
    else:
        try:
            position = validator.save()
        except peewee.IntegrityError as e:
            reporter.error('Integrity error', (str(e), data))
        else:
            msg = 'Position updated' if instance else 'Position created'
            reporter.notice(msg, position.id)