tcgoetz / GarminDB

Download and parse data from Garmin Connect or a Garmin watch, FitBit CSV, and MS Health CSV files into and analyze data in Sqlite serverless databases with Jupyter notebooks.
GNU General Public License v2.0
1.11k stars 137 forks source link

KeyError : 'day' error while importing using fitbit.py #108

Closed spelya closed 2 years ago

spelya commented 3 years ago

First of all, thanks for publishing your GHarminDb and plugins application. After just a few modifications on the defines.mk file, it works well on Windows 10 without WSL functionality. For the python newby I am, it is an excellent learning platform.

Here is my problem. I am trying to import two years of FitBit files in SQLite . I tested using the simplified 2 record csv file 2019-05.zip. The SQLite3 database is created without problem, but the process ends with "KeyError : day.

M:\Users...\GarminDB\venv\Scripts\python.exe M:/Users/.../GarminDB/fitbit.py Processing file: M:\Users...\HealthData\FitBitFiles/2019-05.csv

image

Your help would be appreciated.

tcgoetz commented 3 years ago

Your CSV file has avery different format than mine. Did you get it by using the "export your data" function?

Here's where the columns are mapped: https://github.com/tcgoetz/GarminDB/blob/e672b4d69a221854ab96690361e371bc21d796ca/import_fitbit_csv.py#L23

The first string in each line is a column name.

spelya commented 3 years ago

Hello Tom,

I double checked this morning, using Data Export for a custom period (2018-02-01 to 2018-02-28) in CSV format. A extract of the file is attached. There is also the possibility of export in XSLX format, where Body, Food, Activities, and Sleep data show a table format, one tab for each. Finally there a Export Your Account Archive option which yields multiple JSON files.

Regards,

Serge

De : Tom Goetz notifications@github.com Envoyé : lundi 22 février 2021 20:32 À : tcgoetz/GarminDB GarminDB@noreply.github.com Cc : spelya sp2ps@yahoo.ca; Author author@noreply.github.com Objet : Re: [tcgoetz/GarminDB] KeyError : 'day' error while importing using fitbit.py (#108)

Your CSV file has avery different format than mine. Did you get it by using the "export your data" function?

Here's where the columns are mapped: https://github.com/tcgoetz/GarminDB/blob/e672b4d69a221854ab96690361e371bc21d796ca/import_fitbit_csv.py#L23

The first string in each line is a column name.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tcgoetz/GarminDB/issues/108#issuecomment-783800699 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ANNLKSF2HQHLYMBPCK4WJ4LTAMASDANCNFSM4YA7DKCA .

spelya commented 3 years ago

It seems there is two versions of FitBit export file. As part of my learning curve, I would be interested to implement a method to reformat those files I get from FitBit to the format expected in the import_fitbit_csv.py and csv_importer.py. The method would be called before line 70 of import_fitbit_csv.py. Could you send me a sample csv file of your version so I could scratch my head on the solution ? Thanks

spelya commented 3 years ago

Hello Tom, To solve my problem with csv files of different format, I have created the attached AltFitBitFiles class fitbit_alt_file.zip which works as follow:

for each csv file downloaded to HealthData\FitBitFiles\Downloads split into one file for each table extracted from csv Identify table to retrieve and convert column names to match your col_map for 'Sleep' table, add a calculated date column for day of sleep save new category file using in_file name and category name

In order for fitbit.py to run with minimal modification, I only had to add an exception handling to CsvImporter.map_ymd_date(): except Exception: try: return datetime.datetime.strptime(date_string, "%%Y-%m-%d %I:%M%p").date() except Exception: return None I don't know how to submit my proposal to solve this issue, so I attached the code as a file.

Any comment would be greatly appreciated,

tcgoetz commented 3 years ago

I suggest you host the script your own GitHub project and we can link it from the wiki "Related Projects" page here: https://github.com/tcgoetz/GarminDB/wiki/Related-Projects