From 26f9a97231f327ca049f658b3ecd02d35015e6f8 Mon Sep 17 00:00:00 2001 From: Fleury Butoyi Date: Wed, 18 Dec 2024 09:38:52 +0200 Subject: [PATCH 1/2] Clean existing analytics data in order to generate freshed data --- plugins/wfp/management/commands/nigeria/Under5.py | 6 ++---- plugins/wfp/management/commands/south_sudan/Pbwg.py | 2 +- plugins/wfp/management/commands/south_sudan/Under5.py | 2 +- plugins/wfp/tasks.py | 4 +++- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/wfp/management/commands/nigeria/Under5.py b/plugins/wfp/management/commands/nigeria/Under5.py index fe4c69d9c3..9cdf79fd07 100644 --- a/plugins/wfp/management/commands/nigeria/Under5.py +++ b/plugins/wfp/management/commands/nigeria/Under5.py @@ -110,13 +110,11 @@ def group_visit_by_entity(self, entities): ) def run(self): - children_type = ["ng_-_tsfp_child_3", "ng_-_otp_child_3"] - entity_type = ETL(children_type) - type = EntityType.objects.get(code="ng_-_tsfp_child_3") + entity_type = ETL(["child_under_5_3"]) account = entity_type.account_related_to_entity_type() beneficiaries = entity_type.retrieve_entities() - logger.info(f"Instances linked to Child Under 5 program: {beneficiaries.count()} for {type.name} on {account}") + logger.info(f"Instances linked to Child Under 5 program: {beneficiaries.count()} for {account}") entities = sorted(list(beneficiaries), key=itemgetter("entity_id")) existing_beneficiaries = ETL().existing_beneficiaries() instances = self.group_visit_by_entity(entities) diff --git a/plugins/wfp/management/commands/south_sudan/Pbwg.py b/plugins/wfp/management/commands/south_sudan/Pbwg.py index a36bf3a4a2..2a6147d0c8 100644 --- a/plugins/wfp/management/commands/south_sudan/Pbwg.py +++ b/plugins/wfp/management/commands/south_sudan/Pbwg.py @@ -13,7 +13,7 @@ def run(self): entity_type = ETL(["pbwg_1"]) account = entity_type.account_related_to_entity_type() beneficiaries = entity_type.retrieve_entities() - logger.info(f"Instances linked to PBWG program: {beneficiaries.count()}") + logger.info(f"Instances linked to PBWG program: {beneficiaries.count()} for {account}") entities = sorted(list(beneficiaries), key=itemgetter("entity_id")) existing_beneficiaries = ETL().existing_beneficiaries() instances = self.group_visit_by_entity(entities) diff --git a/plugins/wfp/management/commands/south_sudan/Under5.py b/plugins/wfp/management/commands/south_sudan/Under5.py index 826e2ac19b..05dc1ce4b3 100644 --- a/plugins/wfp/management/commands/south_sudan/Under5.py +++ b/plugins/wfp/management/commands/south_sudan/Under5.py @@ -140,7 +140,7 @@ def run(self): entity_type = ETL(["child_under_5_1"]) account = entity_type.account_related_to_entity_type() beneficiaries = entity_type.retrieve_entities() - logger.info(f"Instances linked to Child Under 5 program: {beneficiaries.count()}") + logger.info(f"Instances linked to Child Under 5 program: {beneficiaries.count()} for {account}") entities = sorted(list(beneficiaries), key=itemgetter("entity_id")) existing_beneficiaries = ETL().existing_beneficiaries() instances = self.group_visit_by_entity(entities) diff --git a/plugins/wfp/tasks.py b/plugins/wfp/tasks.py index e6ca96e572..690dcd83f1 100644 --- a/plugins/wfp/tasks.py +++ b/plugins/wfp/tasks.py @@ -14,7 +14,8 @@ def etl_ng(): """Extract beneficiary data from Iaso tables and store them in the format expected by existing tableau dashboards""" logger.info("Starting ETL for Nigeria") - account = ETL(["ng_-_tsfp_child_3", "ng_-_otp_child_3"]).account_related_to_entity_type() + account = ETL(["child_under_5_3"]).account_related_to_entity_type() + Beneficiary.objects.all().filter(account=account).delete() NG_Under5().run() logger.info( @@ -27,6 +28,7 @@ def etl_ng(): def etl_ssd(): logger.info("Starting ETL for South Sudan") child_account = ETL(["child_under_5_1"]).account_related_to_entity_type() + Beneficiary.objects.all().filter(account=child_account).delete() Under5().run() logger.info( From 6d967fcbfe7360700812a9e4011da66973d30a0e Mon Sep 17 00:00:00 2001 From: Fleury Butoyi Date: Wed, 18 Dec 2024 10:16:05 +0200 Subject: [PATCH 2/2] Delete PBWG data before regenerate freshed one --- plugins/wfp/tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/wfp/tasks.py b/plugins/wfp/tasks.py index 690dcd83f1..5e55a33083 100644 --- a/plugins/wfp/tasks.py +++ b/plugins/wfp/tasks.py @@ -37,6 +37,7 @@ def etl_ssd(): ETL().journey_with_visit_and_steps_per_visit(child_account, "U5") pbwg_account = ETL(["pbwg_1"]).account_related_to_entity_type() + Beneficiary.objects.all().filter(account=pbwg_account).delete() PBWG().run() logger.info( f"----------------------------- Aggregating PBWG journey for {pbwg_account} per org unit, admission and period(month and year) -----------------------------"