Skip to content

Round progress percentages appropriately#3465

Merged
jschuurk-kr merged 8 commits into
mainfrom
3159-floor-for-progress-percentages
Jun 25, 2026
Merged

Round progress percentages appropriately#3465
jschuurk-kr merged 8 commits into
mainfrom
3159-floor-for-progress-percentages

Conversation

@jschuurk-kr

@jschuurk-kr jschuurk-kr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What & why

Solves one of the three findings in #3159:

ProgressBar percentage should be with floored instead of rounded input percentage: example Math.floor((totalFirstEntryFinished / total) * 100) : 0

Reason it should be floor is to avoid rounding a percentage >= 99.5% to 100%, suggesting a completed status. However, always using floor also means we round a percentage between 0 and 1 down to 0 in some cases where we shouldn't.

So we introduced a function (hat tip to @stacktraceghost for the conversation and the pair programming) calculateProgressPercentage() that calculates the percentage and rounds it down, except when it's within a range provided, in which case it rounds up.

There are three occurrences where we calculate a progress percentage. The function is used in two of them:

  1. In ElectionProgress, which is used for the progress bars for typists, any percentage >= 0.5 and < 1 is rounded up. So when you have e.g. 600 polling stations, the 0% of progress dissappears as soon as 3 polling stations have been entered.
  2. In useElectionStatus, which is used for the progress bar per status on the election status page, any percentage >=0 and < 1 is rounded up. So when you have e.g. 600 polling stations of which 599 are complete and 1 has errrors, part of the progress bar is red.

Sidenote on the MultiProgressBar: it accepts values that add up to a total larger than 100. It seems to handle that fine. Because of the data we provide it, the total will at most be slightly larger than 100.

For the third occurrence, calculateDataEntryProgress, which is used for data entry progress of a single entry when a typist submits data entry, I did not introduce the function, since it serves no purpose. It calculates the percentage completed of the pages in data entry. Since it is extremely unlikely we will ever have more than 100 pages, the issue of rounding down to 0 or up to 100 when we shouldn't, will not occur.
Since my initial solution was changing the round to a floor for all three occurrences, I have kept that change for this occurrence in this PR. At least it is consistent with floor being the default way to round in calculateProgressPercentage().

How to test

Tests were updated or added for each of the changes.

Reviewer notes

No notes.

@jschuurk-kr jschuurk-kr self-assigned this Jun 24, 2026
@jschuurk-kr jschuurk-kr requested a review from a team as a code owner June 24, 2026 16:24
@jschuurk-kr jschuurk-kr changed the title 3159 floor for progress percentages round progress percentages appropriately Jun 24, 2026
Lionqueen94
Lionqueen94 previously approved these changes Jun 25, 2026

@Lionqueen94 Lionqueen94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Comment thread frontend/src/utils/progressPercentage.ts Outdated
Comment thread frontend/src/features/data_entry_home/components/ElectionProgress.tsx Outdated
@stacktraceghost stacktraceghost changed the title round progress percentages appropriately Round progress percentages appropriately Jun 25, 2026
Co-authored-by: stacktraceghost <222603941+stacktraceghost@users.noreply.github.com>
@jschuurk-kr jschuurk-kr added this pull request to the merge queue Jun 25, 2026
Merged via the queue into main with commit 5f7c50b Jun 25, 2026
22 checks passed
@jschuurk-kr jschuurk-kr deleted the 3159-floor-for-progress-percentages branch June 25, 2026 08:50
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Abacus Development Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants