fix(gki): build the index from the glucose shown beside it

A reading entered in mmol/L is stored as whole mg/dL, and the index
divided the unrounded conversion, so a 5.2 / 0.3 pair printed beside a
17.4 rather than 17.3. Round the glucose to the decimal it is shown with
first and divide that. The tiles also printed a two-decimal ketone
reading to one decimal; show it as recorded.
This commit is contained in:
Marc-André Bombeck committed 2026-11-11 00:44:29 +01:00
1 parent c8b32ccaea
commit 5ebfac1259
5 files changed
+72 -22

No files matched your search

+6 -6
View File
@@ -207,11 +207,11 @@ describe("glucose-ketone index (#1367)", () => {
glucoseMmol: p.glucoseMmol,
})),
).toEqual([
// 81 mg/dL = 4.5 mmol/L; / 1.2 = 3.7
// 81 mg/dL = 4.5 mmol/L; / 1.2 = 3.75 -> 3.8
{
at: at(0).toISOString(),
glucoseAt: at(0).toISOString(),
value: 3.7,
value: 3.8,
ketonesMmol: 1.2,
glucoseMmol: 4.5,
},
@@ -261,7 +261,7 @@ describe("glucose-ketone index (#1367)", () => {
};
};
expect(gkiBody.data.unit).toBe("ratio");
expect(gkiBody.data.points.map((p) => p.value)).toEqual([3.7, 2.5]);
expect(gkiBody.data.points.map((p) => p.value)).toEqual([3.8, 2.5]);
expect(gkiBody.data.points[1]!.gki).toMatchObject({
glucoseAt: at(130).toISOString(),
glucoseMmol: 5,
@@ -301,7 +301,7 @@ describe("glucose-ketone index (#1367)", () => {
};
};
expect(body.data.glucoseKetoneIndex?.map((p) => p.value)).toEqual([
3.7, 2.5,
3.8, 2.5,
]);
expect(body.data.values.some((v) => v.type === "BLOOD_KETONES")).toBe(true);
});
@@ -324,8 +324,8 @@ describe("glucose-ketone index (#1367)", () => {
count: 2,
latest: 2.5,
min: 2.5,
max: 3.7,
avg: 3.1,
max: 3.8,
avg: 3.2,
});
const ketonesOnly = await collectDoctorReportData(