openaps / oref0

oref0: The open reference implementation of the OpenAPS reference design.
http://www.OpenAPS.org
MIT License
432 stars 394 forks source link

Update Nightscout basal profile from Autotune (new feature to be added) #965

Closed danamlewis closed 6 years ago

danamlewis commented 6 years ago

Proposal: It would be nice if autotune's recommendation file would also upload Nightscout's basal profile, so the profile didn't get out of sync with autotune. (This impacts how OpenAPS basals visualize, because the default value is the NS profile, which is usually out of date for most people)

Alternative/another option would be to have the pump profile drive the Nightscout profile update. Potentially give people an option (in preferences) of turning this on at all; and if so, choosing from pump or Autotune profile to run the update?

Related code: @Kdisimone has done this in a Loop branch. This diff here between her basal-profile branch and Loop master probably shows most of the code most relevant to this concept. From this line and below has some of the relevant code, which should give some clues on the plumbing needed to make this work in oref0: https://github.com/LoopKit/Loop/compare/master...Kdisimone:basal-profiles#diff-5b9067796f682df0e6723dfbb8aa0e6bR50

Some plumbing details to start:

TwistaTim commented 6 years ago

I am in favour of the Basal change driven by the Pump and having an option to update NS when the Basal Program has changed. We also need a profile name to be put in Settings, copy the NS profile to a new profile and update the profile with the new basals.

I am happy to work on this going forward, just need some guidance on branches to dev from, the git workflow here and base code structure etc.

kelseyhuss commented 6 years ago

I would like it to pull from Autotune, as those results are consistently changing versus the pump.

TwistaTim commented 6 years ago

That would be a separate operation as that would be an upload to the pump, you need a base basal even before autotune runs.

The pump should be the source of Truth for basals. Changing your base basals from Auto tune would be good, but the main issue is the Pump and NS base basals getting out of sync.

Proposition would be syncing the two up.....

sethgagnon commented 6 years ago

This would be a great feature to add!

linus-ha commented 6 years ago

So to keep this viral: It would be great if someboady would start inversting some time into this feature. Me and and I think a lot of others would be super happy about it.

danamlewis commented 6 years ago

Hi all - this is live right now @lini500, follow these instructions: https://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#how-to-automatically-sync-your-profile-from-autotune

Will close this issue that I had forgotten about :) Thanks for the reminder!

sethgagnon commented 6 years ago

Hi Dana, I have tried to run this a few times. I am using the Option C for autotune (running in an Ubuntu VM on Windows). I always get the following when I run it, any ideas? I blocked out my site and secret.

seth@SethsSurface:~/myopenaps$ oref0-upload-profile settings/profile.json MyNSSiteHere MySecretHere Could not parse input data: [TypeError: Cannot read property 'length' of undefined]

tim2000s commented 6 years ago

So the next requirement is to add this as an option in the startup script and get the start up script to add it into the nightly batch?

danamlewis commented 6 years ago

@tim2000s here's an open PR for that - I've been using it & like it. https://github.com/openaps/oref0/pull/1098

tim2000s commented 6 years ago

I've just tested this with the autotune profile. While it uploads ISF and basal rates, it doesn't do CR.

philipgo2 commented 5 years ago

For some reason oref0-upload-profile now reproducibly crashes my Nightscout instance (dev as of Dec 06). The output generated when using the --previewoption looks sensible so it must have to do with the upload.

Maybe something to do with https://github.com/nightscout/cgm-remote-monitor/commit/6a0e5d91d3c9378ae5dfd807b6b0d6b1332abf89 ?

PS: Could not find the original PR that added the oref0-upload-profile function. Maybe someone could reference it in here.

This is the Nightscout error log:

2018-12-06T21:48:28.991611+00:00 heroku[router]: at=info method=GET path="/api/v1/profile/current" host=abc.herokuapp.com request_id=4e35d086-6193-40a3-9090-ccd780aca137 fwd="217.224.163.242" dyno=web.1 connect=1ms service=31ms status=200 bytes=3226 protocol=https

2018-12-06T21:48:29.515236+00:00 heroku[web.1]: State changed from up to crashed

2018-12-06T21:48:29.428881+00:00 app[web.1]: GRANTED:  217.224.163.242 api-secret api:profile:read

2018-12-06T21:48:29.428976+00:00 app[web.1]: GRANTED:  217.224.163.242 api-secret api:profile:create

2018-12-06T21:48:29.430866+00:00 app[web.1]: got data-received event, requesting reload

2018-12-06T21:48:29.431572+00:00 app[web.1]: /app/node_modules/mongodb/lib/utils.js:132

2018-12-06T21:48:29.431575+00:00 app[web.1]:       throw err;

2018-12-06T21:48:29.431577+00:00 app[web.1]:       ^

2018-12-06T21:48:29.431578+00:00 app[web.1]: 

2018-12-06T21:48:29.431579+00:00 app[web.1]: TypeError: Cannot read property 'ops' of null

2018-12-06T21:48:29.431580+00:00 app[web.1]:     at /app/lib/api/profile/index.js:44:38

2018-12-06T21:48:29.431582+00:00 app[web.1]:     at /app/lib/server/profile.js:9:7

2018-12-06T21:48:29.431583+00:00 app[web.1]:     at err (/app/node_modules/mongodb/lib/utils.js:415:14)

2018-12-06T21:48:29.431585+00:00 app[web.1]:     at session.endSession (/app/node_modules/mongodb/lib/utils.js:399:27)

2018-12-06T21:48:29.431586+00:00 app[web.1]:     at ClientSession.endSession (/app/node_modules/mongodb-core/lib/sessions.js:129:41)

2018-12-06T21:48:29.431587+00:00 app[web.1]:     at executeCallback (/app/node_modules/mongodb/lib/utils.js:397:17)

2018-12-06T21:48:29.431588+00:00 app[web.1]:     at bulk.execute (/app/node_modules/mongodb/lib/operations/collection_ops.js:118:14)

2018-12-06T21:48:29.431589+00:00 app[web.1]:     at err (/app/node_modules/mongodb/lib/utils.js:415:14)

2018-12-06T21:48:29.431591+00:00 app[web.1]:     at executeCallback (/app/node_modules/mongodb/lib/utils.js:404:25)

2018-12-06T21:48:29.431592+00:00 app[web.1]:     at handleCallback (/app/node_modules/mongodb/lib/utils.js:128:55)

2018-12-06T21:48:29.494802+00:00 heroku[web.1]: Process exited with status 1

2018-12-06T21:48:29.446102+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/v1/profile" host=abc.herokuapp.com request_id=9579b2cf-87b4-4268-a589-436d5ecd25d0 fwd="217.224.163.242" dyno=web.1 connect=0ms service=18ms status=503 bytes=0 protocol=https

@jpcunningh I believe you worked on this, correct?

sulkaharo commented 5 years ago

@philipgo2 That's a strange crash and can only occur if inserting data to Mongo failed without reporting a problem with the insertion. Where do you host Mongo? Can you run repairDatabase() on your Mongo instance, as described here: https://davidburgos.blog/how-fix-quota-exceeded-mlab-mongolab/

This issue is not related to the linked PR - those code changes only affect CGM data uploads, while uploading profile data is handled by the profile API code.

Also note this is a closed ticket and I noticed this comment by luck - in the future please create a new ticket when a new problem is found and in case of Nightscout issues, the Nightscout repo might be a be better place. I now created a ticket there: https://github.com/nightscout/cgm-remote-monitor/issues/4126

macmccabe commented 5 years ago

Very basic question regarding initial setup in the profile.json file

My T1Ds 2 little girls under AGE 10 we don't use a pump, assuming that means we're on a "closed loop" setup? They use Humalog for carbs/correction and Lantus for daily "basal"

Lantus is taken once/daily at 7am

I guess I don't know enough of T1D to understand which values to fill in for the "start," "minutes," "rate," "min_5m_carbimpact," "dia," and "basalprofile" values.

Any help/guidance/sample .json profiles for someone using a "poor man's pump" setup would be greatly appreciated.

philipgo commented 5 years ago

Depending on what you want to achieve, it may be a lot easier for you to use AndroidAPS in open loop mode and select MDI (Multiple Dose Injection) as "pump".