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

Improve rounding when converting between mg/dL and mmol/L #377

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

MikePlante1
Copy link
Contributor

Addresses Issue #267

Currently, Trio just rounds down when logging a manual glucose entry in mmol/L. This means that 7.6 gets logged as 7.5 because 7.6 / 0.0555 ≈ 136.9 gets rounded to 136 when Int(glucose) is performed which gets displayed as 7.5 because 136 * 0.0555 ≈ 7.5.

This PR rounds asMgdL to 0 decimal places and asMmolL to 1 decimal place which allows for more accurate rounding when converting units and back.

Here's a spreadsheet that highlights the mmol/L readings that caused mismatches: https://docs.google.com/spreadsheets/d/10ZHV7ZDd0_fjrV6k0FH1ouuqy2TSsDSBpBULE4yAFyg/edit?usp=sharing

@MikePlante1
Copy link
Contributor Author

I've tested this with manual glucose entries, temp targets, profile overrides, and target glucose. Setting it to a known problem number (like 7.6 or 8.1) in mmol/L and then switching to mg/dL and then switching back to mmol/L.

@marionbarker marionbarker self-requested a review August 12, 2024 14:43
@marionbarker
Copy link
Contributor

Status:

Success

Test with dev:

  • started with Trio dev, commit c04d33e
  • test a few of the mmol/L values in @MikePlante1 spreadsheet
  • use the log glucose screen:
    • enter 6.1, see 6.0 (109)
    • enter 11.1, see 11.1 (200)
    • enter 10.6, see 10.5 (190)

Test with PR 377

  • applied patch for PR
    • requires a Product Clean Folder before building
  • test same entries in the log glucose screen:
    • enter 10.6, see 10.6 (191)
    • enter 11.1, see 11.1 (200)
    • enter 6.1, see 6.1 (110)

Modify to mg/dL, add to list above the mg/dL value in parentheses.

@MikePlante1 MikePlante1 marked this pull request as draft August 12, 2024 21:18
@MikePlante1 MikePlante1 marked this pull request as ready for review August 12, 2024 22:39
@MikePlante1
Copy link
Contributor Author

Note that this PR does not solve rounding issues pointed out in this comment where settings can shift up to 1 mg/dL when switching units from mg/dL to mmol/L and then back to mg/dL.

I think the best way to solve that issue would be to update Trio so all mmol/L inputs are converted to mg/dL upon entry and only converted back to mmol/L when used for display. (Work has already begun on this in a private fork)

@AndreasStokholm AndreasStokholm merged commit aeb9cdf into nightscout:dev Aug 16, 2024
1 check passed
@MikePlante1 MikePlante1 mentioned this pull request Aug 17, 2024
@MikePlante1 MikePlante1 deleted the units branch August 18, 2024 19:35
mountrcg pushed a commit to mountrcg/Trio that referenced this pull request Sep 11, 2024
Improve rounding when converting between mg/dL and mmol/L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants