Hi, in our app we want to calculate a daily sleep from healthkit data and display it on a graph similar to apple health. but the sleep data that we are getting merged a data for consecutive days. how can we calculate the daily sleep data based on the healthkit sleep data? how does apple health calculate the daily sleep data?
Calculate daily steep from healthkit data
I'm not sure exactly what you mean by "merging data for consecutive days" but I suspect you're querying for "what is the total amount of sleep time in this calendar day" which will include data from both the night you care about but also the morning corresponding to the night before and that's what you mean by merged. You'll likely want to query a little differently. For example, instead of bucketing by a midnight to midnight day, bucket by a 6pm - 6pm bounded day. Or apply some other type of processing to determine which "actual" day sleep data belongs to.