Suggestions
Bedtime and wakup-time variance and schedule adherence
Users can set a bedtime goal in Apple Health. Apple Health also shows bedtime and how earlier or later it is than your average.
I’d love to see what correlates with an earlier or later bedtime.
I realize there is no data type for this in HealthKit. I don’t know what Apple Health does to get this data. I can imagine it works something like this: • For each day, prefer to use either inBed (when available — not deprecated but no longer recorded by Apple devices, still used by lots of bed occupancy sensors, though) or fallback to using individual sleep stages. • Group any SleepAnalysis record (whether you’re using inBed or stages) that are within 60 min of each other into a “sleep cycle”. • When near midnight, allow for sleep to cross day boundaries into the previous evening. A sleep record belongs to the day where the majority of the sleep took place, to allow for different sleep schedules. • You should then have one or more sleep cycle groups per day (including naps). • Take the longest sleep cycle, and take its group’s first startDate (that’s your bedtime for that day) and the group’s last endDate (your wake-up time).
Once you have these times, they can be used in a few different ways: • How much off (less or more in mniutes) is the recorded sleep cycle’s duration from the HKDataTypeSleepDurationGoal? (Idealized goal.) https://developer.apple.com/documentation/relevancekit/relevantcontext/sleepcondition/bedtime • How much off (earlier or later in minutes) was today from your average bedtime and wake-up times? Consistency is key to good sleep.
Working out bedtime can help find correlations such as: • Medicine and symptoms to bedtime and wakeup times? • Alcohol and caffeine to bedtime? • Nightime temperature to bedtime? • Daytime temperature to wakeup time? • Dietary water to wakeup time?
RelevancyKit’s RelevantContext.SleepCondition.bedtime and wakeup might be … relevant here.