Documentation and code for manipulating sleep diaries
There is no formal definition for a spreadsheet table, but people often independently create sleep diaries containing a table of values. This format attempts to parse those tables based on common features.
You may find the following useful:
Spreadsheet tables are usually created in Microsoft Excel or LibreOffice Calc. The user puts headings in the first row, then adds a new row each day.
The most common raw format for spreadsheets is Office Open XML, followed by OpenDocument. These formats have been published as international standards, and developers are encouraged to use a library to manipulate them.
Spreadsheet tables generally have the following properties:
Here is a process to detect which column contains the start time:
/sleep|start|begin/i
, the first matching column indicates the start time/wake|stop|end/i
indicates the start timeHere is a process to detect which column contains the end time:
/wake|stop|end/i
, the first matching column indicates the end time/sleep|start|begin/i
indicates the end timeHere is a process to detect which column contains the status:
/event|activity|stat(e|us)/i
, the first matching column indicates the statusasleep
Here is a process to detect which columns contains comments:
/comment|note/i
, the all matching columns indicate the commentThe precise process used by the JavaScript code is more complex than the above. For example, it handles the case where a user specifies the full date in some columns, but only the time in others.
Here is a process to convert status strings to values:
/sleep/i
indicate the user is asleep/wake/i
indicate the user is awake/snack/i
indicate the user is eating a snack/meal|eat/i
but not /snack/i
indicate the user is eating a meal/alco/i
indicate the user is drinking an alcoholic drink/caffeine|coffee|tea|cola/i
indicate the user is drinking a caffeinated drink/choc/i
and /drink/i
indicate the user is drinking a chocolate drink/drink/i
but none of the above indicate the user is drinking something that is neither alcoholic, caffeniated nor chocolate/pill|tranq/i
indicate the user is taking a sleeping pill or tranquiliser/exercise/i
indicate the user is exercising/toilet|bathroom|loo/i
indicate the user is using the toilet/noise/i
indicate the user’s sleep has been disturbed by noise/alarm/i
indicate an alarm is occurring/down|(in|to).*bed/i
indicate the user is going to bed/up|out.*bed/
indicate the user is getting out of bed