Skip to content

Commit

Permalink
merge from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tcgoetz committed Jan 13, 2025
2 parents c727542 + 1ebd5bf commit 5c8bdcf
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
Expand Down
2 changes: 1 addition & 1 deletion Fit
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
2 changes: 1 addition & 1 deletion garmindb/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
python_required = (3, 0, 0)
dev_python_required = (3, 9, 0)
python_tested = (3, 11, 4)
version_info = (3, 6, 2)
version_info = (3, 6, 3)
prerelease = False


Expand Down
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ sqlalchemy~=2.0.32
python-dateutil
cached-property
tqdm
garth>=0.4.47
fitfile>=1.1.8
garth>=0.5.2
fitfile>=1.1.9
tcxfile>=1.0.4
idbutils>=1.1.0
# security fixes
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ SQLAlchemy==2.0.36
python-dateutil==2.9.0.post0
cached-property==1.5.2
tqdm==4.66.5
garth==0.4.47
fitfile>=1.1.8
garth==0.5.2
fitfile>=1.1.9
tcxfile>=1.0.4
idbutils>=1.1.0
# security fixes
Expand Down
50 changes: 34 additions & 16 deletions scripts/garmindb_bug_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,49 @@
import logging
import subprocess
import zipfile
import os
import os.path
import argparse


logging.basicConfig(filename='bugreport.log', filemode='w', level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(stream=sys.stdout))


with open('bugreport.txt', 'w') as report:
report.write(f"sys.version: {sys.version}\n")
report.write(f"sys.platform: {sys.platform}\n")
report.write(f"platform.system(): {platform.system()}\n")
report.write(f"sysconfig.get_platform(): {sysconfig.get_platform()}\n")
report.write(f"platform.machine(): {platform.machine()}\n")
report.write(f"platform.architecture(): {platform.architecture()}\n\n")
def main(argv):
"""Run a data checkup of the user's choice."""
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dir", help="Directory where Garmindb scripts were run", required=True)
args = parser.parse_args()

output = subprocess.check_output([sys.executable, '-m', 'pip', 'show', 'garmindb'])
report.write(output.decode())
bug_report_txt = args.dir + os.sep + 'bugreport.txt'

requirements_files = ["requirements.txt", 'Fit/requirements.txt' 'utilities/requirements.txt', 'tcx/requirements.txt']
with open(bug_report_txt, 'w') as report:
report.write(f"sys.version: {sys.version}\n")
report.write(f"sys.platform: {sys.platform}\n")
report.write(f"platform.system(): {platform.system()}\n")
report.write(f"sysconfig.get_platform(): {sysconfig.get_platform()}\n")
report.write(f"platform.machine(): {platform.machine()}\n")
report.write(f"platform.architecture(): {platform.architecture()}\n\n")

for requirements_file in requirements_files:
report.write(f'\nrequirements {requirements_file}\n\n')
output = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze', requirements_file])
output = subprocess.check_output([sys.executable, '-m', 'pip', 'show', 'garmindb'])
report.write(output.decode())

with zipfile.ZipFile('bugreport.zip', 'w') as zip:
zip.write('bugreport.txt')
zip.write('garmindb.log')
requirements_files = ["requirements.txt", 'Fit/requirements.txt' 'utilities/requirements.txt', 'tcx/requirements.txt']

for requirements_file in requirements_files:
requirements_file_path = args.dir + os.sep + requirements_file
report.write(f'\nrequirements {requirements_file_path}\n\n')
output = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze', requirements_file_path])
report.write(output.decode())

with zipfile.ZipFile(args.dir + os.sep + 'bugreport.zip', 'w') as zip:
zip.write(bug_report_txt)
garmindb_log = args.dir + os.sep + 'garmindb.log'
if os.path.isfile(garmindb_log):
zip.write(garmindb_log)


if __name__ == "__main__":
main(sys.argv[1:])
1 change: 1 addition & 0 deletions test/test_files/fit/activity/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Any FIT activity files placed in this directory will be tested by 'make test'.
1 change: 0 additions & 1 deletion test/test_files/fit/monitoring/readme.txt

This file was deleted.

1 change: 1 addition & 0 deletions test/test_files/fit/sleep/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Any FIT sleep files placed in this directory will be tested by 'make test'.
1 change: 1 addition & 0 deletions test/test_files/fit/unknown/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Any FIT files placed in this directory will be tested by 'make test'.
43 changes: 29 additions & 14 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 Expand Up @@ -212,38 +212,53 @@ def check_unknown_file(self, filename):
def test_parse_monitoring(self):
monitoring_path = self.file_path + '/monitoring'
file_names = FileProcessor.dir_to_files(monitoring_path, fitfile.file.name_regex, False)
for file_name in file_names:
self.check_monitoring_file(file_name)
if len(file_names) > 0:
for file_name in file_names:
self.check_monitoring_file(file_name)
else:
logger.error("Add test files to %s", activity_path)

@unittest.skipIf(not test_activity_files, 'Test not selected')
def test_parse_activity(self):
activity_path = self.file_path + '/activity'
file_names = FileProcessor.dir_to_files(activity_path, fitfile.file.name_regex, False)
for file_name in file_names:
self.check_activity_file(file_name)
if len(file_names) > 0:
for file_name in file_names:
self.check_activity_file(file_name)
else:
logger.error("Add test files to %s", activity_path)

@unittest.skipIf(not test_sleep_files, 'Test not selected')
def test_parse_sleep(self):
activity_path = self.file_path + '/sleep'
file_names = FileProcessor.dir_to_files(activity_path, fitfile.file.name_regex, False)
for file_name in file_names:
self.check_sleep_file(file_name)
if len(file_names) > 0:
for file_name in file_names:
self.check_sleep_file(file_name)
else:
logger.error("Add test files to %s", activity_path)

@unittest.skipIf(not test_metrics_files, 'Test not selected')
def test_parse_metrics(self):
# root_logger.setLevel(logging.DEBUG)
activity_path = self.file_path + '/metrics'
file_names = FileProcessor.dir_to_files(activity_path, fitfile.file.name_regex, False)
for file_name in file_names:
self.check_unknown_file(file_name)
if len(file_names) > 0:
for file_name in file_names:
self.check_unknown_file(file_name)
else:
logger.error("Add test files to %s", activity_path)

@unittest.skipIf(not test_unknown_files, 'Test not selected')
def test_parse_unknown(self):
# root_logger.setLevel(logging.DEBUG)
activity_path = self.file_path + '/unknown'
file_names = FileProcessor.dir_to_files(activity_path, fitfile.file.name_regex, False)
for file_name in file_names:
self.check_unknown_file(file_name)
if len(file_names) > 0:
for file_name in file_names:
self.check_unknown_file(file_name)
else:
logger.error("Add test files to %s", activity_path)


if __name__ == '__main__':
Expand Down

0 comments on commit 5c8bdcf

Please sign in to comment.