Context
Sleep is one of the best forms of recovery from physical and mental stressors (Bird, S. 2013. Sleep, Recovery, and Athletic Performance, Strength and Conditioning Journal. doi: 10.1519/SSC.0b013e3182a62e2f). Healthy adults should be aiming to get 7-9 hours of sleep per night but people with more active days (e.g. athletes, soldiers, dancers) may require longer. Sleep duration can be a useful tool to track recovery and wellbeing.
There are multiple ways to collect sleep data in Smartabase. It could be as simple as providing a field to record how many hours of sleep they got the previous night or you could collect bed and wake times to calculate sleep duration. This tutorial will use time fields, time difference calculations and basic calculations to determine sleep duration based on bed and wake times. The benefit of this method is that you can also monitor and track changes in bed and wake times.
Goals
This tutorial will take you through the steps to capture bed and wake times and calculate sleep duration. Note that bed and wake times will be recorded to the nearest 15 minute interval.
Outcomes
- Use time fields to capture bed and wake times.
- Use time difference calculations and simple calculations to calculate sleep duration.
Outcome 1: Set up fields to capture bed and wake times
- Open an existing or new event form where you want to record sleep.
- Add two time fields and name them Bed time and Wake time. Set both fields to Default to Last Value.
Outcome 2: Use calculations to determine sleep duration
- Add a time difference calculation to determine the hours between bed time and wake time. In the advanced field properties, set the field to be hidden using the Visibility setting. Also set the from time and to time settings to Bed time and Wake time respectively, and set the Time display units to minutes.
- Add a calculation to calculate the sleep duration as a positive number (if bed time was earlier than 12:00pm).
if(contains(Bed time, "PM"), 1440 - (-1 * Time calculation) / 60, Time calculation) / 60
Where Bed time refers to the name of the bed time field and Time calculation refers to the name of the time difference calculation. Set the field advanced properties and set the number format to 1 decimal place. - The resulting value will be the sleep duration in hours.
Test your workflow
Since this workflow does not rely on records being saved, you can test it on the builder site using Preview mode.