Exemplo n.º 1
0
def main(event, context):
    logger.info('got event{}'.format(event))
    uuid = event['campaign_uuid']
    type_name = event['type']
    type_id = type_name.replace(' ', '_')

    campaign = fetch_campaign(
        campaign_path=campaign_path(uuid))
    for type_key in campaign['types']:
        if campaign['types'][type_key]['type'] == type_name:
            typee = campaign['types'][type_key]

    download_overpass_file(uuid, type_id)
    xml_file = open('/tmp/{type_id}.xml'.format(type_id=type_id), 'r')

    parser = CountFeatureParser(typee['feature'])

    try:
        xml.sax.parse(xml_file, parser)
    except xml.sax.SAXParseException:
        print('FAIL')

    output = {
        'type_id': type_id,
        'type_name': type_name,
        'piechart': to_piechart(parser.count)
    }

    save_data(uuid, type_id, output)
Exemplo n.º 2
0
def main(event, context):
    logger.info('got event{}'.format(event))
    uuid = event['campaign_uuid']
    type_name = event['type']
    type_id = type_name.replace(' ', '_')

    campaign = fetch_campaign(campaign_path(uuid))
    for type_key in campaign['types']:
        if campaign['types'][type_key]['type'] == type_name:
            typee = campaign['types'][type_key]

    logger.info(typee['tags'])
    required_tags = fix_tags(typee['tags'])
    logger.info(required_tags)

    render_data_path = build_render_data_path(
        campaign_path=campaign_path(uuid), type_id=type_id)

    download_overpass_file(uuid, type_id)

    if 'element_type' in typee:
        element_type = typee['element_type']
    else:
        element_type = None

    xml_file = open('/tmp/{type_id}.xml'.format(type_id=type_id), 'r')
    parser = FeatureCompletenessParser(required_tags, render_data_path,
                                       element_type)

    try:
        xml.sax.parse(xml_file, parser)
    except xml.sax.SAXParseException:
        print('FAIL')
        parser.endDocument()

    processed_data = {
        'type_id':
        type_id,
        'type_name':
        type_name,
        'percentage':
        compute_completeness_pct(features_collected=parser.features_collected,
                                 features_completed=parser.features_completed),
        'features_collected':
        parser.features_collected,
        'features_completed':
        parser.features_completed,
        'checked_attributes':
        list(required_tags.keys()),
        'geojson_files_count':
        parser.geojson_file_manager.count,
        'errors_files_count':
        parser.errors_file_manager.count,
        'error_ids':
        parser.error_ids
    }
    save_data(uuid, type_id, processed_data)
    invoke_download_errors(uuid, type_name)
    invoke_render_feature(uuid, type_name)
    invoke_process_make_vector_tiles(uuid, type_name)
Exemplo n.º 3
0
def lambda_handler(event, context):
    uuid = event['campaign_uuid']
    type_name = event['type']
    type_id = type_name.replace(' ', '_')

    campaign = fetch_campaign(campaign_path(uuid))
    for type_key in campaign['types']:
        if campaign['types'][type_key]['type'] == type_name:
            typee = campaign['types'][type_key]

    download_overpass_file(uuid, type_id)

    xml_file = open('/tmp/{type_id}.xml'.format(type_id=type_id), 'r')

    tag_name = typee['feature'].split('=')[0]
    start_date = calendar.timegm(
        datetime.datetime.strptime(campaign['start_date'],
                                   '%Y-%m-%d').timetuple()) * 1000
    end_date = calendar.timegm(
        datetime.datetime.strptime(campaign['end_date'],
                                   '%Y-%m-%d').timetuple()) * 1000

    sorted_user_list = osm_object_contributions(xml_file, tag_name, start_date,
                                                end_date)

    save_data(uuid, type_id, sorted_user_list)