-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update Dexcom xDrip sensor start time from transmitter #3263
Conversation
This has been tested with G6 and G7 as far as the value shown on the classic status page. I have not tested AAPS as I don't use AAPS. But, it should work fine. |
I have tested this PR with AAPS and AAPS did receive the correct start time for the G7 Sensor from xDrip. |
@jamorham |
@@ -235,6 +235,16 @@ public static void updateSensorLocation(String sensor_location) { | |||
sensor.sensor_location = sensor_location; | |||
sensor.save(); | |||
} | |||
|
|||
public static void updateSensorStartTime(long started_at) { | |||
Sensor sensor = currentSensor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this could be null...
@jamorham Would you please review this? |
UserError.Log.e(TAG, "Updating sensor start time from the transmitter"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think megastatus is the right place to update this as that is only triggered when the UI is displayed. I think changes are needed like:
- Don't change start time the difference is already within say 10 minutes of the existing value.
- Don't change the sensor start time if the start time would be more than say a month in the past
- I would functionalize the check and move the call to it to just after the call to
DexTimeKeeper.updateAge()
in ob1 state machine EGlucoseRxMessage2 and also in ClassifierAction in the G7 section.
There is an existing function that is called after every reading, It only triggers if there is already an active sensor and only if the device is preemptive restart incapable. The only thing I have not done that you asked for is the requirement for the start time to not be older than 30 days. Please tell me if this is not good enough. I have verified that the start time on the classic status page is updated for G6 and for G7. Thanks |
You asked me to do three things. I believe I have done the first and the last. If we update the start time only if it is less than a month in the past, it means that we don't believe the sensor could have started more than 30 days ago and s till be active. If that is the reason, I don't understand why we are showing it on the G5/G6 status page. If we are showing it there, doesn't that mean that you believe it is valid? Then, why would you question it for putting it on the classic status page? You may be thinking, if you just do what I tell you, this will be merged. |
I ran the code and I noticed a pretty big bug with it. When the start time is updated, the next reading of the G6 sensor then requests a full backfill of glucose data. My use case is that I use an xDrip variant to start and pre-soak a G6 before switching to that sensor on the my main xDrip app. xDrip feeds my glucose data to AAPS and therefore this sort of extra backfilling is not acceptable in my opinion. If the sensor start date is going to be changed on an active sensor, then the code for the backfill calculation needs to be modified to not backfill beyond when the last glucose reading from the old sensor was received, or beyond the last sensor stop time. I think the easiest would be to not backfill beyond the last sensor stop. |
@nickb24 Thanks |
@nickb24 In 5 days, I will test this when I start my next G7. It should let me recreate what you are showing. |
I think it would do the same on the G7. Can't test it because I don't have a G7. But the code here is shows why it backfills to the start time of the sensor: xDrip/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1G5StateMachine.java Line 1099 in 2db9aa6
Not sure why we would even backfill beyond the last timestamp of glucose data. Not sure of the history of this part of the code. |
@Navid200 I had some free time today to take a closer look and figured out where the issue lies. At this line, xDrip/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1G5StateMachine.java Line 1069 in 1212e75
The backfill calculator is getting the list of last readings from the past in order from newest to oldest. However that function gets a list of glucose readings, but ONLY from the active sensor, as seen in that function:
I'm a little surprised by all this, because I thought people do switch from an active G6 sensor started somewhere else into xDrip. Unless no one has really cared about this in the past, or there is some other logic that is different in this use case. The only way to skip this logic is for |
@nickb24 People start G6 with a receiver or with their t:slim pump or even with a previous xDrip installation. And I have not been able to recreate the problem you have reported with this PR. Is it possible that you had anything else changes in your compile? |
@Navid200 I'm sorry I just reviewed this pull request history and I see that there was only 1 user who tried this. That's my fault. I thought more people tested it before me.
Yes that works, but that's because the sensor start time is not set to the time the sensor was actually started. It is set to the current time when xDrip first connects to a session in progress. So the backfill code won't backfill passed the sensor start time.
My code has nothing else that would conflict. The only other thing I did is that when I switch from xDrip variant, to my main xDrip, I make sure to unbond the transmitter first. So then on my main xDrip it does a full bond/pairing before connecting to the in progress session. Maybe that's the issue, not sure. |
@nickb24 Was engineering mode enabled when you ran your test? |
No engineering mode is off. I did think about this more and I maybe have a way to replicate this. So I when I switch to an active sensor I would notice sometimes that it would never pick up on the active session even after 4-5 reads. I would still have to click on start sensor and then it would pick up the session. So this is the sequence I did to cause my error. G6 session running already. On my main xDrip, this transmitter is not bonded. So, first reading happens and it bonds and I accept pairing request, then that's it. Next read comes in and detects an active session but still doesn't pick up glucose readings yet (logs show that since no sensor is active then no readings). So after this second reading I go and start the sensor from the menu, enter the sensor code. Next reading comes in and gets glucose and that it's it. Then on the next reading, it gets glucose, (presumably updates the sensor start time to the real one), and then it backfills the last 3 hours of that sensor and overlaps the readings. |
@nickb24 Can you check your Gitter messages please? |
I was testing a different PR (#3319) and got an overlap: The hardware data source was on xDrip sync follow. I switched it to G6 to test the PR, with that PR installed, and the overlap ocured. I am not sure what causes this. But, I don't believe it is related to the change I am proposing here in this current PR for updating the start time from the transmitter for G7 and Firefly. |
Tested with a four day old G7. Without this commit the classic status page has shown 14 days sensor time. With this commit it updated start time on classic status page and sent it correctly to AAPS. |
I'm thinking simplistically we can't update the start time of the current sensor before the end time of the previous sensor. If we want to allow overlapping sensors then the logic for detecting duplicates needs to ignore which sensor a reading comes from but that likely involves quite a few more changes and I'm worried about unintended consequences there. Would incorporating the check for the previous sensors end time as a gate for how far we can move the sensor start time backwards at least solve many instances of the problem this PR is designed to address? |
Sorry. This sounds like a misunderstanding. There is no overlapping. You can do the exact same thing with a G6. xDrip automatically stops the previous sensor before switching to the new one. |
What I mean is that as far as xDrip is concerned, there is only one active sensor at a time. |
Could this be a problem with backfilling?
Wenn we set (and therefore start) a new G7 while the old one has a few hours left?
Will xDrip backfill the data back til sensor start after connecting to it? Would we end up with double data?
…On 4 March 2024 19:34:26 CET, Navid ***@***.***> wrote:
Sorry. This sounds like a misunderstanding. There is no overlapping.
There is only one active sensor at a time.
You can do the exact same thing with a G6. xDrip automatically stops the previous sensor before switching to the new one.
G7 behavior is different in xDrip and I suspect (only suspect) it has to do with the fact that we cannot associate the Bluetooth name because Dexcom changed the naming convention with G7.
--
Reply to this email directly or view it on GitHub:
#3263 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
|
No, there is no problem with double data. You can test this with a G6. xDrip only backfills the missing data. |
Then we should be fine @jamorham
…On 4 March 2024 19:42:28 CET, Navid ***@***.***> wrote:
No, there is no problem with double data. You can test this with a G6. xDrip only backfills the missing data.
--
Reply to this email directly or view it on GitHub:
#3263 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
|
@jamorham The problem this PR is trying to resolve is a problem we have had since G6. May be even G5, but I am not sure. But, we cannot do that with G7. This may not solve the root cause of the second problem. There is a lot about G7 I am still trying to figure out. This PR fixes what is shown on the classic status page and sent to AAPS. And it does not break anything else. |
What I'm saying is if we adjust the start time of a sensor and this brings it back before the end of the previous sensor (which as far as I can see is not being checked here) then code which checks for glucose values that only reads data matching the current sensor can miss there being multiple readings for the same time period. What I am suggesting is that we don't rewrite the sensor start time earlier than the previous sensor stop time to avoid that potential problem. |
But, I want the sensor start time to be rewritten so that the start time reported to AAPS would be correct. I didn't think there was a chance xDrip would show two readings for one time. However, we have seen it happen occasionally. |
This would have to be in less than five minutes, not one. |
In case of G7 this would be bad, as no one would know when the sensor will stop exactly. |
We have devices that create a reading once every 5 minutes and we also have devices that create a reading once a minute. |
I just rebased this to make sure it does not have a conflict with the magic here: 24922b4 After that, I established connectivity to a newly started G7: And this shows the status page: And this shows the correct start time on the classic status page. I then switched to my old G7, which is still active. There is no overlap: These are the status pages after the switch showing the correct start time on the classic page. |
Please don't consider this PR to be something that solves all problems. The start time of the xDrip session had a significant importance when we used G5 because we could choose to use it in non-native mode. |
We can't set a transmitter's start time before the end time of a previous transmitter. Yes it would be better if we could do this but the de-duplication code is itself duplicated over different collectors and I believe is limited in its search to the current sensor session. Changing all of that could introduce other unintended consequences as well as duplicate data on the graph and there may be other places where it is assumed that the sensor sessions cannot overlap. It feels too risky to change. Instead I would suggest solving this issue by reporting what we think is the transmitter's version of the sensor start time to AAPS instead of xDrip's sensor start time because these are decoupled in the implementation at the moment because it is based on a model of how G4 worked. I think this can be done by looking at the |
Why are you concerned about different collectors. Would you please look at the following image? It shows that my G7 sensor started 26 days ago. It will also allow us to close this issue as well: #1632 as this is the only remaining discrepancy between the two status pages for a Firefly. It is possible I am misunderstanding you. What can go wrong for someone who is using a G7 or a G6 Firefly? |
@jamorham If the change this PR makes can possibly be a problem, we can remove the sensor start time from being shown on the classic status page for G7 and Firefly G6. |
For those of you interested in this fix, I have opened a new PR to address the latest raised concerns: #3414 If you can test it, please report in the PR. Please do not test anything that could compromise your diabetes control. |
The correct start time is now broadcasted for G7 after this: #3414 As far as the start time being shown incorrectly on the classic status page, we need to deal with that separately. What really needs to be fixed is getting xDrip to auto start. Sometimes, it doesn't. That will be very nice to fix. |
If you establish connectivity to a G6 session in progress, xDrip automatically starts an xDrip sensor session and gives it a start time of 3 hours prior to now.
You can confirm this by looking at the classic status page, where the xDrip sensor start time is shown.
If you then look at the G5/G6/G7 status page, you will see the start time reported by the transmitter as "Sensor status".
Those two are in agreement when xDrip is used to start the sensor.
As of the December 5, 2023 release, xDrip broadcasts the xDrip sensor start time to AAPS.
Therefore, the broadcast time is not perfectly accurate for those who use their t:slim pump or Dexcom receiver for starting their sensors.
This PR updates the xDrip sensor start time to match the time reported by the transmitter for G6 Firefly and G7.
As a result the issue reported below is also fixed by this PR.
Fixes: #3250