These are chat archives for nightscout/intend-to-bolus

12th
Sep 2015
Scott Leibrand
@scottleibrand
Sep 12 2015 03:45
and I use a solution almost identical to what Oskar suggested. See my loop.sh for details of how it detects git corruption and fixes it.
Oliver Schumacher
@oschumac
Sep 12 2015 07:25
Hi what i did not understand what is git doing in openaps ?
Oskar Pearson
@oskarpearson
Sep 12 2015 09:14
@oschumac My understanding is that the code commits the files to git every time the program runs, so that:
1) if openaps.ini gets corrupt, you can go back and get a working version
2) If you want to see what the prediction or data was 5 hours ago, you can jump back to the files that existed at that time, and compare it against how your glucose actually changed
Oskar Pearson
@oskarpearson
Sep 12 2015 12:15
@ps2 Regarding the RileyLink and EU/UK usage. I've found reference to ANT-868-JJB-RA in this chatroom in the past. I'm just working through the other components though. It seems that 0915BM15A0001E is also 915Mhz specific. Would 0896BM15A0001E be the correct UK replacement?
Pete Schwamb
@ps2
Sep 12 2015 12:44
I'm not sure how big of a difference that part makes, but yes, it would be ideal to get a balun closer to the desired freq
Pete Schwamb
@ps2
Sep 12 2015 12:50
Dimensions an pin out are the same, so it should be a drop-in
There is also 0868BM15C0001
Oskar Pearson
@oskarpearson
Sep 12 2015 16:10
Great.
Oskar Pearson
@oskarpearson
Sep 12 2015 16:17
@ps2 Another question if you don't mind. I've not bought SMD components before. How do you normally go about buying the resistors and capacitors, which don't have model numbers? I've bought packs of standard resistors/capacitors at local shops, but not SMD ones.
Oskar Pearson
@oskarpearson
Sep 12 2015 16:37
About TPS63031 - the package is listed as SON50P260X260X80-11N which I'm having trouble tracking down. I've found http://uk.mouser.com/ProductDetail/Texas-Instruments/TPS63031DSKT - hope that's right
Scott Leibrand
@scottleibrand
Sep 12 2015 16:56
@oschumac git is what @bewest used to keep a history/log of everything openaps does. Every time you run openaps report invoke, it updates the output file and commits it to the local git repository, so you can go back and see exactly what information was reported by the pump.
Unfortunately git is designed to be run by humans, not run in an automated process on an embedded device whose file system write capabilities are dependent on flaky battery power. So sometimes when it's writing openaps.ini or something else, it instead manages to truncate it, or corrupt the git repository.
So we have a couple workarounds to keep the loop from completely dying when that happens. Unfortunately they involve blowing away the entire git history, which kinda defeats the point of using git.
It would probably be better if we replaced git with something that had more atomic append-only semantics and was incapable of corrupting things. It would need to write a new temp file, verify that it contains valid data, and then do an atomic mv operation or something to update the current file.
Oskar Pearson
@oskarpearson
Sep 12 2015 17:02
I think git's only really getting corrupt because of the raspberry pi's propensity to corrupt files on a reboot
Scott Leibrand
@scottleibrand
Sep 12 2015 17:02
we would also want it to validate that what we got from the pump was what we asked for. Currently we can get nonsense values (like 0 for insulin sensitivity) sometimes. I have some validity checking in openaps-js loop.sh, but it would be better to move that down into openaps or even decocare.
Oskar Pearson
@oskarpearson
Sep 12 2015 17:02
So I suspect that any other program would also have similar issues
I'm interested to see if the edison is better, since it has built in flash
Scott Leibrand
@scottleibrand
Sep 12 2015 17:03
@oskarpearson yes, that seems likely. Especially when the battery power dies off slowly instead of being pulled cleanly.
There are ways to structure this kind of transaction log such that corruption doesn't break the whole system.
If one record gets corrupted, you should still be able to proceed.
Oskar Pearson
@oskarpearson
Sep 12 2015 17:04
http://www.jrmarshall.com/2015/02/05/minimize-corruption-on-raspberry-pi-sd-card/ has an alternative view - it mounts the filesystem as read-write for as short a period as possible
Scott Leibrand
@scottleibrand
Sep 12 2015 17:05
yeah, we could split the persistent data into a read-only partition too.
Oskar Pearson
@oskarpearson
Sep 12 2015 17:05
It can still get corrupt, but the period where it can get corrupted is shorter
Scott Leibrand
@scottleibrand
Sep 12 2015 17:05
I suspect we'll have this issue in some form until we move to android or Edison or something.
I wonder if Linux supports append-only file systems.
Oskar Pearson
@oskarpearson
Sep 12 2015 17:10
The journalling on ext4 should be completely reliable. But the issue is that when the kernel thinks block XYZ has been written, but the SD card hasn't actually decided to write that yet, or does things out of order, there's very little sense to it
I suspect certain SD cards are worse than others.
Pete Schwamb
@ps2
Sep 12 2015 17:20
@oskarpearson I think that’s an artifact of the eagle library part I used. The TPS63031 I ordered from mouser lists the package as WSON-10
I’ve updated the bom.csv file as to not confuse other people.
Oskar Pearson
@oskarpearson
Sep 12 2015 17:24
Thanks
Pete Schwamb
@ps2
Sep 12 2015 17:24
You can buy smd resistors/caps in packs from amazon or other places. Just search "0402 resistor kit”. Some resistors/caps require a certain +/- accuracy, and those I’d order individually.
Oliver Schumacher
@oschumac
Sep 12 2015 18:11
@scottleibrand. I have put in the loop.sh an log function to do so. so i do have an openaps.log in /var/log. And use the nightscout side treadments that i send from openaps. And the thing that a love most is using pebble cards for diagnostic. I used the die () function from loop sh to create a vibration alarm on pebble watch. From my side that are enough methods for diag and logging. What openaps does. Maybe i should upload my loop.sh for campairision.
Oskar Pearson
@oskarpearson
Sep 12 2015 18:46
So, I'm trying to get my head around the way that the determine_basal code works, at the same time as I'm trying to get it to work with the cleaned up glucose reading. Since I've not had it work at all before, I'm not sure if the behaviour I'm seeing is normal
So here's a situation:
Glucose is currently 153, and although there was a bit of a peak, it's reasonably stable.
15 minutes ago, the determine-basal output was that we should set a temp basal of 2 (up from the normal of 1.35).
Now, it's saying that we should suspend the basal:
{"temp":"absolute","bg":154,"tick":"+0","eventualBG":139,"snoozeBG":154,"duration":30,"rate":0.15,"reason":"20@2 > -0.6040477834666667U"}
Screen Shot 2015-09-12 at 19.49.29.png
This message was deleted
(The graph has UK units)
Ok - not quite suspend the basal, but compared to the normal rate of 1.35, it's pretty low
I'm fairly sure that if we follow the advice, sugars will climb
Oskar Pearson
@oskarpearson
Sep 12 2015 18:51
{"iob":0.8622557557333337,"activity":0.021148809523809525,"bolusiob":0.47556333226666675}
I guess I'm trying to understand how the code should react to a high sugar. Does it try bring it down slowly? Does it try bring it down fast and then suspend pump, or what?
Oskar Pearson
@oskarpearson
Sep 12 2015 19:02
Also - what does the '30' in these lines mean? https://github.com/openaps/openaps-js/blob/master/bin/determine-basal.js#L24-L30 It seems to be saying "if the glucose is less than 30" - but I'm not sure why we'd ignore super-low sugars. Is it because the Dexcom occasionally reads such low values, ala https://github.com/bewest/openaps-example/blob/ec1b7dae840a500a90c5262cf82f208642f0a731/glucose.json#L111-L115 ?
I'm inclined to not have special cases in the sugar values. If things need cleaning up before they get into the cleaned-up glucose file, they should be handled by the cleaner script...
It seems like a recipe for dangerous situations - eg, when someone's sugar is actually < 30 the code could do the wrong thing
Chris Hannemann
@channemann
Sep 12 2015 19:07
I can't speak to the specifics of determine_basal, but regarding the very low BG readings, the glucose cleaning (glucose_tools) filters them out.
The Dexcom sensor doesn't show anything below 40 (think it might show 39) for "Low"
Oskar Pearson
@oskarpearson
Sep 12 2015 19:08
Ok
Chris Hannemann
@channemann
Sep 12 2015 19:08
But when there is an error (hourglass, "???", range stuff) it appears as 5, 10, etc
So those get thrown out
Oskar Pearson
@oskarpearson
Sep 12 2015 19:09
So the actual lows (40 or 39) do get passed through?
Chris Hannemann
@channemann
Sep 12 2015 19:09
Correct
Oskar Pearson
@oskarpearson
Sep 12 2015 19:10
:thumbsup:
I'm going to remove that bit from the js code then
Chris Hannemann
@channemann
Sep 12 2015 19:10
But since glucose_tools and determine_basal were created independently, they do that redundantly at the moment
@scottleibrand et al will be working on harmonizing them in the near future
Oskar Pearson
@oskarpearson
Sep 12 2015 19:11
Ok. I'm busy working on trying to get the determine_basal code to work off the cleaned up input files, rather than dexcom specific files
Chris Hannemann
@channemann
Sep 12 2015 19:11
If you remove it from js, I'd make sure and create a unit test to still check it
Oskar Pearson
@oskarpearson
Sep 12 2015 19:12
There are no unit tests - not even a unit testing library :(
oskarpearson @oskarpearson sobs
Chris Hannemann
@channemann
Sep 12 2015 19:12
Congrats, you get to build the first one!
Oskar Pearson
@oskarpearson
Sep 12 2015 19:13
That's the blind leading the blind ;) I don't have a dexcom so I'm not sure entirely what it should be doing, so I'm more likely to put bad tests into place
but I'm slowly figuring it out
Chris Hannemann
@channemann
Sep 12 2015 19:14
glucose_tools has unit tests, so you can look at the inputs and outputs there to see what you'd be passing
Oskar Pearson
@oskarpearson
Sep 12 2015 19:14
honestly, my inclination is to chuck the js code and use the same unit-tested structure as the python code. I really don't like that the JS code seems to be completely happy to use global variables, which makes it very difficult to test. Eg - each function can see all the data loaded by the main code, rather than requiring it be passed in.
But.. I need to understand the JS code before I can really say that
Chris Hannemann
@channemann
Sep 12 2015 19:15
Understand. Again, not very familiar with the JS code, so Scott is your best resource there.
Oskar Pearson
@oskarpearson
Sep 12 2015 19:17
@channemann you're on closed loop, aren't you? What are you using for determining the basal? the JS code?
Chris Hannemann
@channemann
Sep 12 2015 19:17
@loudnate and I use openaps-predict
That runs the predictions; the code for dosing is not public
Ali Mazaheri
@amazaheri
Sep 12 2015 19:20
@oskarpearson I originally added the check for Dexcom ??? Calibration numbers (5 and 10) but looks like @channemann has seen random numbers like 13 . You can certainly change your version to a number you comfortable but if you have a really low number like 40 you cannot and you should not rely on openAPS anyways.
Oskar Pearson
@oskarpearson
Sep 12 2015 19:23
I'd say the code needs to handle super low numbers in an appropriate and safe way, yep
Ali Mazaheri
@amazaheri
Sep 12 2015 19:25
For really low scenarios for example I rely on push notification coming from NightScout and prevent it before it gets that low and it has happed couple of times that openAPS been trying to fight a low with 0 temps but a carb correction needed to bring numbers to normal range :)
Scott Leibrand
@scottleibrand
Sep 12 2015 19:29
@oskarpearson so I suspect what you're seeing is because you don't have a max_iob.json, so it goes into "safe mode", sets the max iob to zero, and only helps with low BGs.
if you set {"max_iob": 1} or something, it will high-temp for high BG until basal iob gets up to 1U
and yes, the BG < 30 code is because the Dexcom always reports 39 for LOW BG, and codes <30 are reserved for error conditions like ??? and hourglass. For compatibility with Medtronic CGM we may need to change how those are recognized.
Heh. Codes < 30.
Ali Mazaheri
@amazaheri
Sep 12 2015 19:32
:)
Scott Leibrand
@scottleibrand
Sep 12 2015 19:33
Someone suggested we import the unit testing stuff from Nightscout, where they have implemented tests for the same code I imported for iob.js.
Oskar Pearson
@oskarpearson
Sep 12 2015 19:34
@scottleibrand that guess sounds spot on. I'm not supplying max_iob.json to the profile code
Scott Leibrand
@scottleibrand
Sep 12 2015 19:35
we did that as a safety measure so if anyone blindly implements the openaps-js code they can't get an insulin overdose from bad pump settings etc.
Scott Leibrand
@scottleibrand
Sep 12 2015 19:36
I might need to adjust it to not high-temp in the first place if that would put iob over max_iob
the original source is in scottleibrand/cgm-remote-monitor branch wip/iob-cob.
That iob.js is the original source imported into mainline with tests.
And refactored some.
Oskar Pearson
@oskarpearson
Sep 12 2015 20:00

