Skip to content

Commit b7e0110

Browse files
Update README.md
Updated SleepDataAutomation README to link to new repo.
1 parent 3af575e commit b7e0110

File tree

1 file changed

+5
-121
lines changed

1 file changed

+5
-121
lines changed

SleepDataAutomation/README.md

Lines changed: 5 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -2,128 +2,12 @@
22

33
# Sleep Data Automation
44

5-
## Description
6-
Automated sleep data cleanup and processing for Fitbit data obtained via Fitabase and self-reported sleep diary entries sent via SMS-to-Email. This project uses Microsoft Power Automate for processing sleep diary entries in a shared mailbox, and Excel / Power Query for loading and cleaning sleep stages and HRV data.
7-
8-
### What this automation does:
9-
+ Parse sms-to-email messages to get a list of sleep markers (self-reported sleep/wake times) into a spreadsheet
10-
+ Decipher the correct sleep/wake times based on sleep stages from Fitabase (because Fitbit includes time in bed before and after sleep sometimes)
11-
+ Identify the main sleep episode and filter out naps, based on configurable settings (longest duration, latest sleep episode, etc.)
12-
+ From that, get the correct total time asleep, time awake, time in bed, and other measures
13-
+ Use the calculated sleep/wake times to get the correct HRV values falling only inside that time window, and calculate averages for RMSSD/HF/LF
14-
+ Combine sleep stages, HRV and email markers (sleep diary)
15-
+ Optionally, adjust the sleep/wake up times based on self-reported times automatically when actual vs self-reported differ by a certain number of minutes
16-
+ Option to enter manual time adjustments in an override file, which will will override both Fitbit and self-reported times
17-
+ Present everything in a single sheet with one row per participant, per day, per sleep episode
18-
+ Show a weekly summary with a drop-down to select the study participant and the week
19-
20-
21-
![Sleep Data Automation Output Screenshot](https://github.com/DepressionCenter/MDEN/blob/1ba004e1297de82580cc98ec4852cec86e161ce1/SleepDataAutomation/SleepDataAutomation-Screenshot.png "Sleep Data Automation Output Example")
22-
23-
24-
![Sleep Data Automation Weekly Summary Screenshot](https://github.com/DepressionCenter/MDEN/blob/36693a1ad17f6e23ed9c0acc021958483dd025a2/SleepDataAutomation/SleepDataAutomation-WeeklySummary-Screenshot.png "Sleep Data Automation Weekly Summary Example")
25-
26-
27-
28-
## Quick Start Guide
29-
+ Download the Excel-PowerQuery directory
30-
+ Save your Fitbit, sleep markers, and sleep override files to the CSV directory
31-
+ Open CleanSleepData.xlsx, adjust the parameters in Power Query, and refresh all data
32-
+ To use sms-to-email sleep markers, import the Power Automate zip file into your Power Automate environment, adjust the mailbox name and output location for OneDrive, and create the needed directories in the mailbox
33-
34-
35-
36-
37-
## Documentation
38-
Documentation for this project is available at the Eisenberg Family Depression Center's [Knowledge Base](https://teamdynamix.umich.edu/TDClient/210/DepressionCenter/KB/ArticleDet?ID=11822).
39-
40-
### Detailed Setup
41-
+ Download the Excel-PowerQuery directory.
42-
+ Login to Fitabase, and create a "merged" export that includes 30-second sleep stages and 5-minute HRV. Be sure to click the "merge" checkbox so all participants are included in one file per measure.
43-
+ Download and unzip the export, and place the two CSV files in the Excel-PowerQuery\CSV sub-directory.
44-
+ Open CleanSleepData.xlsx in Excel. Alternatively, load CleanSleepData-PowerQuery.odc in PowerBI Desktop.
45-
+ In Excel, right-click on the data table and select Table -> Edit Query to open Power Query.
46-
+ Find the CSV-Directory parameter and enter your local path to the CSV sub-directory.
47-
+ Adjust the other optional parameters for automatically adjusting times based on sleep diary entries, how to identify main sleep vs naps, etc.
48-
+ Click Refresh Preview. If there are no errors, click File -> Save and Load.
49-
+ In Excel, under the Data ribbon, click Refresh All.
50-
+ The data table will now have a row for every participant, per day, with measures such as sleep start/end times, sleep duration, and average RMMSD / HF / LF.
51-
+ To use sleep markers, setup a shared mailbox to which participants can send an SMS/MMS message. Participants should send a text to that email address with the format "ParticipantID sleep" upon going to sleep, and "ParticipantID wake" upon waking up.
52-
+ In the shared mailbox, create two top-level folders called "Data-Processed" and "Data-Failed". Power Automate will automatically move emails to one of these folders after processing. Anything under Data-Failed will need to be processed manually.
53-
+ Login to OneDrive for Business (if you are a Michigan Medicine user, login using your level-2 credentials). Create a folder called EmailSleepMarkers or similar. In this project, we use a mailbox called "[email protected]" so the folder is called EmailSleepMarkers-SleepTimesMailbox. Upload the sample EmailSleepMakers.xlsx spreadsheet to this folder, and clear all rows except the headers.
54-
+ Login to [Power Automate](https://make.powerautomate.com) (if you are a Michigan Medicine user, login using your level-2 credentials). Go to My Flows -> Import -> Import Package (Legacy) and upload a copy of ParseMessagesInSleepTimesMailbox.zip (from the PowerAutomate\packages sub-dirctory). When prompted, enter your credentials to connect to OneDrive and Outlook.
55-
+ Once imported, edit the flow and change the shared mailbox email address in the 2nd step, under "Set Shared Mailbox Address Here." Then scroll down to the last step, and change the path to your EmailSleepMarkers.xlsx spreadsheet (saved to OneDrive) under the step titled "Add a row into a table."
56-
+ Enable the flow. By default it will run every 30 minutes and process 25 emails at a time. Do not run it more often than this to avoid being throttled by the Microsoft Graph API.
57-
+ Emails will be processed and saved to the spreadsheet in OneDrive. Once a week, copy the spreadsheet from OneDrive and place it in the CSV sub-directory. Refresh the data, and the sleep markers will show alongside the sleep and HRV data.
58-
59-
60-
61-
## Additional Resources
62-
+ Mobile Technologies KB Articles - [Code Documentation](https://teamdynamix.umich.edu/TDClient/210/DepressionCenter/KB/?CategoryID=847)
63-
64-
65-
66-
## About the Team
67-
The Mobile Technologies Core provides investigators across the University of Michigan the support and guidance needed to utilize mobile technologies and digital mental health measures in their studies. Experienced faculty and staff offer hands-on consultative services to researchers throughout the University – regardless of specialty or research focus.
68-
69-
70-
71-
## Contact
72-
To get in touch, contact the individual developers in the check-in history.
73-
74-
If you need assistance identifying a contact person, email the EFDC's Mobile Technologies Core at: [email protected].
75-
76-
77-
78-
## Credits
79-
#### Contributors:
80-
+ Eisenberg Family Depression Center [(@DepressionCenter)](https://github.com/DepressionCenter/)
81-
+ [Dr. Cathy Goldstein, M.D., M.S.](https://depressioncenter.org/become-member/our-members/cathygo)
82-
+ Gabriel Mongefranco [(@gabrielmongefranco)](https://github.com/gabrielmongefranco)
83-
+ [Sleep and Circadian Research Laboratory](https://medicine.umich.edu/dept/psychiatry/programs/sleep/sleep-circadian-research-laboratory)
84-
+ [Dr. Helen J. Burgess, Ph.D.](https://medicine.umich.edu/dept/psychiatry/helen-burgess-phd)
85-
+ [Moony Rizvydeen](https://www.linkedin.com/in/muneer-rizvydeen-b3b26254?original_referer=https%3A%2F%2Fdepressioncenter.org)
86-
+ [Zainab Fayyaz](https://mcommunity.umich.edu/person/fzainab)
87-
88-
89-
90-
#### This work is based in part on the following projects, libraries and/or studies:
91-
+ "IBD-Sleep: A Pilot Study Looking at Changes in Sleep Timing and IBD Symptoms." Principal investigator: [Helen J. Burgess, Ph.D.](https://medicine.umich.edu/dept/psychiatry/helen-burgess-phd)
92-
93-
94-
95-
## License
96-
### Copyright Notice
97-
Copyright © 2024 The Regents of the University of Michigan
98-
99-
100-
### Software and Library License
101-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
102-
103-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
104-
105-
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
106-
107-
108-
### Documentation License
109-
Permission is granted to copy, distribute and/or modify this document
110-
under the terms of the GNU Free Documentation License, Version 1.3
111-
or any later version published by the Free Software Foundation;
112-
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
113-
You should have received a copy of the license included in the section entitled "GNU
114-
Free Documentation License". If not, see <https://www.gnu.org/licenses/fdl-1.3-standalone.html>
115-
116-
117-
118-
## Citation
119-
If you find this repository, code or paper useful for your research, please cite it.
120-
121-
122-
*Eisenberg Family Depression Center, Mongefranco, Gabriel, et al. (2024). MDEN - Sleep Data Automation for Fitbit. University of Michigan. https://github.com/DepressionCenter/MDEN/SleepDataAutomation. https://doi.org/10.6084/M9.FIGSHARE.25438714*
123-
124-
*DOI: 10.6084/M9.FIGSHARE.25438714*
125-
5+
## **THIS CODE HAS MOVED TO A NEW REPOSITORY**
6+
For ease of maintenance, the Sleep Data Automation for Fitbit code has moved into its own repository at:
7+
[*https://github.com/DepressionCenter/SleepDataAutomation*](https://github.com/DepressionCenter/SleepDataAutomation)
1268

9+
10+
12711

12812
----
12913

0 commit comments

Comments
 (0)