Skip to content

Commit

Permalink
fix: delete existing analytics data before generate fresh one
Browse files Browse the repository at this point in the history
Refs: WC2-631
  • Loading branch information
bramj authored Dec 18, 2024
2 parents e1d0797 + 6d967fc commit 24eda93
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
6 changes: 2 additions & 4 deletions plugins/wfp/management/commands/nigeria/Under5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/wfp/management/commands/south_sudan/Pbwg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/wfp/management/commands/south_sudan/Under5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion plugins/wfp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -35,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) -----------------------------"
Expand Down

0 comments on commit 24eda93

Please sign in to comment.