I saw a mail to the dev mailing list about "bgi" (Blood Glucose Impact: "current insulin activity times sensitivity") the other day. I wanted to check in about these lines of code, though: https://github.com/openaps/openaps-js/blob/master/bin/determine-basal.js#L104-L107

Does the '5' in them refer to the 5 minute interval between blood glucose readings?

Ali Mazaheri
@amazaheri
Sep 12 2015 20:05
@scottleibrand switching to your loop.sh and give in to aliases :)
Oskar Pearson
@oskarpearson
Sep 12 2015 20:15
@bewest Have you considered adding locking to the serial port on decoding-carelink, ala http://stackoverflow.com/a/19823120 ?
(I'm aware there's still a locking issue with .json files being overwritten if the scripts overrun each other)
Ben West
@bewest
Sep 12 2015 20:19
yes, using fuser
not locking
see man fuser or fuser --help
will add it to openaps direct
Scott Leibrand
@scottleibrand
Sep 12 2015 20:24
@oskarpearson Yes, the 5 is 5m.
There's a TODO with that code: we should be parsing times, not assuming a data point every 5 minutes.
Currently my code overreacts when data is missing.
Ed Raskin
@msrcgm
Sep 12 2015 20:42
Hi gang, Ed here. Ready for set up.
Ali Mazaheri
@amazaheri
Sep 12 2015 21:10
Welcome Ed!
Ed Raskin
@msrcgm
Sep 12 2015 22:09
Thanks, Ali -- I've got my CanaKit taunting me to get started. @bewest , I hear you are the man with the latest draft of instructions. I'm ready for my dry run as soon as you upload.
Rachel Sandlain
@audiefile
Sep 12 2015 22:26
@scottleibrand I've been looking at getting loop.sh to run. I'm curious about the x.json.new why call both glucose.json and glucose.json.new?
Scott Leibrand
@scottleibrand
Sep 12 2015 22:35
Generally I don't call both. I usually call .new when I want to check its output before copying (rsync'ing) the .json.new file over to .json
otherwise you get garbage data from te pump and the loop makes bad decisions until it refreshes.
Rachel Sandlain
@audiefile
Sep 12 2015 22:36
so if they have the same data then you know it's old without having to try and read time stamps, etc
that makes a lot of sense.
Scott Leibrand
@scottleibrand
Sep 12 2015 22:37
Yeah, in that case that's what I'm doing.
Oskar Pearson
@oskarpearson
Sep 12 2015 23:03
With openaps-js, how should we be handling food boluses? I saw mention of the question with openaps-predict, so am interested in whether there's anything specific to do with openaps-js
Scott Leibrand
@scottleibrand
Sep 12 2015 23:17
In openaps-js we have "bolus snooze", which subtracts out (adds back in) the bolus IOB initially, then decays it over 60-90m.
The assumption is you must have bolused for some good reason, whether it's for carbs or something else.
So the user can bolus for their meal normally, and after an hour or so openaps will take back over and start fine-tuning basal as you start to come down from the meal rise (if any).
Oskar Pearson
@oskarpearson
Sep 12 2015 23:23
@loudnate @channemann Do you plan on releasing the openaps-predict based dosage calculator? What are your concerns doing so? It still in the early stages?