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

Support Trend as a number and now as a string, Dexcom EU changed the type of Trend to string #51

Merged
merged 3 commits into from
Dec 1, 2021

Conversation

cpitchford
Copy link
Contributor

At 2021-11-30 17:00+UTC I found that, in the EU region, the Dexcom API switched the format of the Trend property.

Where as previously, the Trend property was a number, it is now a string. This breaks the direction feature.

here's a snip from my logs after the change:

Entries [ {
  WT: 'Date(1638301612000)',
  ST: 'Date(1638301612000)',
  DT: 'Date(1638301612000+0000)',
  Value: 84,
  Trend: 'Flat' // Previously this would've been 4
}

This change converts the string value back to an integer by finding the correct value in the DIRECTIONS object.

This restores the direction feature

It is unlikely to be rigorous since I don't now all the string values Dexcom will now return for Trend, but it certainly works for common values (up arrows, down arrows and flat)

At 2021-11-30 17:00+UTC I found that, in the EU region, the Dexcom API switched the format of the Trend property.

Where as previously, the Trend property was a number, it is now a string. This breaks the direction feature.

here's a snip from my logs after the change:

```
Entries [ {
  WT: 'Date(1638301612000)',
  ST: 'Date(1638301612000)',
  DT: 'Date(1638301612000+0000)',
  Value: 84,
  Trend: 'Flat' // Previously this would've been 4
}
```

This change converts the string value back to an integer by finding the correct value in the DIRECTIONS object.

This restores the direction feature

It is unlikely to be rigorous since I don't now all the string values Dexcom will now return for Trend, but it certainly works for common values (up arrows, down arrows and flat)
@cpitchford
Copy link
Contributor Author

This patch resolves #52

@p-kimberley
Copy link

p-kimberley commented Dec 1, 2021

@cpitchford Good spot. I've observed this too. US users don't appear to be affected...yet.

The only trend string I haven't yet seen is the equivalent of 9, or "RateOutOfRange".

Think you'll need to adjust your conversion method for "NOT COMPUTABLE" which in the API response, is now "NotComputable". Same for "NONE", which is "None". Think it's safe to say they've gone for TitleCase for all values.

Attempt to match the string Trend value passed in by Dexcom.

If it is a non-string, it is left unchanged (e.g if it is a integer as we expected previously)
If it matches a key in DIRECTIONS, that value is used
If it is converted to lowercase and spaces are removed, does it match a value in DIRECTIONS that have been similarly processed

This will help if Dexcom's case or usage of spaces is not entirely determined.
@cpitchford
Copy link
Contributor Author

Good point, I'm still getting fully up to speed!

I've added some code to match the string trend after converted to lowercase and removing spaces. This should cover all eventualities , save the prospect of an entirely new string appearing. This might be worth logging if we happen to fail to match?

Check that Trend is a number or a string as both may be returned by Dexcom API.
@bewest bewest changed the base branch from master to dev December 1, 2021 02:10
@bewest
Copy link
Member

bewest commented Dec 1, 2021

Thanks for improving this! I've retargeted the dev branch.

@PieterGit
Copy link
Collaborator

@cpitchford Great work! I was just figuring out why I saw Unicode Character “⇼” (U+21FC) in the direction field in Nightscout. Figured out it was caused by https://github.com/nightscout/cgm-remote-monitor/blob/46418c7ff275ae80de457209c1686811e033b5dd/lib/plugins/direction.js#L54 but then saw you and @bewest created a new share2nightscout-bridge and Nightscout release. Thanks a lot.

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