Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compute totals for numeric/boolean types respecting totalAggregationType (DHIS2-9155) #1700

Merged
merged 17 commits into from
Oct 18, 2024

Conversation

edoardo
Copy link
Member

@edoardo edoardo commented Sep 12, 2024

Implements DHIS2-9155

Relates to dhis2/data-visualizer-app#3194


Key features

  1. fix subtotals/totals to avoid undefined and show N/A when a sum cannot be computed due to different totalAggregationType along rows
  2. include booleans and all numeric types besides PERCENTAGE and UNIT_INTERVAL when computing cumulative values

Description

With these changes, all numeric and boolean types are used when computing totals, the calculation also respects totalAggregationType.
If the totalAggregationType changes along a row, the total cannot be computed and N/A is shown instead.
Along columns, the total should work and use the correct calculation based on the totalAggregationType of the data element (ie. SUM or AVERAGE), it's therefore possible to have different calculations on different column totals, depending on the PT layout.

There can still be cases where the api returns inconsistent metadata for certain data elements, where the totalAggregationType is not correct for the valueType.
This inconsistencies can cause the totals to be calculated wrongly in certain scenarios with mixed valueTypes (ie. a data element with PERCENTAGE valueType has SUM in totalAggregationType and its value will be included in the total calculation).
This is likely a problem along rows.

Before cumulative values only considered data elements with valueType NUMBER.
Now all values of data elements with numeric and boolean types except PERCENTAGE and UNIT_INTERVAL are used.
The other required condition is that the totalAggregationType for the value is SUM.
Depending on the PT layout, some tables can be a bit unclear, as some columns might be "skipped" in the calculation.


Screenshots

Totals with mixed numeric and boolean types (except PERCENTAGE and UNIT_INTERVAL):
Screenshot 2024-09-12 at 15 34 12

Totals with mixed numeric and non-numeric types:
Screenshot 2024-09-12 at 15 37 34

Screenshot 2024-09-12 at 15 39 05

Subtotals and totals with mixed numeric and non-numeric types:
Screenshot 2024-09-12 at 15 37 49

Cumulative values with mixed numeric and non-numeric types:
Screenshot 2024-09-12 at 15 40 21
Screenshot 2024-09-12 at 15 40 32

Cumulative values with mixed numeric, boolean and non-numeric types:
Screenshot 2024-09-12 at 15 47 18

Cumulative values with mixed numeric, boolean, and non-numeric types (PERCENTAGE is ignored):
Screenshot 2024-09-12 at 15 50 39

…alues

This makes the cumulative values feature more in line with the way
totals are computed.
The difference is that there is no accumulation for PERCENTAGE and
UNIT_INTERVAL types as these don't accumulate with a simple sum.
For row totals where 1 or more columns have a non-numeric/boolean data element, N/A is returned for the total cell.
For column totals, the totalAggregationType of the data element is used to compute
the total value.
Copy link
Collaborator

@janhenrikoverland janhenrikoverland left a comment

Choose a reason for hiding this comment

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

Approved after test session on Friday Oct 18

@edoardo edoardo merged commit a2bfd20 into master Oct 18, 2024
4 checks passed
@edoardo edoardo deleted the fix/pt-totals branch October 18, 2024 09:43
dhis2-bot added a commit that referenced this pull request Oct 18, 2024
## [26.8.7](v26.8.6...v26.8.7) (2024-10-18)

### Bug Fixes

* compute totals and cumulative values for numeric/boolean types respecting totalAggregationType (DHIS2-9155) ([#1700](#1700)) ([a2bfd20](a2bfd20))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 26.8.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants