Skip to content

Add monthly daly reporting to individual history tracker#1847

Open
marghe-molaro wants to merge 9 commits into
masterfrom
molaro/add-dalys-to-individual-history-tracker
Open

Add monthly daly reporting to individual history tracker#1847
marghe-molaro wants to merge 9 commits into
masterfrom
molaro/add-dalys-to-individual-history-tracker

Conversation

@marghe-molaro
Copy link
Copy Markdown
Collaborator

PR to ensure that the monthly dalys reported are included in the individual history tracker, broken down by cuase.

Note: In the healthburden module, we do not automatically dispatch the raw reported dalys dataframe in all instances, but first:

  • Check if relevant listener is included;
  • Pre-process dispatched data to only include non-zero entries;
    This should avoid unnecessarily dispatching large dataframes during runtime.

Copy link
Copy Markdown
Collaborator

@tbhallett tbhallett left a comment

Choose a reason for hiding this comment

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

All seems fine to me.

Two comments both thinking about speed, but do not feel very attached to either.

Happy to approve now

Comment on lines +626 to +630
data = {
person: {col: val for col, val in cols.items() if val != 0}
for person, cols in monthly_dalys_nonzero.items()
}
notifier.dispatch("healthburden.monthly_daly_report", data=data)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm wondering why you pack it into a dictionary here (two nested for-loops), and then unpack again (two more nested for-loops) when it goes to the function in the notifier? Could the pd.Dataframe be passed here, and then packed-into the eav format once?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes that's a good point; my naive guess was that the cost of reformatting non-zero entries into a dictionary is less than dispatching the entire dataframe which may contain a lot of zero entries*, but this may be incorrect. @tamuri happy for you to advise.

*This also a naive guess, based on the assumption that most individuals only have one or two conditions reported every months (meaning that all other columns would be zero for them), and that a single condition would typically affect <<20% (?) of the population.

Copy link
Copy Markdown
Collaborator

@tamuri tamuri Mar 25, 2026

Choose a reason for hiding this comment

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

Tim is right - you don't need any filtering here. You're passing a reference, not a copy of the dataframe. You do need to ensure there is no editing of the dataframe in the receiver because it is used after the notification.

It's also how notifications are usually setup. You don't know how receivers need the information so send everything and then the receiver can do its own filtering (or not, as needed).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

An additional benefit is that you can remove the has_listeners check

Comment thread src/tlo/methods/healthburden.py Outdated
@marghe-molaro
Copy link
Copy Markdown
Collaborator Author

Last commit now ensures that event_tag is leveraged when reformatting the eav-style log, to distinguish between events with the same name happening on the same day for the same individual.

for idx, row in monthly_dalys_nonzero.iterrows()
}

notifier.dispatch("healthburden.monthly_daly_report", data=data)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use dash instead of underscores here, to match other listeners.

Suggested change
notifier.dispatch("healthburden.monthly_daly_report", data=data)
notifier.dispatch("healthburden.monthly-daly-report", data=data)

Copy link
Copy Markdown
Collaborator

@tamuri tamuri left a comment

Choose a reason for hiding this comment

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

Mentioned some small changes, otherwise looks good.

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.

3 participants