Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node": "20.8.0"
},
"packageManager": "[email protected]",
"version": "1.54.0-web-4274-copy-billing.6",
"version": "1.54.0-rc.4",
"description": "Tidepool data visualization for diabetes device data.",
"keywords": [
"data visualization"
Expand Down
2 changes: 1 addition & 1 deletion src/utils/basics/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function defineBasicsAggregations(bgPrefs, manufacturer, pumpUpload = {})

case 'boluses':
title = t('Insulin');
summaryTitle = t('Avg boluses / day');
summaryTitle = t('Avg insulin injections / day');
dimensions = [
{ path: 'summary', key: 'total', label: t('Avg per day'), average: true, primary: true },
{ path: 'summary.subtotals', key: 'wizard', label: t('Calculator'), percentage: true, selectorIndex: 0 },
Expand Down
10 changes: 8 additions & 2 deletions src/utils/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const formatDatum = (datum = {}, format, opts = {}) => {
*
* @returns {Object} an object with values corrected to sum up to 100%
* - if the values do not sum up to 100%, the 'high' range is adjusted to compensate
* - in specific edge cases, the values may still sum up to 101%
*/
export const reconcileTIRPercentages = (timeInRanges) => {
const DECIMAL_PRECISION = 2;
Expand All @@ -325,8 +326,13 @@ export const reconcileTIRPercentages = (timeInRanges) => {
// e.g. if sum === 0.99 and high === 0.21, we increase high to 0.22 so that all TIR
// values add up to 1 (or 100%).
const diff = 1 - sum;
const newHigh = bankersRound((modifiedTimeInRanges.high || 0) + diff, DECIMAL_PRECISION);
modifiedTimeInRanges.high = newHigh;

let newHigh = (modifiedTimeInRanges.high || 0) + diff;

if (newHigh < 0) newHigh = 0;
if (newHigh > 1) newHigh = 1;

modifiedTimeInRanges.high = bankersRound(newHigh, DECIMAL_PRECISION);

return modifiedTimeInRanges;
};
Expand Down
22 changes: 22 additions & 0 deletions test/utils/stat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,28 @@ describe('stat', () => {
});
});
});

describe('does not adjust high below 0% (edge case)', () => {
it('when using standard range', () => {
const timeInRanges = {
veryLow: 0.069767,
low: 0.465116,
target: 0.465116,
high: 0,
veryHigh: 0,
};

// The algorithm would be expected to subtract 1% from High to keep the Total at 100%,
// but we can't go below 0%, so the Total in this case will be 101%
expect(stat.reconcileTIRPercentages(timeInRanges)).to.deep.equal({
veryLow: 0.07,
low: 0.47,
target: 0.47,
high: 0,
veryHigh: 0,
});
});
});
});

describe('reconcileTIRDatumValues', () => {
Expand Down