Hello Guest, 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.

or Create an Account


New Posts   Today's Posts

Fitbit import to OSCAR
#1
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 Wink


Attached Files Thumbnail(s)
   
Post Reply Post Reply
#2
RE: Fitbit import to OSCAR
Hi ExtremeDeepSleep !  -  Welcome

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.  

- Red
Crimson Nape
Apnea Board Moderator
Project Manager for OSCAR - Open Source CPAP Analysis Reporter
www.ApneaBoard.com
___________________________________
Useful Links -or- When All Else Fails:
The Guide to Understanding OSCAR
OSCAR Chart Organization
Attaching Images and Files on Apnea Board
Apnea Helpful Tips

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.
Post Reply Post Reply
#3
RE: Fitbit import to OSCAR
Thanks Red!
When I'll get something useful I'll let you know Smile
Post Reply Post Reply
#4
RE: Fitbit import to OSCAR
I have have a fitbit also.
How do you get the the chart data from the fitbit to the PC.
LoudSnorer
Post Reply Post Reply
#5
RE: Fitbit import to OSCAR
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.


Attached Files Thumbnail(s)
   
Post Reply Post Reply
#6
RE: Fitbit import to OSCAR
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:

"data" : [{
"dateTime" : "2024-04-10T05:57:30.000",
"level" : "asleep",
"seconds" : 3660
},{
"dateTime" : "2024-04-10T06:58:30.000",
"level" : "awake",
"seconds" : 60
},{
"dateTime" : "2024-04-10T06:59:30.000",
"level" : "restless",
"seconds" : 120
},{
"dateTime" : "2024-04-10T07:01:30.000",
"level" : "asleep",
"seconds" : 180
},{
Post Reply Post Reply
#7
RE: Fitbit import to OSCAR
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.

Links:
  • https://github.com/KayOhtie/fitbit-oscar-convert
  • https://codeberg.org/KayOhtie/fitbit-oscar-convert
Post Reply Post Reply
#8
RE: Fitbit import to OSCAR
Hello,

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'


This can be easily fixed by replacing:
Code:
   parser.add_argument("-v", "--verbosity",
       action="count",
       help="increase output verbosity")

with:
Code:
   parser.add_argument("-v", "--verbosity",
       action="count",
       help="increase output verbosity", default=0)

Regards
Post Reply Post Reply
#9
RE: Fitbit import to OSCAR
Oops, I thought that was working without! I've got it fixed now! Thank you!
Post Reply Post Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Question OSCAR does not import data - "failed to parse identification file" thearrow3456 3 276 01-06-2025, 12:14 AM
Last Post: thearrow3456
  Oscar Crash to desktop on SP02 import WallyPepper 11 1,120 01-05-2025, 12:12 PM
Last Post: Crimson Nape
  OSCAR: Questions regarding a potential import for Garmin data littleyoda 10 873 12-29-2024, 06:45 AM
Last Post: bedeee
Sad No more data import from prisma smart since1984 8 475 12-13-2024, 07:47 AM
Last Post: since1984
  OSCAR import from other oscar computer Olivier France 10330 0 181 12-10-2024, 01:19 PM
Last Post: Olivier France 10330
  O2 import DST > ST 1:14am happened twice dgconder 5 386 11-03-2024, 08:55 PM
Last Post: dgconder
  Trouble understanding how to import O2 ring info into Oscar katbrat 6 660 10-26-2024, 08:25 PM
Last Post: katbrat


New Posts   Today's Posts


About Apnea Board

Apnea Board is an educational web site designed to empower Sleep Apnea patients.