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)
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)
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)
def lambda_handler(event, context): logger.info('got event{}'.format(event)) uuid = event['campaign_uuid'] type_name = event['type'] 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] type_id = typee['type'].replace(' ', '_') if 'element_type' in typee: element_type = typee['element_type'] else: element_type = None elements = [] if element_type == 'Point': elements.append('node') elif element_type == 'Polygon': elements.append('way') elif element_type == 'Line': elements.append('way') else: elements.append('way') elements.append('node') query = build_query(uuid, type_id, elements) post_request(query, type_id) save_to_s3(path=build_path(uuid, type_id), type_id=type_id)
def lambda_handler(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)) geometry = fetch_campaign_geometry(campaign_path(uuid)) # type_name = fetch_type(feature, campaign['selected_functions']) print(type_name) print(type_id) for type_key in campaign['types']: if campaign['types'][type_key]['type'] == type_name: typee = campaign['types'][type_key] print(typee) data = {} # feature completeness feature_completeness_data_path = build_feature_completeness_path( campaign_path=campaign_path(uuid), type_id=type_id) data['feature_completeness'] = S3Data().fetch( feature_completeness_data_path) data['uuid'] = uuid data['type_id'] = type_id template_path = build_template_path(campaign_path=campaign_path(uuid), type_id=type_id) # count feature count_feature_data_path = build_count_feature_path( campaign_path=campaign_path(uuid), type_id=type_id) data['count_feature'] = S3Data().fetch(count_feature_data_path) data['geometry'] = geometry data['url'] = '/'.join([ "https://s3-us-west-2.amazonaws.com/{bucket}", "campaigns/{uuid}", "render/{type_id}" ]).format(bucket=os.environ['S3_BUCKET'], uuid=uuid, type_id=type_id) render_templates(template_path, data)