Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map country codes to names in generating aggregate data #2429

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions data-serving/scripts/aggregate/aggregate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import pymongo
import requests

from iso3166 import countries

_JHU_COUNTRY_MAP = {
"Czechia": "Czech Republic",
"Korea South": "South Korea",
Expand Down Expand Up @@ -168,6 +170,10 @@ def get_country_codes():
return countrycodes_dict


def country_name(c):
return countries.get(c).name


def generate_country_json(cases, s3_endpoint, bucket, date, line_list_url, map_url):
"""
Generate json of case counts by country and upload to S3.
Expand Down Expand Up @@ -196,13 +202,10 @@ def generate_country_json(cases, s3_endpoint, bucket, date, line_list_url, map_u
jhu_counts = get_jhu_counts()
country_codes = get_country_codes()

merged_countries = []
for record in records:
country = record["_id"]
merged_countries.append(country)
merged_countries = [country_name(record["_id"]) for record in records]

for record in records:
country = record["_id"]
country = country_name(record["_id"])
if country is None:
continue
try:
Expand Down Expand Up @@ -318,14 +321,14 @@ def generate_region_json(cases, s3_endpoint, bucket, date):
id = record["admin1"]
search_term = "admin1"
else:
id = record["country"]
id = country_name(record["country"])
if id is None:
continue
search_term = "country"
new_record = {
"_id": id,
"casecount": record["casecount"],
"country": record["country"],
"country": id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a country_code field so that we don't have to lookups elsewhere in case we need it?

"admin1": record["admin1"],
"admin2": record["admin2"],
"admin3": record["admin3"],
Expand Down
14 changes: 13 additions & 1 deletion data-serving/scripts/aggregate/aggregate/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions data-serving/scripts/aggregate/aggregate/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pymongo = "3.11.2"
dnspython = "2.1.0"
pandas = "^1.3.4"
requests = "^2.26.0"
iso3166 = "^2.0.2"

[tool.poetry.dev-dependencies]

Expand Down