Skip to content

Conversation

mcarans
Copy link
Contributor

@mcarans mcarans commented Sep 18, 2023

get_hapi_results now returns a dictionary that looks like what is below. The results dictionary for the hapi-pipelines would have keys adminone and admintwo (the names passed to _create_configurable_scrapers in pipelines.py).

{
            "hdx_id": "6a41be98-75b9-4365-9ea3-e33d0dd2668b",
            "hdx_stub": "global-school-closures-covid19",
            "provider_code": "18f2d467-dcf8-4b7e-bffa-b3c338ba3a7c",
            "provider_name": "unesco",
            "reference_period": {
                "enddate": datetime(
                    2022, 4, 30, 23, 59, 59, tzinfo=timezone.utc
                ),
                "enddate_str": "2022-04-30T23:59:59+00:00",
                "ongoing": False,
                "startdate": datetime(2020, 2, 16, 0, 0, tzinfo=timezone.utc),
                "startdate_str": "2020-02-16T00:00:00+00:00",
            },
            "resource": {
                "download_url": "https://data.humdata.org/dataset/6a41be98-75b9-4365-9ea3-e33d0dd2668b/resource/3b5baa74-c928-4cbc-adba-bf543c5d3050/download/covid_impact_education.csv",
                "filename": "School Closures",
                "format": "csv",
                "hdx_id": "3b5baa74-c928-4cbc-adba-bf543c5d3050",
                "update_date": datetime(
                    2022, 4, 4, 9, 56, 5, tzinfo=timezone.utc
                ),
            },
            "results": {
                "national": {
                    "headers": (("School Closure",), ("#impact+type",)),
                    "values": ({"AFG": "Closed due to COVID-19"},),
                },
                "regional": {
                    "headers": (
                        ("No. closed countries",),
                        ("#status+country+closed",),
                    ),
                    "values": ({"ROAP": 1},),
                },
            },
            "title": "Global School Closures COVID-19",
        }

@mcarans mcarans requested a review from turnerm September 18, 2023 01:38
@github-actions
Copy link

github-actions bot commented Sep 18, 2023

Test Results

37 tests  ±0   37 ✔️ ±0   3m 0s ⏱️ -3s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ±0 

Results for commit 894122a. ± Comparison against base commit 1a5698e.

♻️ This comment has been updated with latest results.

@turnerm
Copy link
Member

turnerm commented Sep 19, 2023

@mcarans Thanks so much for implementing this. However I'm not quite getting exactly the output that you've quoted ablove. For example, in this branch when I print the output of get_hapi_results, I obtain (truncated):

 '8520e386-9263-48c9-b1bf-b2349e019fbb': {'hdx_id': '8520e386-9263-48c9-b1bf-b2349e019fbb',
                                          'hdx_stub': 'cod-ps-col',
                                          'provider_code': '95aa8d05-b110-4607-9330-f2a779885493',
                                          'provider_name': 'unfpa',
                                          'reference_period': {'enddate': datetime.datetime(2023, 9, 19, 23, 59, 59, 706701, tzinfo=datetime.timezone.utc),
                                                               'enddate_str': '2023-09-19T23:59:59+00:00',
                                                               'ongoing': True,
                                                               'startdate': datetime.datetime(2023, 8, 8, 0, 0, tzinfo=datetime.timezone.utc),
                                                               'startdate_str': '2023-08-08T00:00:00+00:00'},
                                          'resource': {'download_url': 'https://data.humdata.org/dataset/8520e386-9263-48c9-b1bf-b2349e019fbb/resource/e8f7fb08-af9c-4bdf-8a49-a54c56a4a1b0/download/col_admpop_adm1_2023.csv',
                                                       'filename': 'col_admpop_adm1_2023.csv',
                                                       'format': 'CSV',
                                                       'hdx_id': 'e8f7fb08-af9c-4bdf-8a49-a54c56a4a1b0',
                                                       'update_date': datetime.datetime(2023, 8, 8, 19, 57, 17, tzinfo=datetime.timezone.utc)},
                                          'results': {'adminone': {'headers': (['T_TL',
                                                                                'M_TL',
                                                                                'F_TL',
                                                                                'F_00_04',
                                                                                'F_100Plus',
                                                                                'T_00_04',
                                                                                'T_100Plus'],
                                                                               ['#population+total',
                                                                                '#population+f+total',
                                                                                '#population+m+total',
                                                                                '#population+f+age_0_4',
                                                                                '#population+f+age_100_plus',
                                                                                '#population+age_0_4+total',
                                                                                '#population+age_100_plus+total']),
                                                                   'values': ({'CO05': '6994792',
                                                                               'CO08': '2835509',
                                                                               'CO11': '7968095',
                                                                               'CO13': '2258929',
                                                                               'CO15': '1267378',
                                                                               'CO17': '1046418',
                                                                               'CO18': '423857',

(and there is also an "admintwo" key in the results)

Namely, the output of get_hapi_results is a dictionary with the dataset ID as keys, and while there are keys for both admin levels as expected, the resource information is only for admin 1.

@mcarans mcarans changed the title get_hapi_results now returns a dictionary not a list get_hapi_metadata, get_hapi_results now return dictionaries Sep 21, 2023
@mcarans
Copy link
Contributor Author

mcarans commented Sep 21, 2023

@turnerm get_hapi_metadata returns something like this:

{"3d9b037f-5112-4afd-92a7-190a9082bd80": {"hdx_id": "3d9b037f-5112-4afd-92a7-190a9082bd80",
                                          "hdx_stub": "cod-ps-eth",
                                          "provider_code": "522a7e16-3ba7-4649-b327-df81fd6dd689",
                                          "provider_name": "ocha-ethiopia",
                                          "reference_period": {"enddate": datetime.datetime(2023, 9, 21, 23, 59, 59, 385291, tzinfo=datetime.timezone.utc),
                                                               "enddate_str": "2023-09-21T23:59:59+00:00",
                                                               "ongoing": True,
                                                               "startdate": datetime.datetime(2022, 1, 5, 0, 0, tzinfo=datetime.timezone.utc),
                                                               "startdate_str": "2022-01-05T00:00:00+00:00"},
                                          "resources": {"bfb57304-3e22-498f-8a82-a345a8976852": {"download_url": "https://data.humdata.org/dataset/3d9b037f-5112-4afd-92a7-190a9082bd80/resource/bfb57304-3e22-498f-8a82-a345a8976852/download/eth_admpop_adm2_2022_v2.csv",
                                                                                                 "filename": "eth_admpop_adm2_2022_v2.csv",
                                                                                                 "format": "CSV",
                                                                                                 "hdx_id": "bfb57304-3e22-498f-8a82-a345a8976852",
                                                                                                 "update_date": datetime.datetime(2022, 8, 4, 18, 15, 44, tzinfo=datetime.timezone.utc)}},
                                          "title": "Ethiopia - Subnational "
                                                   "Population Statistics"},...}

get_hapi_results returns something like:

{"3d9b037f-5112-4afd-92a7-190a9082bd80": {"hdx_id": "3d9b037f-5112-4afd-92a7-190a9082bd80",
                                          "hdx_stub": "cod-ps-eth",
                                          "provider_code": "522a7e16-3ba7-4649-b327-df81fd6dd689",
                                          "provider_name": "ocha-ethiopia",
                                          "reference_period": {"enddate": datetime.datetime(2023, 9, 21, 23, 59, 59, 385291, tzinfo=datetime.timezone.utc),
                                                               "enddate_str": "2023-09-21T23:59:59+00:00",
                                                               "ongoing": True,
                                                               "startdate": datetime.datetime(2022, 1, 5, 0, 0, tzinfo=datetime.timezone.utc),
                                                               "startdate_str": "2022-01-05T00:00:00+00:00"},
                                          "results": {"admintwo": {"hapi_resource_metadata": {"download_url": "https://data.humdata.org/dataset/3d9b037f-5112-4afd-92a7-190a9082bd80/resource/bfb57304-3e22-498f-8a82-a345a8976852/download/eth_admpop_adm2_2022_v2.csv",
                                                                                              "filename": "eth_admpop_adm2_2022_v2.csv",
                                                                                              "format": "CSV",
                                                                                              "hdx_id": "bfb57304-3e22-498f-8a82-a345a8976852",
                                                                                              "update_date": datetime.datetime(2022, 8, 4, 18, 15, 44, tzinfo=datetime.timezone.utc)},
                                                                   "headers": (["T_TL",
                                                                                "M_TL",
                                                                                "F_TL"],
                                                                               ["#population+total",
                                                                                "#population+f+total",
                                                                                "#population+m+total"]),
                                                                   "values": ({"ET0101": "902719",
                                                                               "ET0102": "1475184",
                                                                               ...},
                                                                              {"ET0101": "446866",
                                                                               "ET0102": "724860",
                                                                               ...},
                                                                              {"ET0101": "455853",
                                                                               "ET0102": "750324",
                                                                               ...})}},
                                          "title": "Ethiopia - Subnational "
                                                   "Population Statistics"},
 "8520e386-9263-48c9-b1bf-b2349e019fbb": {"hdx_id": "8520e386-9263-48c9-b1bf-b2349e019fbb",
                                          "hdx_stub": "cod-ps-col",
                                          "provider_code": "95aa8d05-b110-4607-9330-f2a779885493",
                                          "provider_name": "unfpa",
                                          "reference_period": {"enddate": datetime.datetime(2023, 9, 21, 23, 59, 59, 385291, tzinfo=datetime.timezone.utc),
                                                               "enddate_str": "2023-09-21T23:59:59+00:00",
                                                               "ongoing": True,
                                                               "startdate": datetime.datetime(2023, 8, 8, 0, 0, tzinfo=datetime.timezone.utc),
                                                               "startdate_str": "2023-08-08T00:00:00+00:00"},
                                          "results": {"adminone": {"hapi_resource_metadata": {"download_url": "https://data.humdata.org/dataset/8520e386-9263-48c9-b1bf-b2349e019fbb/resource/e8f7fb08-af9c-4bdf-8a49-a54c56a4a1b0/download/col_admpop_adm1_2023.csv",
                                                                                              "filename": "col_admpop_adm1_2023.csv",
                                                                                              "format": "CSV",
                                                                                              "hdx_id": "e8f7fb08-af9c-4bdf-8a49-a54c56a4a1b0",
                                                                                              "update_date": datetime.datetime(2023, 8, 8, 19, 57, 17, tzinfo=datetime.timezone.utc)},
                                                                   "headers": (["T_TL",
                                                                                "M_TL",
                                                                                "F_TL",
                                                                                "F_00_04",
                                                                                "F_100Plus",
                                                                                "T_00_04",
                                                                                "T_100Plus"],
                                                                               ["#population+total",
                                                                                "#population+f+total",
                                                                                "#population+m+total",
                                                                                "#population+f+age_0_4",
                                                                                "#population+f+age_100_plus",
                                                                                "#population+age_0_4+total",
                                                                                "#population+age_100_plus+total"]),
                                                                   "values": ({"CO05": "6994792",
                                                                               "CO08": "2835509",
                                                                               ...},
                                                                              {"CO05": "3382645",
                                                                               "CO08": "1382767",
                                                                               ...},
                                                                              {"CO05": "3612147",
                                                                               "CO08": "1452742",
                                                                               ...},...)},
                                                      "admintwo": {"hapi_resource_metadata": {"download_url": "https://data.humdata.org/dataset/8520e386-9263-48c9-b1bf-b2349e019fbb/resource/76e12f52-af0d-45b2-8024-e6b0e63913c4/download/col_admpop_adm2_2023.csv",
                                                                                              "filename": "col_admpop_adm2_2023.csv",
                                                                                              "format": "CSV",
                                                                                              "hdx_id": "76e12f52-af0d-45b2-8024-e6b0e63913c4",
                                                                                              "update_date": datetime.datetime(2023, 8, 8, 19, 57, 19, tzinfo=datetime.timezone.utc)},
                                                                   "headers": (["T_TL",
                                                                                "M_TL",
                                                                                "F_TL",
                                                                                "F_00_04",
                                                                                "F_100Plus",
                                                                                "T_00_04",
                                                                                "T_100Plus"],
                                                                               ["#population+total",
                                                                                "#population+f+total",
                                                                                "#population+m+total",
                                                                                "#population+f+age_0_4",
                                                                                "#population+f+age_100_plus",
                                                                                "#population+age_0_4+total",
                                                                                "#population+age_100_plus+total"]),
                                                                   "values": ({"CO05001": "2653729",
                                                                               "CO05002": "21246",
                                                                               ...},
                                                                              {"CO05001": "1400979",
                                                                               "CO05002": "10112",
                                                                               ...})}},
                                          "title": "Colombia - Subnational "
                                                   "Population Statistics"}}

Copy link
Member

@turnerm turnerm left a comment

Choose a reason for hiding this comment

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

Thanks for making this change!

@mcarans mcarans merged commit 7d4faa5 into main Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants