From 047e1e7f43dbfd90a8f6a9e1d7309243d8eacb67 Mon Sep 17 00:00:00 2001 From: Briar Date: Tue, 23 Jan 2024 15:00:04 -0500 Subject: [PATCH] Redo org table reference periods --- CHANGELOG.md | 7 +++++ requirements.txt | 8 ++--- .../database/operational_presence.py | 29 +++++-------------- src/hapi/pipelines/database/org.py | 2 +- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb57c3a7..3025a8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.6.8] - 2024-01-23 + +### Changed + +- Change date in org table to match v1 release date +- Correct outdated admin logic in operational presence + ## [0.6.7] - 2024-01-17 ### Added diff --git a/requirements.txt b/requirements.txt index f8d856c7..68492d7b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,13 +31,13 @@ colorama==0.4.6 # via typer coverage[toml]==7.4.0 # via pytest-cov -cryptography==41.0.7 +cryptography==42.0.0 # via pyopenssl defopt==6.4.0 # via hdx-python-api distlib==0.3.8 # via virtualenv -dnspython==2.4.2 +dnspython==2.5.0 # via email-validator docopt==0.6.2 # via @@ -119,7 +119,7 @@ markdown-it-py==3.0.0 # via rich marko==2.0.2 # via frictionless -markupsafe==2.1.3 +markupsafe==2.1.4 # via jinja2 mdurl==0.1.2 # via markdown-it-py @@ -171,7 +171,7 @@ pydantic-core==2.14.6 # via pydantic pygments==2.17.2 # via rich -pyopenssl==23.3.0 +pyopenssl==24.0.0 # via # hdx-python-api # ndg-httpsclient diff --git a/src/hapi/pipelines/database/operational_presence.py b/src/hapi/pipelines/database/operational_presence.py index 06fc758f..d88d941e 100644 --- a/src/hapi/pipelines/database/operational_presence.py +++ b/src/hapi/pipelines/database/operational_presence.py @@ -4,6 +4,7 @@ from hapi_schema.db_operational_presence import DBOperationalPresence from hdx.location.names import clean_name +from hdx.utilities.dateparse import parse_date from sqlalchemy.orm import Session from . import admins @@ -57,6 +58,9 @@ def populate(self): for admin_code, org_names in values[org_name_index].items(): for i, org_name in enumerate(org_names): + admin2_code = admins.get_admin2_code_based_on_level( + admin_code=admin_code, admin_level=admin_level + ) # TODO: find the country code for get_org_info parameter "location" org_info = self._org.get_org_info( org_name, location="Country code" @@ -95,37 +99,20 @@ def populate(self): ) not in self._org.data ): + # Date is release date of HAPI v1 self._org.populate_single( acronym=org_acronym, org_name=org_name, org_type=org_type_code, - reference_period_start=reference_period_start, - reference_period_end=reference_period_end, + reference_period_start=parse_date( + "2023-11-21" + ), ) sector = values[sector_index][admin_code][i] sector_code = self._sector.get_sector_code(sector) if not sector_code: logger.error(f"Sector {sector} not in table") - if admin_level == "national": - admin1_code = ( - admins.get_admin1_to_location_connector_code( - admin_code - ) - ) - admin2_code = ( - admins.get_admin2_to_admin1_connector_code( - admin1_code - ) - ) - if admin_level == "adminone": - admin2_code = ( - admins.get_admin2_to_admin1_connector_code( - admin1_code=admin_code - ) - ) - elif admin_level == "admintwo": - admin2_code = admin_code resource_ref = self._metadata.resource_data[ resource_id ] diff --git a/src/hapi/pipelines/database/org.py b/src/hapi/pipelines/database/org.py index efd2f18e..83d68588 100644 --- a/src/hapi/pipelines/database/org.py +++ b/src/hapi/pipelines/database/org.py @@ -45,7 +45,7 @@ def populate_single( org_name, org_type, reference_period_start, - reference_period_end, + reference_period_end=None, ): logger.info(f"Adding org {org_name}") org_row = DBOrg(