def generate_dataset_and_showcase(countryName, countryISO2): title = '%s - Demographic, Health, Education and Transport indicators' % countryName logger.info('Creating dataset: %s' % title) name = 'unhabitat-%s-indicators' % countryISO2 slugified_name = slugify(name).lower() dataset = Dataset({ 'name': slugified_name, 'title': title, }) # dataset.set_dataset_date(date, dataset_end_date=) dataset.set_dataset_year_range(1950, 2050) dataset.set_expected_update_frequency('Every year') dataset.set_subnational(1) dataset.add_country_location(getCountryISO3Code(countryISO2)) dataset.add_tags(['EDUCATION', 'POPULATION', 'HEALTH', 'TRANSPORT', 'HXL']) if os.path.isfile('data/indicator_data_' + countryISO2 + '.csv'): resource = Resource() resource['name'] = 'Indicators_data_%s' % countryISO2 resource[ 'description'] = '%s - Demographic, Health, Education and Transport indicators' % countryName resource['format'] = 'csv' resource.set_file_to_upload('data/indicator_data_' + countryISO2 + '.csv') resource.check_required_fields(['group', 'package_id']) dataset.add_update_resource(resource) showcase_name = slugify('unhabitat-%s' % countryName + ' indacators-data').lower() showcase = Showcase({ 'name': showcase_name, 'title': 'Explore %s' % countryName + ' indicators', 'notes': 'Explore %s' % countryName + ' indicators', 'url': 'http://urbandata.unhabitat.org/data-country/?countries=%s' % countryISO2 + '&indicators=total_length_road,rural_population,urban_population_countries,urban_slum_population_countries,population,income_gini_coefficient_countries', 'image_url': 'https://centre.humdata.org/wp-content/uploads/2018/09/unhabitat-showcase.png' }) showcase.add_tags(['EDUCATION', 'POPULATION', 'HEALTH', 'TRANSPORT']) return dataset, showcase
def generate_dataset(configuration, countryName): #showedName = countryName if (countryName == "Ivory Coast"): showedName = "Cote d'Ivoire" name = countryName + '-healthsites' title = countryName + '-healthsites' slugified_name = slugify(name).lower() # dataset = Dataset(configuration, { # }) dataset = Dataset({ 'name': slugified_name, 'title': title, }) # dataset['name'] = slugified_name # dataset['title'] = title #generating the datasets getCountryHealthSites(configuration, countryName) # geojson resource if (os.path.isfile(configuration.read()['data_folder'] + countryName + '.geojson')): rName = countryName + '-healthsites-geojson' geojsonResource = Resource() geojsonResource['name'] = rName geojsonResource['format'] = 'geojson' geojsonResource['url'] = configuration.read()['base_url'] geojsonResource['description'] = countryName + ' healthsites geojson' geojsonResource.set_file_to_upload( configuration.read()['data_folder'] + countryName + '.geojson') geojsonResource.check_required_fields(['group', 'package_id']) dataset.add_update_resource(geojsonResource) #csv resource if (os.path.isfile(configuration.read()['data_folder'] + countryName + '.csv')): resource_csv = Resource() resource_csv['name'] = countryName + '-healthsites-csv' resource_csv['description'] = countryName + ' healthsites csv' resource_csv['format'] = 'csv' resource_csv.set_file_to_upload(configuration.read()['data_folder'] + countryName + '.csv') resource_csv.check_required_fields(['group', 'package_id']) dataset.add_update_resource(resource_csv) # shp resource if (os.path.isfile(configuration.read()['data_folder'] + countryName + "-shapefiles.zip")): resource_shp = Resource() resource_shp['name'] = countryName + '-healthsites-shp' resource_shp['format'] = 'zipped shapefile' resource_shp['description'] = countryName + ' healthsites shapefiles' resource_shp.set_file_to_upload(configuration.read()['data_folder'] + countryName + "-shapefiles.zip") resource_shp.check_required_fields(['group', 'package_id']) dataset.add_update_resource(resource_shp) return dataset
def test_check_required_fields(self, configuration): resource_data = copy.deepcopy(TestResource.resource_data) resource = Resource(resource_data) resource.check_url_filetoupload() resource.check_required_fields()
def test_check_required_fields(self, configuration): resource_data = copy.deepcopy(TestResource.resource_data) resource = Resource(resource_data) resource.check_url_filetoupload() resource.check_required_fields()