nightscout / cgm-remote-monitor

nightscout web monitor
GNU Affero General Public License v3.0
2.4k stars 71.69k forks source link

Feature: activity tracking in Nightscout #3337

Closed PieterGit closed 4 years ago

PieterGit commented 6 years ago

Design decisions for integration of actvity tracking within Nightscout and APS'es:

@sulkaharo started the branch https://github.com/nightscout/cgm-remote-monitor/tree/wip/activitydata to make it possible for Nightscout to store activty data.

Discussion is: https://gitter.im/openaps/oref0?at=5a7ac3a97dcd63481f2aebba

I would like to use this issue for discussing this new feature.

PieterGit commented 6 years ago

My thoughts on minimal viable product and the responsibilities of ActivityUploader, Nightscout and the APS:

Minimal viable product:

ActivityUploader uploads one or more activity_records to Nightscout

{
  created_at: 2018-02-09T10:40:30Z // in UTC format, when was the activity record created
   activity_records: [ { 
    startTimeStamp: 2018-02-09T10:35:00Z, // start of activity (UTC)
    endTimeStamp: 2018-02-09T10:40:00Z, // end of activity (UTC)
    state: "awake", // awake, sleep, deepsleep, optional
    steps: 300  // number of steps in last 5 minutes (timeperiod)
  } ]
}

Based on some profile setting Nightscout will create temp targets when new actvity records are uploaded (and current) and there is no manual current temp target. In that case Nightscout will create temporary target for say 30 minutes based on some linear model based on normal steps per 5 minutes, and raise the target accordingly (e.g. running 8 mph leads to ~ 2000 steps in 5 minutes, so target is raised to 170).

I'll see if I can create an uploader in the xdrip / Pebble app somehow (note Pebble and Android programming is both new for me).

APS will use the temp targets for better insuline dosage. For oref0 this is already implemented as excercise mode, but in this case the excercise mode is automatically triggered without user intervention.

References:

Thoughts?

PieterGit commented 6 years ago

Also digged up some research (need to look more closely):

scottleibrand commented 6 years ago

I agree with the automatic temp target approach, but I don’t know if that should be done inside Nightscout. Downloading the activity data to the OpenAPS rig and doing the artificial temp targets locally seems to me like it would make more sense, so we can keep the auto-targeting logic together with the exercise mode logic. Thoughts?

jamorham commented 6 years ago

I have an uploader for this in xDrip but the format I have used so far is to reproduce the database records that xDrip stores, so like bpm vs timestamp.

PieterGit commented 6 years ago

