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.18k stars 142 forks source link

Activities analyze gives TypeError #163

Closed c2bull closed 1 year ago

c2bull commented 1 year ago

Describe the bug When performing an analyze a python error is thrown when parsing Activities:

TypeError: '<' not supported between instances of 'NoneType' and 'int'

To Reproduce Steps to reproduce the behavior:

This happens whenever the analyze flag is called: 1) Run the cli with garmindb_cli.py --all --analyze 2) View output 3) See error

Expected behavior Parsing the activity data should proceed without error.

Logs Screen capture:

$ /home/curtis/.local/bin/garmindb_cli.py --all --analyze Analyzing Data Summary Tables Generation: Traceback (most recent call last): File "/home/curtis/.local/bin/garmindb_cli.py", line 358, in main(sys.argv[1:]) File "/home/curtis/.local/bin/garmindb_cli.py", line 345, in main analyze_data(args.trace) File "/home/curtis/.local/bin/garmindb_cli.py", line 238, in analyze_data analyze.summary() File "/home/curtis/.local/lib/python3.10/site-packages/garmindb/analyze.py", line 192, in summary for year in sorted(list(set(Monitoring.get_years(self.garmin_mon_db) + Activities.get_years(self.garmin_act_db)))): TypeError: '<' not supported between instances of 'NoneType' and 'int'

Attaching garmindb.log: garmindb.log

Please run bugreport.sh and attach bugreport.zip. I do not have the bugreport.sh script on my system (locate bugreport.sh gives no answer)

Additional context I have uninstalled and re-installed garmindb via pip. When I first noticed the issue I moved the HealthData directory and re-ran everything as fresh, the issue still happened. I've rebuilt the db with garmindb_cli.py --rebuild_db, this error persists no matter what I do.

Happy to supply an activity file if that will help. Currently the FitFiles/Activities/ directory has 1228 files, of which 819 are json, 355 are .tcx, 11 are .gpx, 43 are .fit

As a test I moved the gpx and tcx files out of the Activities directory and re-ran the analyze (thinking maybe the XML brackets were an issue) and same TypeError happens on analyze)

tcgoetz commented 1 year ago

Please attach garmindb.log.

c2bull commented 1 year ago

Hi @tcgoetz - it was attached in the section marked "Attaching garmindb.log" (is that not visible to you? I can put on a web host elsewhere if need be)

https://github.com/tcgoetz/GarminDB/files/10098751/garmindb.log

tcgoetz commented 1 year ago

Can you also load up the monitoring table, sort it by timestamp, and see if there are any empty or bad timestamps?

tcgoetz commented 1 year ago

Sorry. My bad. I see it. Nothing interesting in garmindb.log

tcgoetz commented 1 year ago

Given that this line:

for year in sorted(list(set(Monitoring.get_years(self.garmin_mon_db) + Activities.get_years(self.garmin_act_db)))):

resulted in this error:

TypeError: '<' not supported between instances of 'NoneType' and 'int'

I think we need to be looking at the time column, which I think is timestamp for monitoring and start_time for activities, in the entries in the monitoring or activities table. I suspect bad or no data there.

c2bull commented 1 year ago

Sure, loading up $ sqlite3 DBs/garmin_monitoring.db

sqlite> select timestamp from monitoring where timestamp not like "20%";
sqlite> 

So it looks like none of the timestamps start with the bracket

tcgoetz commented 1 year ago

I wouldn't expect the timestamps to start with a bracket. Here is an example from my table "2022-08-01 23:59:59.000000". Do you have entries in both the "monitoring" and "activities" tables?

c2bull commented 1 year ago

I do have items in both

One thing that's strange is if I sort activities by timestamp desc I get a bunch of blank lines:

sqlite> select start_time from activities order by start_time desc;
2010-07-18 11:24:25.000000
2010-07-17 11:17:18.000000
2010-07-14 23:56:35.000000
2010-07-10 09:55:30.000000
2010-01-09 11:32:37.000000

However I cannot find any blanks in the table (doing a search for where timestamp = NULL or timestamp = " "

There are 7 entries however...:

sqlite> select count(*) from activities;
408
sqlite> select count(*) from activities where start_time like "20%";
401

Let me see if I can figure out what those are.

c2bull commented 1 year ago

This is interesting, I have some things that just don't have column values, I'm doing to delete them and see what happens.

||00:00:00.000000|00:00:00.000000|0.0||||||0|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|130900088|130900088||||1|Biking|||
||00:00:00.000000|00:00:00.000000|2.68304257476533||||||338|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|402045084|402045084||||2|Other|||
||00:00:00.000000|00:00:00.000000|2.68304257476533||||||338|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|402045087|402045087||||2|Other|||
||00:00:00.000000|00:00:00.000000|0.00294434468901408||||||0|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|668294373|668294373||||1|Running|||
||00:00:00.000000|00:00:00.000000|0.00294434468901408||||||0|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|668294374|668294374||||1|Running|||
||00:00:00.000000|00:00:00.000000|0.00294434468901408||||||0|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|668294377|668294377||||1|Running|||
||00:00:00.000000|00:00:00.000000|0.0||||||0|||||0.0|0.0||||||||||||||00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|00:00:00.000000|881132811|881132811||||1|Running|||
c2bull commented 1 year ago

That did it, I deleted those rows based on activity_id and now it's progressing just fine. Garmin must be hanging onto them somehow? I basically wiped the data and restarted from scratch and it still pulled those down.

Appreciate the app, and appreciate the help!

c2bull commented 1 year ago

Closing the issue as it turned out to be empty values in a timestamp column (if anyone is looking for the same issue in the future)