Open bjornoleh opened 4 weeks ago
@mountrcg noted that the conversion issue also affects BG target values:
I notice the behaviour too. If I change from mg -> mmol and back, my target settings will change from an even number to an odd number. very annoying.
Perhaps other parts of the code too (BG values in general, ISF settings?)
Please see: LoopKit PR 527: Fix issue where glucose values outside of guardrails could be selected.
Possibly adapt the code in the LoopKit/QuantityFormatter.swift
for Trio:
func doubleValue(for unit: HKUnit, withRounding: Bool, usingFractionDigits fractionDigits: Int? = nil, rule: FloatingPointRoundingRule = .toNearestOrAwayFromZero)
I notice the behaviour too. If I change from mg -> mmol and back, my target settings will change from an even number to an odd number. very annoying.
Screenshots - note the original target = 100mg/dL | mg/dL | -> mmol/L | change back |
---|---|---|---|
Describe the bug
The manual BG values 8,0 and 8,1 are both displayed as 8,0 in the list of BG values.
Test of manual BG values (mmol/L) : 8,2 (stored as 147 mg/dL) 8,11 (stored as 146 mg/dL) 8,1 (stored as 145 mg/dL) 8 (stored as 144 mg/dL)
Displayed as follows in the app:
Below is the json of the above manual BG values:
Trio Version:
Additional context
The BG values are not saved as mmol, but are converted to mgdL first.
It turns out 8,1 is stored as 145 mg/dL, although the correct conversion is 8,1 / 0,055 = 145,9459
Then the displayed value after converting back to mmol is no longer the same as the entered value of 8,1 mmol: 145 x 0,055 = 8,0475
The reason seems to be that the initial conversion to mgdL does not round the result correctly, and truncate the result to the integer value.
The relevant code is here:
https://github.com/nightscout/Trio/blob/14c7643275e3f351448d7623432f0d1778b65af4/FreeAPS/Sources/Models/BloodGlucose.swift#L52-L105