@scottleibrand : I thought about this as well. I think there can be more than one activity devices, e.g. phone (GPS, Android wear, etc.), watches (e.g. Pebble) and API's from actvitytrackers (e.g. FitBit, Amazfit). So for most usecases online access will be available. When in house a Pebble or watch is much better for getting activity information than a mobile phone that's just lying on one place. If we would like to have an offline mode ( e..g xdrip to a rig with some kind of https://github.com/colinlennon/xDripAPS setup for activity data), we can create a nodejs javascript library that is shared for both Nightscout and oref0 (similar to Nightscout Autotune integration, https://github.com/nightscout/cgm-remote-monitor/pull/3191 ).

I'm thinking of using Xdrip+ with Android NS Client for connecting to the Pebble and then an oref0 rig with Dexcom G4 attached. In this setup Xdrip can upload the activities to Nightscout (similar as it does for treatments), Nightscout will set the appropriate automatic temp target and then the oref0 rig will use that. I'm using this Xdrip+ setup (without Xdrip) already because the Xdrip watchface and xdrip plus app of @jamorham is much better than urchin-cgm watchface connected to a rig. This setup would also work without problems for multiple rigs. If we decide to integrate an accelerometer on a future Explorer board, this setup could also work offline with the same codebase I suppose.

jamorham commented 6 years ago

Similar topic also worth thinking about. I have been interested in some time about like geographical based targets. With my family I have observed that lows can often occur at certain locations, for example swimming pool, supermarket etc. Altering the target higher at these locations could help perhaps. Somewhere some kind of geofencing or recording of the location so that machine learning can be used on the data set. I could probably build something with tasker and AAPS but as we're talking about extra sensor data, GPS can be quite significant too and is worth considering how it could be handled.

sulkaharo commented 6 years ago

Uploader requirements note: for kid users, a smart watch paired to the kid's phone might actually be used by a caretaker, so being able to select which data sources are uploaded and what are ignored would be extremely useful.

PieterGit commented 6 years ago

Thanks to @jamorham's commit the Android xdrip app is now able to upload activity data (steps, heartrate and activity according to the Android phone: in vehicle, walking, cycling, still, etc) and upload it to Nightscout. You'll need to enable Engineering mode.

I tested with Android xdrip, Android NS Client app, Pebble Time and it worked, but it drains the battery of the phone within 5 hours of walking.

I've been thinking of a user interface that makes it possible to set a temp target. First draft and first attempt of setting some activity targets in the profile: image

Quite complex UI I think. Ideas to make it easier are welcome. For heatrate I used the activity zones based on percentage of the HRmax from https://en.wikipedia.org/wiki/Heart_rate#Haskell_&_Fox

scottleibrand commented 6 years ago

You seem to be assuming the people's normal resting target is < 90 mg/dL? I think 100 is probably more common (and certainly safer). I would raise all of the activity targets to the values you have listed for > 30 minutes, since you can't know when the activity starts how long it will last. The "in vehicle" one presumably does not involve any physical exertion, so I would leave that one at 120 regardless of duration. You might be able to cancel the temp targets after just 15m of inactivity / lack of movement, though.

PieterGit commented 6 years ago

@scottleibrand : the 90 is an error. I should have written 100. I think the UI should not allow values lower than 100. I normally use mmol/L format so it's a mistake. I'll take your suggestions when I start to code the UI in Nightscout profile. From my experience 15m of inactivity/lack of movement is too short, blood glucose values seem to fall after excercise. The research above states "Increased insulin sensitivity lasts up to 24–48 h following exercise" and from my experience "exercise started within 90 min of consumption of the meal" can cause insulin to work much more aggressive and drop BG than without excercise. That's why I don't mind having set a higher target after excercise to prevent a hypo. All research suggest to decrease basal insuline upfront, but we can't look in the future of what activity is coming.

scottleibrand commented 6 years ago

Ok, I'm fine with either 15m or 30m. In my experience BG is usually falling by the time the activity is complete (and certainly by 15-30m later), so it's going to end up zero temping regardless of your temp target at that point, and it doesn't really matter exactly when you endit.

jamorham commented 6 years ago

@PieterGit I don't understand what the NSClient component was for in your above tests?

PieterGit commented 6 years ago

@jamorham: I don't use xdrip directly for CGM data. I'm using the xdrip app because it's much better for connecting to the pebble, and it can gives some extra alerts (and can upload activity data from the phone and pebble to Nightscout!). In my config BG is from Dexcom G4 connected to oref0 (edison) rig, that uploads bg+pump treatments to Nightscout. xdrip get's bg's from xDrip+ Sync Follower and AndroidAPS NS Client. It's a long route, but works quite well and stable. The core loop is just the Edison oref0 rig connected a Dexcom G4 by USB. The European Dexcom's don't support G4 share and as far as I know there is no other possibility for xdrip to get the CGM data from Nightscout.

PieterGit commented 6 years ago

I set the milestone for the next release. I first want to clean out the open PR's and open issues. so that Nightscout 0.10.3 can be released. If somebody fixes this feature in the next weeks, I'm happy to include it in the 0.10.3 release 😄

AndrewLovettHome commented 5 years ago

Hello. I am a newbie and in orr of the work that you guys have done. Thank you very humbly as your good work has changed my life in the last couple of weeks.

I wanted to offer a thought on uploading exercise data to NightScout. There is an app called FitnessSyncher that will take activity data from garmin, apple health, google fit, etc. and then send it to many other services. So it can take garmin activity data and put it into google fit which is pretty cool and I just did that tonight. The question arises, could there be an uploader from google fit to nightscout via xdrip? That way people could bring in most fitness activity data via fitnesssyncher to google fit and then on to the xdrip/nightscout ecosystem.

As I said, I am a newbie and also not very techo so I might be asking a silly question. Sorry if that's the case.

Cheers Andrew

PieterGit commented 5 years ago

Postponing to Nightscout 0.13 because we only implemented a bit for this PR. We should either work on it, or remove the activity storage feature from Nightscout if there is no interest in doing usefull stuff with int.

@jamorham Do you known if there xdrip plus uses activity data or that it's only able of storing it in Nightscout?