mddub / urchin-cgm

A graph of your CGM data on a Pebble watch.
MIT License
56 stars 45 forks source link

raw data for dexcom #2

Closed francesc0-cgm closed 8 years ago

francesc0-cgm commented 8 years ago

Great watch face...any chance to get raw data in? thank you

mgranberry commented 8 years ago

I was thinking raw data as a single-pixel-width line would work fairly well in the UI. I suspect the biggest barrier to raw data support is the size of the message required to transmit raw data.

mddub commented 8 years ago

At the least, we can show the most recent raw readings and noise in the status bar. I haven't had a chance to understand how the current Pebble app does it (I use Share), but that feature is coming soon.

Graphing raw data is a bit more complicated, but it's not out of the question. There are some other updates that are higher priority before I'll have a chance to look into that.

mgranberry commented 8 years ago

Raw data is pretty simple. From /api/v1/entries/sgv.json:

{
_id: "5663c657658c460aec52fce9",
unfiltered: 154592,
filtered: 157632,
direction: "Flat",
device: "alrightypump-Dexcom-G4-SM50556137",
rssi: 177,
dateString: "2015-12-06T05:20:20.000Z",
sgv: 130,
date: 1449379220000,
type: "sgv",
noise: 1
},

And from /api/v1/entries/cal.json:

{
_id: "5663c656658c460aec52fcb0",
scale: 1,
intercept: 31319.493324369978,
slope: 875.759135541607,
device: "alrightypump-Dexcom-G4-SM50556137",
dateString: "2015-12-05T21:05:23.000Z",
date: 1449349523000,
type: "cal"
},

This is the code from my dex library that applies a calibration to a raw value from the receiver:

interface Calibration {
    val slope: Double
    val intercept: Double
    val scale: Double
    val decay: Double
    fun apply(bgl: RawGlucoseValue): Double? {
        val mgdl = bgl.mgdl
        val filtered = bgl.filtered
        val unfiltered = bgl.unfiltered
        return if (unfiltered != null) {
            if ((mgdl != null) && (mgdl >= 40.0) && (mgdl <= 400.0) && filtered != null) {
                val ratio = scale * (filtered - intercept) / slope / mgdl
                scale * (unfiltered - intercept) / slope / ratio
            } else
                scale * (unfiltered - intercept) / slope
        } else
            null
    }
}

If the sgv field is unavailable (recently restarted, noise, etc), it uses the unfiltered value. Otherwise it scales the weight of the filtered/unfiltered values dynamically.

Algorithmically it is the same as NightScout's implementation, only somewhat more compact.

[edited to pull values from my lib vs. xDrip, which does some strange rounding and conversion to longs vs. Doubles that come from the receiver.]

mgranberry commented 8 years ago

I went ahead and implemented it as a status line message in https://github.com/mddub/nightscout-graph-pebble/pull/5

francesc0-cgm commented 8 years ago

Thank you i will give it a try. Many thanks again

mddub commented 8 years ago

@mgranberry, thanks for implementing this! Some thoughts:

  1. Would it be worthwhile to drop "Raw" and include "Cln/Lgt/Med/Hvy" instead?
  2. I think we should reverse the order of the numbers so that they go from older to newer (I think the graph biases towards that order). What do you think?
  3. My sense is that if people have raw, they also have a rig battery level. Is that right? Should there be a status bar option that shows both?
  4. Does cgm-pebble show the last 2 raw readings, or present the last value using both unfiltered and filtered? Not saying we should do the same thing, but if it's different, it might be worth calling the option "Raw Dexcom readings (last 2)" to avoid confusion.

I'm comfortable making these changes, but wanted some input since I don't use raw or xDrip.

francesc0-cgm commented 8 years ago

Imho i think raw are useful. A great gap between raw and BG is of course clue of noise. I can't use it on pebble time however. Settings menu is not accessible

mgranberry commented 8 years ago

1) yes, I think so. "raw" contains no information after a user is comfortable with it. 2) I've been thinking the same thing after using it for a day. 3) Probably. 4) it shows the three most-recent readings, but it does it without any consistency. It didn't look like three would fit with enough space to be readily interpretable. Nothing shows just filtered/unfiltered, but in most cases filtered is just unfiltered delayed by a few minutes. The nightscout "scaled" display does a pretty good job of showing filtered when flat and unfiltered when BG is changing rapidly. If nothing else it's what's expected because that's what nightscout and the cgm-pebble watchface do.

francesc0-cgm commented 8 years ago

When i load it on pebble time i go to settings but it freezes on loading settings and then it says app unsuccesfully installed. Sometimes pebble time app crashes instead trying to load it

francesc0-cgm commented 8 years ago

Tried also on pebble classic app. No settings access.

francesc0-cgm commented 8 years ago

Sorry i tried to compile it by myself. Now i used the pbw linked in readme and it works. I configured the graph and here it is 1449474519537-1339415747 Very cool imho. It would be perfect if instead "raw" we could have a third raw then as you said the noise status and then the battery status. Then i would Like also 24 HR option for euro people as me and then an alarm system...so it will be perfect. :-)

