Skip to content

Commit

Permalink
Issue #257: handle field cycles_to_calories being not present in moni…
Browse files Browse the repository at this point in the history
…toring_info
  • Loading branch information
tcgoetz committed Jan 13, 2025
1 parent 3e9a4ac commit 1ebd5bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 8 additions & 3 deletions garmindb/monitoring_fit_file_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def write_file(self, fit_file):
def _plugin_dispatch(self, handler_name, *args, **kwargs):
return super()._plugin_dispatch(self.monitoring_fit_file_plugins, handler_name, *args, **kwargs)

@classmethod
def __unpack_tuple(cls, entry, name, value, index):
if type(value) is tuple:
entry[name] = value[index]

def _write_monitoring_info_entry(self, fit_file, message_fields):
activity_types = message_fields.activity_type
if isinstance(activity_types, list):
Expand All @@ -46,10 +51,10 @@ def _write_monitoring_info_entry(self, fit_file, message_fields):
'file_id' : File.s_get_id(self.garmin_db_session, fit_file.filename),
'timestamp' : message_fields.local_timestamp,
'activity_type' : activity_type,
'resting_metabolic_rate' : message_fields.get('resting_metabolic_rate'),
'cycles_to_distance' : message_fields.cycles_to_distance[index],
'cycles_to_calories' : message_fields.cycles_to_calories[index]
'resting_metabolic_rate' : message_fields.get('resting_metabolic_rate')
}
self.__unpack_tuple(entry, 'cycles_to_distance', message_fields.cycles_to_distance, index)
self.__unpack_tuple(entry, 'cycles_to_calories', message_fields.cycles_to_calories, index)
MonitoringInfo.s_insert_or_update(self.garmin_mon_db_session, entry)

def _write_monitoring_entry(self, fit_file, message_fields):
Expand Down
1 change: 0 additions & 1 deletion test/test_files/fit/monitoring/readme.txt

This file was deleted.

8 changes: 4 additions & 4 deletions test/test_fit_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
logger = logging.getLogger(__name__)


test_activity_files = True
test_activity_files = False
test_monitoring_files = True
test_sleep_files = True
test_metrics_files = True
test_unknown_files = True
test_sleep_files = False
test_metrics_files = False
test_unknown_files = False


class TestFitFile(unittest.TestCase):
Expand Down

0 comments on commit 1ebd5bf

Please sign in to comment.