Welcome to Apnea Board !
As a guest, you are limited to certain areas of the board and there are some features you can't use.
To post a message, you must create a free account using a valid email address.
Login or Create an Account
04-08-2024, 05:18 AM (This post was last modified: 04-08-2024, 05:21 AM by ExtremeDeepSleep.)
Fitbit import to OSCAR
Hello everyone,
Let me share a little bit about myself first. My apnea treatment started with a blast, but after adjusting my settings I couldn't get as good sleep as during my first night with CPAP. Since my AHI was all ok, I started to look into O2 saturation monitoring.
I have tried O2 Ring, but after it's battery didn't last even 2h during my sleep I developed distrust on Viatom suppliers in my country. My doctor suggested that I don't need very accurate device right now, so I should take a look into some kind of fitband. That was exactly what I did and I find some youtube channel that suggested that fitbit has pretty accurate sleep phases detection. Since I couldn't find any data about SpO2 accuracy, this information along with ability to export data through Google Takeout made me buy Fitbit Inspire 3.
I have made an account here specifically to share with you my python script, that I have worked on last week to transform Fitbit data into Viatom SpO2+HR and Dreem sleep phases files. Now with all data in OSCAR I find it easier to adjust my CPAP settings. Maybe someone will find it useful, I have shared it on my gDrive: https://drive.google.com/file/d/12bb0a_nW6s0hrm2cIdUw5FuvZW-SLT17/view?usp=drive_link
Since I am a C++ programmer myself, would you accept change that adds Fitbit import directly in OSCAR? For my use it is easier to use script than OSCAR fork, but it there is a possibility that it would go into official release, then it is worth an effort
The OSCAR Team is always looking for additions. Please feel free to submit new code. Since I don't have the administrative rights to add you as contributor to the code, please email or PM me regarding your submission. The code is configured to compile with Qt v5.15.
INFORMATION ON APNEA BOARD FORUMS OR ON APNEABOARD.COM SHOULD NOT BE CONSIDERED AS MEDICAL ADVICE. ALWAYS SEEK THE ADVICE OF A PHYSICIAN BEFORE SEEKING TREATMENT FOR MEDICAL CONDITIONS, INCLUDING SLEEP APNEA. INFORMATION POSTED ON THE APNEA BOARD WEB SITE AND FORUMS ARE PERSONAL OPINION ONLY AND NOT NECESSARILY A STATEMENT OF FACT.
If you login to fitbit with google account, you can use https://takeout.google.com/ to export your raw data. Click "Deselect all" and check "Fitbit data" and you can download it or add to cloud (gDrive, Dropbox, OneDrive or Box). It says it could take hours, but for me it is usually 1-2 minutes if I only export Fitbit.
I am not sure how data is structured if downloaded from Fitbit account (but I think it is possible to download as well).
Once downloaded and extracted you can use script to convert data to Dreem CSV (sleep phases) and Viatom binary files (SpO2 and heart rate). You need to install python for that and execute script from console giving folder with data as and argument (it will be named like this: takeout-20240407T093621Z-001 and it will contain Takeout/Fitbit directory with data).
If you are on Windows you can have drag&drop and avoid executing from console. Use this scripts https ://drive.google.com/file/d/1o4Nv5Bs0HdBnmxVs9HLCdhuWAIBxBjeC/view?usp=sharing - archive contains two files: fitbit_convert.bat and fitbit_convert.py. Those two needs to be in same directory.
Now just drag takeout directory on fitbit_convert.bat and it should convert data for you. I attach screenshot of my output to give you a reference.
PS. In this new link I updated script to not use any additional python packages. Original script requires additional pytz package and installing it requires some technical knowledge.
PPS. Because of Viatom file format, script will not generate spo2 file if heart rate data is incomplete. I noticed that google attaches detailed heart rate data for each finished day, so your latest sleep will lack of heart rate data. Therefore only sleep phases will be visible for that day.
Thanks for this script, it works well.
I did have to add an extra check for the export sleep function:
if (item["type"] != "stages"):
continue
Perhaps this is only a pixel watch feature, but it has other types of sleep records that are 'mainsleep=false', 'type=classic' and a different set of levels:
I ran into some issues running the script myself, so I saved and edited it to patch an issue with the sleep phase processing, and then extended it further to meet needed feature functionality -- optional start/end dates (it was processing many years of data and taking several minutes just to get to an error message), export path instead of current directory, and some code revisions such as stripping the FitbitData class. The class was not storing any Fitbit data itself, and was only utilized once.
I hope this can be helpful! I have it on GitHub and on Codeberg for choice of submitting any issues or improvements as well! I'm sure I've gotten something a little goofy when trying to be lenient with date ranges.
a big thank you from me to the guys here making it possible to import FitBit Data into Oscar.
With the latest GitHub Version from KayOhtie i was able to import the data just fine.
Just a small comsmetic note: if you leave the opional -v parameter out of the command line the python script crashes.
Code:
Traceback (most recent call last):
File "D:\fc.py", line 362, in <module>
'level': get_verbosity(args.verbosity),
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "D:\fc.py", line 326, in get_verbosity
if x >= 2:
^^^^^^
TypeError: '>=' not supported between instances of 'NoneType' and 'int'