Skip to content

Commit

Permalink
Generate missing country datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-mills committed Dec 18, 2024
1 parent 67446f4 commit 638768e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/hdx/scraper/hno/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,43 @@ def main(
if not generate_country_resources:
continue
dataset = dataset_generator.get_country_dataset(countryiso3)
if not dataset:
logger.error(f"No dataset found for {countryiso3}!")
continue
highest_admin = plan.get_highest_admin(countryiso3)
resource = dataset_generator.add_country_resource(
dataset, countryiso3, rows, folder, year, highest_admin
)
if not resource:
continue
resource.set_date_data_updated(published)
dataset.preview_resource()
dataset.update_in_hdx(
operation="patch",
match_resource_order=True,
remove_additional_resources=False,
hxl_update=False,
updated_by_script=updated_by_script,
batch=batch,
)
if not dataset:
logger.warning(
f"No dataset found for {countryiso3}, generating!"
)
dataset = dataset_generator.generate_country_dataset(
countryiso3, folder, rows, year, highest_admin
)
dataset.update_from_yaml(
script_dir_plus_file(
join("config", "hdx_dataset_static.yaml"), main
)
)
resource = dataset.get_resource(0)
dataset.create_in_hdx(
match_resource_order=True,
remove_additional_resources=False,
hxl_update=False,
updated_by_script=updated_by_script,
batch=batch,
)
else:
resource = dataset_generator.add_country_resource(
dataset, countryiso3, rows, folder, year, highest_admin
)
if not resource:
continue
resource.set_date_data_updated(published)
dataset.preview_resource()
dataset.update_in_hdx(
operation="patch",
match_resource_order=True,
remove_additional_resources=False,
hxl_update=False,
updated_by_script=updated_by_script,
batch=batch,
)
if highest_admin == 0:
filename = "hdx_country_resource_view_static_adm0.yaml"
elif highest_admin == 1:
Expand Down Expand Up @@ -165,7 +183,7 @@ def main(
join("config", "hdx_dataset_static.yaml"), main
)
)
if highest_admin == 0:
if global_highest_admin == 0:
filename = "hdx_resource_view_static_adm0.yaml"
else:
filename = "hdx_resource_view_static.yaml"
Expand Down
27 changes: 27 additions & 0 deletions src/hdx/scraper/hno/dataset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,30 @@ def generate_global_dataset(
)
dataset.add_country_locations(countries_with_data)
return dataset

def generate_country_dataset(
self,
countryiso3: str,
folder: str,
rows: Dict,
year: int,
highest_admin: Optional[int],
) -> Optional[Dataset]:
if not rows or highest_admin is None:
return None
countryname = Country.get_country_name_from_iso3(countryiso3)
title = f"{countryname}: Humanitarian Needs"
filename = self.get_automated_resource_filename(countryiso3, year)

dataset = self.generate_dataset(
title,
title,
filename,
filename,
self._country_hxltags,
rows,
folder,
highest_admin,
)
dataset.add_country_location(countryiso3)
return dataset

0 comments on commit 638768e

Please sign in to comment.