francesc0-cgm commented 8 years ago

Another thing missing is the time ago of last update indication imho. However i'm using it since this morning and it seems very stable and full working. Updates are on time as for classic nightscout WF. Another thing i would Like to have it is a line or a symbol on the graph to know the time map (3 HR - 2 HR - 1 HR) ![Uploading 1449497988045322578853.jpg…]()

mddub commented 8 years ago

Awesome! Maybe you were compiling it in a way that made the config page inaccessible from your phone. That would explain the app being unable to install. The watchface shouldn't crash in the absence of communication with the phone on startup, but I haven't actually tested that on a Time.

24 hour time format and showing noise and rig battery with raw will definitely be part of the next release. And yeah, I've also found myself wanting vertical gridlines... so they're coming Soon.

To show time since last update, Jason had a great suggestion of a pie chart icon that fills up (or empties) as it gets closer to the time of the next update. It could go in any corner of the screen like the battery icon. The fewer numbers, the better :)

francesc0-cgm commented 8 years ago

Excellent. It will be the best watchface ever! Last thing missing: iob information...with it i think it could be never overtaken. Maybe resizing pebble battery icon....With colour for pebble time i think will be heaven-like :-)

mddub commented 8 years ago

Made the changes to raw data I suggested above, plus support for mmol: https://github.com/mddub/nightscout-graph-pebble/commit/e1fe03 https://github.com/mddub/nightscout-graph-pebble/commit/a0846d

mddub commented 8 years ago

@francesc0-cgm, by IOB, do you mean IOB calculated from CarePortal treatments? The one displayed in the pill on Nightscout web?

francesc0-cgm commented 8 years ago

Yep thanks

francesc0-cgm commented 8 years ago

But it is an optional add. I tried new adds and it is almost perfect. Imho i would put rig battery info toghether with raw (are you able to put last three as in nightwatch and skycgm?). However i find it fully stable. Will you add alarms too?

francesc0-cgm commented 8 years ago

A bug i found is when you go away from the phone it will not connect automatically again. It shows bluetooth symbol with a line on and the time ago of disconnection but you have to restart the WF to let it works again

mddub commented 8 years ago

@francesc0-cgm, alarms are absolutely coming (eventually). IOB from NS would be straightforward to add by pulling it from the /pebble endpoint. Not sure 3 raw points would fit with the rig battery and noise (37% Cln 107 109 113), but I'll consider exposing number of raw points as an option (especially for when the status bar is taller).

For the connection issue, can you give steps to reproduce? On my iPhone, this is what I tried:

It could be an Android-only problem, or perhaps there is a difference between disabling Bluetooth and going out of range of the phone. Either way, being able to reproduce it is the first step.

francesc0-cgm commented 8 years ago

Disconnection issue never happened again. It could have been a BT problem of my phone. 3 raw will be awesome. Maybe you can reduce size of pebble battery icon and put it next to the time indication on the upper part, 3 raw, noise indication and rig battery will fit on the bottom bar. Iob could be inserted on the left of time imdication.

mgranberry commented 8 years ago

I am running 3 points with both battery indicators on the bottom row now and it is a very tight fit. Some of the text is drawn over the battery icon if BG is stable in the 140s. At most other times it is close but not obscured.

On Mon, Dec 14, 2015, 2:01 AM francesc0-cgm notifications@github.com wrote:

Disconnection issue never happened again. It could have been a BT problem of my phone. 3 raw will be awesome. Maybe you can reduce size of pebble battery icon and put it next to the time indication on the upper part, 3 raw, noise indication and rig battery will fit on the bottom bar. Iob could be inserted on the left of time imdication.

— Reply to this email directly or view it on GitHub https://github.com/mddub/urchin-cgm/issues/2#issuecomment-164372650.

francesc0-cgm commented 8 years ago

@mddub could you move away the pebble battery meter and reduce it. I appreciate editability of this watchface but for a reason of development might be better to set a standard screen aspect with most data as possible on screen?

mddub commented 8 years ago

I agree it's worth optimizing the display for the most common data scenarios, but it's still a work-in-progress. At the moment I'm focusing on making the layout configurable from the phone, which will also enable having several preset layouts. Some layouts will inevitably be more optimal than others for certain types of data. In the meantime, you can configure the battery icon to be in the time area (and move the time to the left or right), or remove the battery indicator. And of course you could remove the right-padding from the battery.

It's probably worth standardizing the size of icons like battery, but I'm waiting until there's a second icon to do that. If you want to make a smaller battery icon, pull requests are welcome :)

mddub commented 8 years ago

I made the number of raw points configurable in https://github.com/mddub/urchin-cgm/commit/2b0eda. This will be more useful when combined with a configurable layout (so someone could, say, make the status bar twice as tall and view the last ~8 raw points), but you can use it to show 3 points now.

Thanks so much for all your testing and feedback. Since the raw feature has been implemented, I'm closing this issue. Feel free to open another issue for other feature suggestions.