-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
bg data smoothing #2141
bg data smoothing #2141
Conversation
The plugin works as @justmara described. The fact that not only back smoothing takes place, but that the current value is also modified (and deviates from the display in xDrip+) is unusual at first. But at second view it is plausible. |
well smoothing actual value leads to slowing down reaction to bg changes which not happen when backsmoothing |
@MilosKozak one of the future problems |
It adds minor slowdown of AAPS reaction for instant big changes. But that IS the point of smoothing itself - to leverage impact of occasional changes and give AAPS strong reliable data to work with. |
@osodebailar Actually we are testing the first prototype with @blaqone together and the general broadcasting from G7 app to AAPS is working. Also backfilling capabilities are possible. We are just struggling with the data handling in AAPS but this is not a big deal at first look. @justmara It looks wonderful and is a great approach to also support stupid G7 sensors in the future. This will make the implementation in the G7 app obsolete. As i see there are some conflicts here. Do you plan to resolve them? |
bbc0d19
to
bce387d
Compare
@khskekec rebased on latest dev |
Hey @justmara , maybe i can help you just more with some additional data broadcasted from G7 to make the algorithm more solid? The following images are showing the available data for G7 sensor readings. I am not sure what data could be helpful for you but who knows... Just let me know :) |
@khskekec this code is sensor-agnostic. It works regardless of bg data source and does not have any of the particular source's additional data. It works over the AAPS GlucoseValue abstraction. So it won't have any special branch for G7 or any other sensor because it does not rely on sensor type at all. |
Love it! Please add! |
bce387d
to
2007bee
Compare
2007bee
to
3a2500a
Compare
and rebased on dev once again |
3a2500a
to
9af742a
Compare
9af742a
to
428196e
Compare
Basically very good approach! |
@szantos something like this? and a light theme and with smoothing switched off for my opinion it makes graph even more overloaded. there is too much info on it. maybe i can be added with additional selection option from dropdown - didnt look how that could be made |
holy crap, three rebases in a row and every time like whole project is mixed and moved around. some files are even deleted so i give up fixing this stuff up for now. will keep using it for myself then. |
All PRs have these problems at the moment, there is quiet some movement in the files right now. Just wait a week or two. I Really would love to have this merged! |
That's a nice one 👍 |
@justmara What I can see from it:
The effect on local extreme values is not clear to me. At 19:25 smoothed value is lower, at 20:15 higher than raw. Which one is right is hard to tell. 19:30-20:00 seems to be a fake low for me, but this smoothing is not intended to detect or correct it. The main reason I've asked for a 1:1 comparison ability is to make users able to better understand and judge the effect of this smoothing algorithm. Personally I'm happy about all kind of improvements which extend our toolbox, since they can be toggled on/off and not forced. Hope you get it merged! Danke! |
nope, it was real low handled with juice. but there was fake high at 19:25 (6mmol) - sometimes libre gives such one-point jumps and this smoother handles'em nicely. |
This is a brilliant addon, thank you for it! |
reverted bolus icon accidentally crawled in to previous commit:) (cherry picked from commit 47b5472)
Very cool. |
Yea works perfectly here too. Added it to the main branch, added autoIFS and g7 Support. So far: flawless! |
SonarCloud Quality Gate failed. 29 Bugs No Coverage information |
Hey, I just prepared nightscout to get and show smoothed data points across the raw values. As I know the smoothing just happens in Cgm Transaction but I think this is A very bad place to put interaction with nightscout. What is in your opinion a preferable place? And... is it correct that only the latest 10 readings will become smoothed? |
While I understand everyone's desire for super smoothed BG data, I don't know whether most people are aware that SMB existed well before the G6 and back smoothing did. It was never a requirement for using SMB. The original reason for preferring Dexcom was that the Dexcom data had a noise indicator in it (it still does) so OpenAPS could moderate it's behaviour based on that noise indication. |
Hi! Could you please update / rebase the PR? Milos is save of nitpicks done with moving things around. |
I'm the author of this code and have just been made aware about this PR from Mara's own repository. Sorry for being late to the party, I wasn't informed about this discussion, but as Mara said I am happy to make the code available to the community, especially as the feedback has been so positive. :) Anyway, here's a few comments from me:
@justmara Not that the details matter much, but it's a hybrid of first-order and second-order exponential smoothing functions - so not a true moving average. Basically, first-order exp. smoothing is faster to respond, but less robust (more prone to accepting sudden jumps). Second-order smoothing is slower to respond, but more robust as it assumes that the incoming data follows a trend. I made a hybrid out of the two as for our purposes, we want both: Speed and robustness. Of course, you can't have both at the same time, it's a trade-off. So what the code delivers is basically a little bit of both.
@MilosKozak I am often affected by noisy sensors (Dexcom G6) and back smoothing would mean trusting incoming values more than the sum of historic data. As you say, back smoothing will allow for faster reaction by AAPS, but this also means that dosing decisions may fluctuate a bit more when the sensor is noisy. Instead of questioning the current value, back smoothing will make historic data fit to the latest reading, regardless of its plausibility.
@szantos That's the dilemma here. :) The sensor spits out readings, but unless we compare it to true BG measurements (finger pricking..), we have no way to tell whether or not the reading is legit or not. What we can do (and what the code is doing) is a plausibility check. If there's a sudden jump, say +25 mg/dl, then it will mostly be smoothed out unless the trend continues. If the sensor spits out a series of wrong readings (e.g. compression lows at night), then it's very hard to tell if it's legit or not as this requires interpretation and putting the readings into context.
@khskekec Nope. The smoothing begins with historic data, and then progresses into the future until it reaches the latest reading. That's the main difference to back smoothing approaches, where we'd start with the most recent value and update the historic values only, moving backward.
@tim2000s While true, this is generally not enough for safe SMB delivery. Without smoothing, I've had some completely unnecessary SMBs in response to sensor noise on the G6. I know that BYODA is a smoothed Dexcom source, but AAPS will not reject alternative sources such as xDrip and allow enabling SMB always. Don't get me wrong, I'm a big supporter of xDrip, and because I do not want to use BYODA, I wrote this smoothing plugin.
@Der-Schubi There's been some massive changes to the AAPS code in the last few days that also affect the databases. I'll wait a bit and merge the changes into the smoothing algorithm later when it seems like the biggest changes are over. That's unfortunately not super simple and just getting the database migration right gave me a headache recently. :P But it will get done, eventually. Those interested in this and other developments by me (Tsunami project) are welcome to join my discord server for discussion. I'm less likely to miss messages there than I am here. ;P https://discord.gg/HFHVd3QB |
@piecycle hey! Didn't know how tag you here :). But this feature is so helpful, and we were talking with you about publishing it, so I decided to try bringing it here by myself. Damn, now it looks like if I've stolen it. You weren't very active in discord lately so I thought you don't have enough time, so I decided to make a move by myself since we were discussing it and already and you weren't against this. This code already was merged to my repo for pretty long time and I've heard many positive feedback from people using it, so decided to share. It is really very helpful feature. Will you handle updates by yourself then (making new pr or?) |
How does this PR handle new sensors (I'm using G6 atm, soon G7)? I noticed when I started a new sensor and the first readings came in AAPS with smoothing enabled just showed missing data all the time (waited for 30 minutes so 6 readings). Disabling smoothing, waiting for sensor readings and then re-enabling smoothing worked fine. |
You should always see new data immediately. The first few readings will not be smoothed as there's too few reference values, but you should still see something. I'm using a G6 myself with xDrip as my datasource. What is your source, are you using BYODA by any chance? |
Yes, BYODA. xDrip displayed the new data (coming from BYOAD) instantly and without problem, so we can rule out sensor or transmitter errors as reason. |
G7 or g6? |
At the moment G6. |
Hope someone can merge it quickly to dev (and later to master). My G6 with last BYODA has some noise too, when sensor is on last day/hours. |
https://github.com/DiaKEM/dexcom-g7-aaps/tree/blaqone-final With autoIFS thou. |
This problem also happens when you disable the smoothing after changing the sensor but before the 2hr wait time is over. Edit: Again, once there a five values available it backfills them and starts working as it should. |
I'm not against smoothing per se, but the elephant in the room here is one of the reasons that Dexcom took it out. From what I understand this was because their integration partners requested removal and the original data, not the backsmoothed data. Whilst it probably doesn't change much, it might be sensible to try to understand why that was. @piecycle it turns out that the noise data was never used in AAPS, which is why jumpy data for SMB will always have been an issue. |
This is incoming BG data smoothing taken from Tsunami project (I've contacted author long time ago, he has nothing against this move, but for some reason still didn't managed to make a PR).
It is a switchable option under 'Overview' settings group.
It uses sliding weighted average algo for calculating smoother curve. This acts much better than existing
use long_delta
.This can be used as a replace of 'advanced filtering' option to allow SMB usage on any data source.