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

___Analyzing Data___ TypeError: '<' not supported between instances of 'int' and 'NoneType' #234

Open ItzFender opened 4 months ago

ItzFender commented 4 months ago

GarminDB version: 3.6.0 Python version: 3.12.4

Command: garmindb_cli.py --all --download --import --analyze --latest

<- Downloads data Removed for brevity ->

Error:

___Analyzing Data___
Summary Tables Generation:
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python312\Scripts\garmindb_cli.py", line 368, in <module>
    main(sys.argv[1:])
  File "C:\Users\username\AppData\Local\Programs\Python\Python312\Scripts\garmindb_cli.py", line 355, in main
    analyze_data(args.trace)
  File "C:\Users\username\AppData\Local\Programs\Python\Python312\Scripts\garmindb_cli.py", line 248, in analyze_data
    analyze.summary()
  File "C:\Users\username\AppData\Local\Programs\Python\Python312\Lib\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 'int' and 'NoneType'
ItzFender commented 4 months ago

I ended up finding issue #163 which pointed me in the right direction.

I had 16 rows in my activities table that were completely blank.

View: select start_time from activities where start_time IS NULL;

Delete: DELETE from activities WHERE start_time IS NULL;

I don't have a lot of experience with python so I may be way off base, but could you filter out null or empty datetimes in the get_years() method/function?

tcgoetz commented 1 day ago

It should:

@classmethod def get_years(cls, db): """Return a list of the unique years present in the time column.""" with db.managed_session() as session: return cls._rows_to_ints_not_none(session.query(extract('year', cls.time_col)).distinct().all())

_rows_to_ints_not_none should do that. It needs some debugging to see why it isn't working as intended.