Sleep graphs are inconsistent and have gaps(?)
#442
Open
opened 6 years ago by 6arms1leg
·
28 comments
No Branch/Tag Specified
nightly-branch
master
arjan5-testing-branch
fix_supported_unsupported_discovery
osmand-experiments
soflow_so6
remove-duplicated-empty-methods
nightly-changelog
huami-reserved-calendar-reminders
sony-fixes
sony-linkbuds-s
supercars_blinking
device-update-reason
discover-freeze-fix
device-flipper-zero
test_link
test_debug_release
debug-branch
fossil-hr-gen6
test_own_image
fix_logger_again
streaks
huami-sms-reply
RemoveMibandGlobalPreferences
SystemEvents
combined
openTracksObserver-debug
cycling_sensor
multi-device-support-clean-2
miband6-alipay
fossil-hr-activity-fix
fossil-q-hr-html
dakhnod/fix-notification-removed
dakhnod/beautify-device-information
Lightwars/TurnClocksForward
andyboeh/ble_reconnect_scan
ildar/patches/circleci
mvallerie/custom_menu_miband2
christian-n/master
lucasgaley/master
Dikay900/steps_diagram
comradekingu/patch-3
elagin/sleep_values_on_chart
boun/runnerup
thePanz/add-raw-data-support
plugdio/master
atx/master
Vebryn/csv-export
rosenpin/master
lazarosfs/EnableBtOnConnect
health-new-database
mi2-text-notifications
polarm400
release-0.11.x
led-profile
live-sensor-data
0.1.0
0.1.1
0.1.2
0.1.3
0.1.4
0.1.5
0.10.0
0.10.1
0.10.2
0.11.0
0.11.1
0.11.2
0.12.2
0.13.0
0.13.1
0.13.2
0.13.3
0.13.4
0.13.5
0.13.6
0.13.7
0.13.8
0.13.9
0.14.0
0.14.1
0.14.2
0.14.3
0.14.4
0.15.0
0.15.1
0.15.2
0.16.0
0.17.0
0.17.1
0.17.2
0.17.3
0.17.4
0.17.5
0.18.0
0.18.1
0.18.2
0.18.3
0.18.4
0.18.5
0.19.0
0.19.1
0.19.2
0.19.3
0.19.4
0.2.0
0.20.0
0.20.1
0.20.2
0.21.0
0.21.1
0.21.2
0.21.3
0.21.4
0.21.5
0.21.6
0.22.0
0.22.1
0.22.2
0.22.3
0.22.4
0.22.5
0.23.0
0.23.1
0.23.2
0.24.0
0.24.1
0.24.2
0.24.3
0.24.4
0.24.5
0.24.6
0.25.0
0.25.1
0.26.0
0.26.1
0.26.2
0.26.3
0.26.4
0.26.5
0.27.0
0.27.1
0.28.0
0.28.1
0.29.0
0.29.1
0.3.0
0.3.1
0.3.2
0.3.3
0.3.4
0.3.5
0.30.0
0.31.0
0.31.1
0.31.2
0.31.3
0.32.0
0.32.1
0.32.2
0.32.3
0.32.4
0.33.0
0.33.1
0.34.0
0.34.1
0.35.0
0.35.1
0.35.2
0.36.0
0.36.1
0.36.2
0.37.0
0.37.1
0.38.0
0.39.0
0.39.1
0.4.0
0.4.1
0.4.2
0.4.3
0.4.4
0.4.5
0.4.6
0.40.0
0.40.1
0.41.0
0.41.1
0.42.0
0.42.1
0.43.0
0.43.1
0.43.2
0.43.3
0.44.0
0.44.1
0.44.2
0.45.0
0.45.1
0.46.0
0.47.0
0.47.1
0.47.2
0.48.0
0.49.0
0.5.0
0.5.1
0.5.2
0.5.3
0.5.4
0.50.0
0.51.0
0.52.0
0.53.0
0.54.0
0.54.1
0.55.0
0.56.0
0.56.1
0.56.2
0.57.0
0.57.1
0.58.0
0.58.1
0.58.2
0.59.0
0.59.1
0.59.2
0.59.3
0.6.0
0.6.1
0.6.2
0.6.3
0.6.4
0.6.5
0.6.6
0.6.7
0.6.8
0.6.9
0.60.0
0.61.0
0.62.0
0.63.0
0.63.1
0.64.0
0.65.0
0.66.0
0.67.0
0.67.1
0.68.0
0.69.0
0.7.0
0.7.1
0.7.2
0.7.3
0.7.4
0.70.0
0.71.0
0.71.1
0.71.2
0.71.3
0.72.0
0.8.0
0.8.1
0.8.2
0.9.0
0.9.1
0.9.2
0.9.3
0.9.4
0.9.5
0.9.6
0.9.7
0.9.8
Labels
Mi Band 7 activity post processing
activity data processing, import, export activity/health Android 12 Android 13 android integrations architecture Bangle.js bug changes requested
the provided PR needs some modifications charts developer documentation
Information for contributors device amazfit band 5
Amazfit Band 5 device amazfit bip device amazfit cor device Casio device fossil device gtr 2e device gts 2 mini device h30 device hplus device Huawei
Huawei honor device liveview device mi band device mi band 2 device mi band 3 device mi band 4 device mi band 5
Mi Smart Band 5 device mi band 6
Mi Smart Band 6 device no.1 f1 device pace device pebble device pebble 2 device pinetime infinitime device request device sony
Sony device support device watch 9 discussion documentation duplicate enhancement feature request Gadgetbridge
Gadgetbridge good first issue
good entry level issue for new contributors help wanted i am developing my own app can you help
no, sorry icebox
An icebox for abandoned PRs. Feel free to pick it up, update and make a new PR internationalisation
metric/imperial/celsius/fahrentheit... invalid needs work network companion app
ideas pool for a network enabled companion app no feedback not a bug notifications
ideas and improvements for notifications one of the 1000 issues about disconnection pairing/connecting potentially fixed / confirm and close question research security seems abandoned
PR seems to abandoned Solved, waiting for F-Droid release suggest to close
probably should/could close task user interface / UX weather wontfix Zepp OS
Apply labels
Clear labels
device mi band 7
Mi Band 7 activity post processing
activity data processing, import, export activity/health Android 12 Android 13 android integrations architecture Bangle.js bug changes requested
the provided PR needs some modifications charts developer documentation
Information for contributors device amazfit band 5
Amazfit Band 5 device amazfit bip device amazfit cor device Casio device fossil device gtr 2e device gts 2 mini device h30 device hplus device Huawei
Huawei honor device liveview device mi band device mi band 2 device mi band 3 device mi band 4 device mi band 5
Mi Smart Band 5 device mi band 6
Mi Smart Band 6 device no.1 f1 device pace device pebble device pebble 2 device pinetime infinitime device request device sony
Sony device support device watch 9 discussion documentation duplicate enhancement feature request Gadgetbridge
Gadgetbridge good first issue
good entry level issue for new contributors help wanted i am developing my own app can you help
no, sorry icebox
An icebox for abandoned PRs. Feel free to pick it up, update and make a new PR internationalisation
metric/imperial/celsius/fahrentheit... invalid needs work network companion app
ideas pool for a network enabled companion app no feedback not a bug notifications
ideas and improvements for notifications one of the 1000 issues about disconnection pairing/connecting potentially fixed / confirm and close question research security seems abandoned
PR seems to abandoned Solved, waiting for F-Droid release suggest to close
probably should/could close task user interface / UX weather wontfix Zepp OS
No Label
device mi band 7
activity post processing
activity/health
Android 12
Android 13
android integrations
architecture
Bangle.js
bug
changes requested
charts
developer documentation
device amazfit band 5
device amazfit bip
device amazfit cor
device Casio
device fossil
device gtr 2e
device gts 2 mini
device h30
device hplus
device Huawei
device liveview
device mi band
device mi band 2
device mi band 3
device mi band 4
device mi band 5
device mi band 6
device no.1 f1
device pace
device pebble
device pebble 2
device pinetime infinitime
device request
device sony
device support
device watch 9
discussion
documentation
duplicate
enhancement
feature request
Gadgetbridge
good first issue
help wanted
i am developing my own app can you help
icebox
internationalisation
invalid
needs work
network companion app
no feedback
not a bug
notifications
one of the 1000 issues about disconnection
pairing/connecting
potentially fixed / confirm and close
question
research
security
seems abandoned
Solved, waiting for F-Droid release
suggest to close
task
user interface / UX
weather
wontfix
Zepp OS
Milestone
Set milestone
Clear milestone
No items
No Milestone
Assignees
Assign users
Clear assignees
No Assignees
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.
No due date set.
Dependencies
No dependencies set.
Reference: Freeyourgadget/Gadgetbridge#442
Reference in new issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
No
Yes
There are three things I noticed about the sleep activity graphs which I think are wrong(?):
I observed the above with my old Mi Band 1.
I guess we should make the labels of deep and light sleep user-configurable (SCNR ;-)).
We had those labels inverted previously, but some people reported that they were wrong and Mi Fit would report them the other way round, so we toggled the meaning, which is still how it is today.
We had a few problems when we ported to a major new version of the charting library, so it might be that there are still some regressions.
It may very well be that there is no activity data for a while though. If you want to share a gadgetbridge log from a day where this happens (together with a screenshot of the charts view), please do. I could check if the band didn't provide any data or if there's something wrong.
As always, many thanks for your support!
Here is a Gadgetbridge log and the corresponding screenshots of the sleep screen in Gadgetbridge (one with the bar graph zoomed to the whole sleep part only and one zoomed to a ~30min gap):
GB_Sleep_Issue-442.zip
The Mi Band 1's sleep detection is awful, as I went to bed at around 02:00am, but I guess that's a problem with the device itself, not Gadgetbridge.
Ah OK, I checked the log and the Mi Band 1 indeed reports an "intensity" of 0.0 for long periods of time that match the gaps of the bar graph in Gadgetbridge. So Gadgetbridge just displays them as gaps in the bar graph but actually takes them into account for the sleep pie chart.
If that's the case, both graphs are consistent – just the representation with gaps in the bar graph is confusing (maybe it would be better to distinguish between "no data" and "0.0 intensity"? BTW, why isn't the latter interpreted as "Not Worn"?)
This renders points two and three of the initial issue post obsolete, with only the first question remaining.
Thanks for the log and screenshots!
The whole recognition of deep sleep and light sleep with a simple band is a bit like black magic (or charlatanry, if you prefer ;-))
Have a look at the wikipedia articles for example
https://en.wikipedia.org/wiki/Rapid_eye_movement_sleep
https://en.wikipedia.org/wiki/Non-rapid_eye_movement_sleep
The former (REM) sleep includes paralysis of the body, so this should correlate with (very) little intensity values.
The latter (NREM) does not include paralysis, and is characterized as "deep sleep", at least in stages 3/4.
This might explain low intensity values during light sleep and higher intensity values during deep sleep.
I'm sure there is room for improvement in how we display sleep and activity. Ideas and suggestions welcome :-)
RE: 0.0 intensity value vs "not worn": there are probably different ways for the band to distinguish them, one of them being the heartrate measurements.
@cpfeiffer
I think in common language when someone is in "deep sleep" he looks like a rock. No one would say he is in deep sleep because he is moving.
To avoid the confusion, if you think some band might be capable of detecting NREM stages 3/4 which I doubt, we shoud use the terms "restful sleep" and "sleep" or something
@ashimokawa agree.
I believe there's more logic involved on the app side than just counting the light sleep/deep sleep epochs:
https://github.com/Freeyourgadget/Gadgetbridge/issues/250#issuecomment-233173323
@ashimokawa definitions.net has "deep sleep" as "Artificially induced hibernation in humans for the purpose of long distance space travel." So that's what I do half of the night? 👽 😝
@cpfeiffer Not sure how detailed the data from different devices are. Do they just have "markers" for deep vs light sleep – or allow for more/all phases? In the latter case, maybe GB should offer a hypnogram instead of that circle?
@ashimokawa My naive understanding of deep sleep is that the deeper your sleep is, the harder it is to get you to wake up, and the more disoriented you are.
German Wikipedia says similar things.
I never said that you'd be in deep sleep when you move 😀
What I meant was that deep sleep does not mean "no movement". I contrast, some other, non-deep-sleep phases are related to "no movement". Hence, the intensity values actually correlate to this.
@rplevka Totally agree. do you want to join us in finding an appropriate algorithm?
@IzzySoft AFAIK there's no further classification. I doubt these could be accurately calculated from such devices anyway.
@cpfeiffer yes, thought so.
Btw: regression. Just updated to 0.14.4, and my sleep graphs are gone again. At least those for the last night; funnily the ones from the night before are still there. Guess I have to wait for 0.14.5 to bring them back (same happend with 0.14.2, where 0.14.3 brought them back)... And yes, I was wearing the watch, and it was connected all day long.
Izzy you should try installing the ocean survey pebble app and trigger a sync (it's enough to enter and leave the ocean survey app).
The fact that pebble sends activity data (or not) and when it's not something we can influence. Same for the GB version it has no influence: it just happens that we release often and things seem to be related.
@danielegobbetti any pointer as where to find that, so I can give it a try? My Google-Fu just picked up links to the SDK (not being a dev, I have no dev env setup and thus cannot compile that), but no installable
.pbw
or the like. If nowhere public, a mail is welcome as well :)@cpfeiffer,
sure, I'll do my best
@danielegobbetti regression solved, partly. Last night's data did show up and looks alright, but the night before is rather lost (just showed ~1h deep sleep, nothing else – and I know I've slept more than that). Nevermind, I guess that's why it's still labeled "Alpha", right? 😝
Nevertheless: I'd still welcome that watch app you've mentioned. Step on my toe if it's attached somewhere in the Wiki and I've just been too blind to see it 🙀
@cpfeiffer - regarding the gaps -
isn't there one more (or even more) activity code we don't recognize? perhaps there's one more counting to deep sleep or a light sleep(i've read some articles about light/deep sleep and learned that NREM consists of 3 stages).I've compared the chart with the actual data exported and browsed using sqlite browser and found out the gaps are actually bars of deep sleep with intensity: 0. So it only looks like a gap. Perhaps there could be some minimum height for a bar so it doesn't look like a gap too much? Or, set the color of the whole cell (on entire Y-axis) for that time epoch, same as the official app does (with e.g. white bar in the foreground to visualize the intensity)
Also, I've found that the code assigns 2 activitiy types to the same code (was that intentional?):
https://github.com/Freeyourgadget/Gadgetbridge/issues/450
..looks to me like the ACTIVITY was supposed to be bound to no. 1, not -1
Yes, the bar height is intensity. We actually had a minimum height some time ago... maybe that was lost at some point. I think that the visualization itself could be improved, though. E.g. by giving all bars the full height and adding the intensity as a line chart overlay. Not sure if that would be better, would need to try or have a mockup. Further suggestions welcome :-)
Regarding activity types, good question, I don't have an answer to at the moment. Needs some digging through git logs, which Android Studio is not so good at.
Last night I got a call and had to work starting at 12:30 AM until about 2:30 AM. When I downloaded the data from my MiBand1S this morning, here is what I saw (apparently I was Deep Sleeping through work!):
Deep and Light really are reversed.
@gadgetguy08 Please check your call history. Maybe you just had a bad dream 😜 But yes, in that case there should be some "light sleep" to account for dreaming, right?
No update in more than 2 years: can we consider this solved, and close the issue – or is anything left to do first?
Dark blue lines on my device (mi-band 1s) still indicate activity/motion and correspond to my being awake in bed, but still get designated as 'deep sleep'. So it continues to provide inaccurate results.
Thanks for the update, @gadgetguy08 – and apologies for a solution still not being available. For the records: Using a Pebble time Steel, I can confirm "gaps" in so far that I've never seen time frames marked "not worn" – though of course I cannot wear my PTS while it's charging.
The core team is somewhat "reduced" currently, so unfortunately it won't be fixed overnight 😢
I'd see the issue of "not worn" time periods embedded in sleep periods also strongly related to this issue. My sleep plots look weird, because GB kinda claims that my Mi band gets lost and reattached during night without me waking up, see attached screenshot.
To my understanding it is obvious here that the band was worn and the embedded "notworn" period should be added in the overall sleep time.
I guess the heart rate data gathered during these "not worn" times are just interpolated (which I think should not be done for any period longer than a few minutes).
BTW: using a Mi Band 3 (FW: 2.4.0.32 on HW V0.23.18.49) with Gadgetbridge 0.47.2 from fDroid, running on Lineage 17 (Android 10).
My plot looks somewhat similar to this previously reported issue: #1856
I can't see that from the graph. I think for the same reason the band can't either. How are you wearing the band?
I wear the band relatively tight, but also tried to vary this as users have raised the question here whether this could have an effect. For me it didn't.
For illustrating what I mean with an "obviously impossible not-worn period" in the given plot let me add a screenshot of the same time in the activity plot mode, zooming a bit in:

GB concludes that (in the middle of the night!), the state changes from light sleep to notworn and then to deep sleep. With such a sequency of state transitions at that time of the day, I'd propose to have this changed by means of some plausibility correction.
As mentioned before, the heart rate in that notworn phase is obviously only interpolated, by zooming into the HR plot it looks very much like a polynomial of 3rd order connecting the ends of the neighbouring data periods. Unless GB is doing this somewhere, the band must have done the interpolation itself.
Nonono, that's Mi Band itself.
I don't see any sense adding comments to many issues all around the bugtracker here, there is limited number of people who will read them and respond...
Anyhow, i think i see what @TaaviE sees as well:
Before and after the "not worn" period, there is an activity (indicated as
intensity
on the band). I can imagine, that what the band sees is the following:As i mentioned before - they switched to postprocessing the data, because as you can see, the logic can be flawed. There have been attempts to do the same, but it is actually difficult for many reasons.
This is my view, but i can be wrong of course.
The only reasonable solution to me seems to be manual adjustment option. This is a topic for an another single issue.
As the interpolation curve shape is only hard to see in the previous plot, let me give a zoomed example from another day, seeing most of the night as not-worn phases (the sleep plot concluding far-off that I slept less than 4hrs that night), intermitting with sleep phases, and the heart rate plot interval curve looking like cubic polynomial interpolation:
https://codeberg.org/Freeyourgadget/Gadgetbridge/src/branch/master/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java#L620
https://codeberg.org/Freeyourgadget/Gadgetbridge/src/branch/master/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java#L472
I agree that approaches for sorting out these implausible states are worth an issue of its own. Having some hope that using some data smoothing plus restricting the acceptable state transitions might make an improvement possible without any manual editing, but could end up in the UI as just a config checkbox like "use experimental data filtering", I will try to play a bite with the raw data from the exported sqlite database, hopefully arriving at something helpful.