Skip to content

Commit

Permalink
Issue #133: handle multiple app ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Goetz committed Sep 22, 2021
1 parent 4b0976c commit 190e4b5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Fit
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include garmindb/GarminConnectConfig.json.example
include requirements.in
include requirements.txt
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ build:
$(PROJECT_BASE)/dist/$(MODULE)-*.whl: build

install: $(PROJECT_BASE)/dist/$(MODULE)-*.whl
$(PIP) install --upgrade --force-reinstall $(PROJECT_BASE)/dist/$(MODULE)-*.whl
$(PIP) install --upgrade --force-reinstall --no-deps $(PROJECT_BASE)/dist/$(MODULE)-*.whl

install_all: $(SUBMODULES:%=%-install) install

Expand Down Expand Up @@ -126,7 +126,6 @@ $(SUBDIRS:%=%-clean):
clean: $(SUBMODULES:%=%-clean) $(SUBDIRS:%=%-clean) test_clean
rm -f *.pyc
rm -f *.log
rm -rf build
rm -f *.spec
rm -f *.zip
rm -f *.png
Expand Down
1 change: 1 addition & 0 deletions garmindb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

__version__ = version_string()

from .activity_plugin_base import ActivityPluginBase
from .activity_fit_file_processor import ActivityFitFileProcessor
from .fit_data import FitData
from .fit_file_processor import FitFileProcessor
Expand Down
56 changes: 56 additions & 0 deletions garmindb/activity_plugin_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Base class for GarminDb plugins."""

__author__ = "Tom Goetz"
__copyright__ = "Copyright Tom Goetz"
__license__ = "GPL"

import logging


logger = logging.getLogger(__file__)


class ActivityPluginBase():
"""Base class for GarminDb plugins."""

@classmethod
def matches_activity_file(cls, fit_file):
"""Return if the file matches this plugin."""
if hasattr(cls, '_application_id'):
return cls._application_id in fit_file.dev_application_ids
if hasattr(cls, '_sport') and (fit_file.sport_type is None or fit_file.sport_type.value is not cls._sport):
return False
if hasattr(cls, '_sub_sport') and (fit_file.sub_sport_type is None or fit_file.sub_sport_type.value is not cls._sub_sport):
return False
if hasattr(cls, '_dev_fields'):
for dev_field in cls._dev_fields:
if dev_field not in fit_file.dev_fields:
return False
return True

@classmethod
def init_activity(cls, act_db_class, activities_table):
"""Initialize an instance of the elliptical plugin as an activity FIT file plugin."""
logger.info("Initializing tables for activity plugin %s with act_table %s", cls.__name__, activities_table)
if hasattr(cls, '_records_tablename') and 'record' not in cls._tables:
cls._tables['record'] = activities_table.create(cls._records_tablename, act_db_class, cls._records_version, cls._records_pk, cls._records_cols)
if hasattr(cls, '_laps_tablename') and 'lap' not in cls._tables:
cls._tables['lap'] = activities_table.create(cls._laps_tablename, act_db_class, cls._laps_version, cls._laps_pk, cls._laps_cols)
if hasattr(cls, '_sessions_tablename') and 'session' not in cls._tables:
cls._tables['session'] = activities_table.create(cls._sessions_tablename, act_db_class, cls._sessions_version, cols=cls._sessions_cols,
create_view=cls._views['activity_view'], vars={'activities_table': activities_table})

@classmethod
def _get_field(cls, message_fields, field_name_list):
for field_name in field_name_list:
if field_name in message_fields:
return message_fields[field_name]

@classmethod
def filter_data(cls, indict):
"""Filter None and 0 values from a dict."""
return {key: value for key, value in indict.items() if value}

def __str__(self):
"""Return a string representation of the class instance."""
return f'{self.__class__.__name__}(tables {repr(self._tables.keys())})'
2 changes: 1 addition & 1 deletion garmindb/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

python_required = (3, 0, 0)
python_tested = (3, 9, 5)
version_info = (3, 0, 3)
version_info = (3, 0, 4)
prerelease = True


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ tqdm
matplotlib
cloudscraper
ipykernel
fitfile>=1.0.1
fitfile>=1.0.3
tcxfile>=1.0.1
idbutils>=1.0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_requirements(requirements_file):
module_name = 'garmindb'
module_version = get_version(module_name + os.sep + 'version_info.py')
module_long_description = get_long_description('README.md')
install_requires = get_requirements('requirements.in')
install_requires = get_requirements('requirements.txt')

print(f"Building {module_name} {module_version}")

Expand Down

0 comments on commit 190e4b5

Please sign in to comment.