Skip to content

Commit

Permalink
merge ConfigManager and GarminConnectConfigManager
Browse files Browse the repository at this point in the history
  • Loading branch information
tcgoetz committed Mar 8, 2024
1 parent fe68a4a commit dd71124
Show file tree
Hide file tree
Showing 36 changed files with 342 additions and 450 deletions.
4 changes: 2 additions & 2 deletions Jupyter/activities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"import snakemd\n",
"\n",
"import fitfile\n",
"from garmindb import ConfigManager, GarminConnectConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, ActivitiesDb, Activities, StepsActivities, ActivityLaps, ActivityRecords\n",
"from idbutils.list_and_dict import list_not_none\n",
"\n",
"from jupyter_funcs import format_number\n",
"\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"db_params_dict = gc_config.get_db_params()\n",
"\n",
"\n",
"garmin_db = GarminDb(db_params_dict)\n",
Expand Down
4 changes: 2 additions & 2 deletions Jupyter/activities_dashboard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"source": [
"import datetime\n",
"from ipywidgets import fixed, Layout, interactive\n",
"from garmindb import ConfigManager, GarminConnectConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, ActivitiesDb, Activities, ActivityLaps, ActivityRecords\n",
"from maps import ActivityMap\n",
"from collections import ChainMap\n",
Expand Down Expand Up @@ -71,7 +71,7 @@
"outputs": [],
"source": [
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"db_params_dict = gc_config.get_db_params()\n",
"garmin_db = GarminDb(db_params_dict)\n",
"garmin_act_db = ActivitiesDb(db_params_dict)\n",
"measurement_system = Attributes.measurements_type(garmin_db)\n",
Expand Down
6 changes: 4 additions & 2 deletions Jupyter/activity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"import snakemd\n",
"\n",
"import fitfile\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, Device, ActivitiesDb, Activities, ActivityLaps, ActivityRecords, ActivitiesDevices\n",
"from idbutils import Location\n",
"\n",
Expand All @@ -29,7 +29,9 @@
"\n",
"doc = snakemd.new_doc()\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"\n",
"garmin_db = GarminDb(db_params_dict)\n",
"garmin_act_db = ActivitiesDb(db_params_dict)\n",
"measurement_system = Attributes.measurements_type(garmin_db)\n",
Expand Down
5 changes: 3 additions & 2 deletions Jupyter/checkup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"\n",
"import fitfile\n",
"import garmindb\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Device, DeviceInfo, ActivitiesDb, Activities, ActivityLaps, ActivityRecords, StepsActivities\n",
"\n",
"doc = snakemd.new_doc()\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"\n",
"garmin_db = GarminDb(db_params_dict)\n",
"\n",
Expand Down
5 changes: 3 additions & 2 deletions Jupyter/course.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"import snakemd\n",
"\n",
"import fitfile\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, ActivitiesDb, Activities, ActivityLaps, ActivityRecords, StepsActivities\n",
"\n",
"from jupyter_funcs import format_number\n",
Expand All @@ -29,7 +29,8 @@
"\n",
"doc.add_heading(f\"Analysis for Course {course_id}\", 2)\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"\n",
"garmin_db = GarminDb(db_params_dict)\n",
"measurement_system = Attributes.measurements_type(garmin_db)\n",
Expand Down
5 changes: 3 additions & 2 deletions Jupyter/daily.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"from IPython.display import display, Markdown\n",
"import snakemd\n",
"\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminSummaryDb, DaysSummary\n",
"\n",
"from jupyter_funcs import format_number\n",
Expand All @@ -39,7 +39,8 @@
" graph.graph_date(date)\n",
"\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"garmin_sum_db = GarminSummaryDb(db_params_dict)\n",
"\n",
"graph = Graph()"
Expand Down
6 changes: 4 additions & 2 deletions Jupyter/daily_trends.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"from IPython.display import display\n",
"import pandas as pd\n",
"\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminSummaryDb, DaysSummary, MonitoringDb, MonitoringHeartRate, Sleep, GarminDb\n",
"from garmindb.summarydb import DaysSummary, SummaryDb\n",
"\n",
Expand Down Expand Up @@ -48,7 +48,9 @@
"# end date (today)\n",
"end_ts = datetime.datetime.combine(datetime.date.today(), datetime.datetime.max.time())\n",
"\n",
"db_params = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params = gc_config.get_db_params()\n",
"\n",
"garmin_db = GarminDb(db_params)\n",
"sum_db = SummaryDb(db_params, False)\n",
"data = DaysSummary.get_for_period(sum_db, start_ts, end_ts, DaysSummary)\n",
Expand Down
5 changes: 3 additions & 2 deletions Jupyter/garmin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"import snakemd\n",
"\n",
"import fitfile\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, File\n",
"\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"garmin_db = GarminDb(db_params_dict)\n",
"\n",
"measurement_system = Attributes.measurements_type(garmin_db)\n",
Expand Down
10 changes: 5 additions & 5 deletions Jupyter/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

from garmindb import ConfigManager
from garmindb import GarminConnectConfigManager
from garmindb.garmindb import MonitoringDb, Monitoring, MonitoringHeartRate, ActivitiesDb
from garmindb.summarydb import DaysSummary, WeeksSummary, MonthsSummary, SummaryDb

Expand Down Expand Up @@ -76,6 +76,8 @@ def __init__(self, debug=False, save=False):
"""Return an instance of the Graph class."""
self.debug = debug
self.save = save
self.gc_config = GarminConnectConfigManager()
self.db_params = self.gc_config.get_db_params()

@classmethod
def __remove_discontinuities(cls, data):
Expand Down Expand Up @@ -206,8 +208,7 @@ def graph_activity(self, activity, period=None, days=None, geometry=111):
period = config[activity]['period']
if days is None:
days = config[activity]['days']
db_params = ConfigManager.get_db_params()
sum_db = SummaryDb(db_params, self.debug)
sum_db = SummaryDb(self.db_params, self.debug)
end_ts = datetime.datetime.now()
start_ts = end_ts - datetime.timedelta(days=days)
table = self.__table[period]
Expand Down Expand Up @@ -237,8 +238,7 @@ def graph_date(self, date, geometry=111):
"""Generate a graph for the given date."""
if date is None:
date = (datetime.datetime.now() - datetime.timedelta(days=1)).date()
db_params = ConfigManager.get_db_params()
mon_db = MonitoringDb(db_params, self.debug)
mon_db = MonitoringDb(self.db_params, self.debug)
start_ts = datetime.datetime.combine(date, datetime.datetime.min.time())
end_ts = datetime.datetime.combine(date, datetime.datetime.max.time())
hr_data = MonitoringHeartRate.get_for_period(mon_db, start_ts, end_ts, MonitoringHeartRate)
Expand Down
5 changes: 3 additions & 2 deletions Jupyter/monitoring.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"import snakemd\n",
"\n",
"import fitfile\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, Weight, Stress, RestingHeartRate, IntensityHR, Sleep\n",
"from garmindb.garmindb import MonitoringDb, Monitoring, MonitoringHeartRate, MonitoringIntensity, MonitoringClimb\n",
"\n",
"from jupyter_funcs import format_number\n",
"\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"garmin_db = GarminDb(db_params_dict)\n",
"garmin_mon_db = MonitoringDb(db_params_dict)\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions Jupyter/month.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"from IPython.display import display, Markdown\n",
"import snakemd\n",
"\n",
"from garmindb import ConfigManager, GarminConnectConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminDb, Attributes, ActivitiesDb, Activities\n",
"\n",
"from graphs import Graph\n",
Expand All @@ -36,7 +36,7 @@
"\n",
"\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"db_params_dict = gc_config.get_db_params()\n",
"\n",
"num_of_days = 30\n",
"\n",
Expand Down
5 changes: 3 additions & 2 deletions Jupyter/summary.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"import snakemd\n",
"import datetime\n",
"\n",
"from garmindb import ConfigManager\n",
"from garmindb import GarminConnectConfigManager\n",
"from garmindb.garmindb import GarminSummaryDb, YearsSummary\n",
"\n",
"from jupyter_funcs import format_number\n",
Expand All @@ -27,7 +27,8 @@
"years_to_display = 4\n",
"days_to_display = (years_to_display * 365)\n",
"\n",
"db_params_dict = ConfigManager.get_db_params()\n",
"gc_config = GarminConnectConfigManager()\n",
"db_params_dict = gc_config.get_db_params()\n",
"garmin_sum_db = GarminSummaryDb(db_params_dict)\n",
"\n",
"graph = Graph()"
Expand Down
2 changes: 1 addition & 1 deletion Plugins
Submodule Plugins updated 1 files
+1 −1 Makefile
16 changes: 15 additions & 1 deletion garmindb/GarminConnectConfig.json.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"db": {
"type" : "sqlite"
},
"garmin": {
"domain": "garmin.com"
"domain" : "garmin.com"
},
"credentials": {
"user" : "joe@shmoe.com",
Expand All @@ -15,6 +18,10 @@
"download_latest_activities" : 25,
"download_all_activities" : 1000
},
"directories": {
"relative_to_home" : true,
"base_dir" : "HealthData"
},
"copy": {
"mount_dir" : "/Volumes/GARMIN"
},
Expand All @@ -34,5 +41,12 @@
},
"activities": {
"display" : []
},
"settings": {
"metric" : false,
"default_display_activities" : ["walking", "running", "cycling"]
},
"checkup": {
"look_back_days" : 90
}
}
1 change: 0 additions & 1 deletion garmindb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from .fit_data import FitData
from .fit_file_processor import FitFileProcessor
from .garmin_connect_config_manager import GarminConnectConfigManager
from .config_manager import ConfigManager
from .statistics import Statistics
from .tcx import Tcx
from .monitoring_fit_file_processor import MonitoringFitFileProcessor
Expand Down
3 changes: 1 addition & 2 deletions garmindb/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ def summary(self):

def create_dynamic_views(self):
"""Create database views specific to the data in this database."""
gc_config = GarminConnectConfigManager()
course_ids = gc_config.course_views('steps')
course_ids = GarminConnectConfigManager().course_views('steps')
if course_ids:
for course_id in course_ids:
StepsActivities.create_course_view(self.garmin_act_db, course_id)
7 changes: 4 additions & 3 deletions garmindb/checkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import fitfile

from garmindb.garmindb import GarminDb, Attributes, Device, DeviceInfo, DailySummary, ActivitiesDb, Activities, StepsActivities
from garmindb import ConfigManager
from garmindb import GarminConnectConfigManager


logger = logging.getLogger(__file__)
Expand All @@ -26,7 +26,8 @@ class Checkup():

def __init__(self, paragraph_func=logger.info, heading_func=logger.info, debug=False):
"""Return an instance of the CheckUp class."""
self.db_params = ConfigManager.get_db_params()
self.gc_config = GarminConnectConfigManager()
self.db_params = self.gc_config.get_db_params()
self.paragraph_func = paragraph_func
self.heading_func = heading_func
self.debug = debug
Expand All @@ -36,7 +37,7 @@ def __init__(self, paragraph_func=logger.info, heading_func=logger.info, debug=F

def goals(self):
"""Do a checkup of the user's goals."""
look_back_days = ConfigManager.checkup.get('look_back_days')
look_back_days = self.gc_config.get_node_value_default('checkup', 'look_back_days', 90)
end_ts = datetime.now()
start_ts = end_ts - timedelta(days=look_back_days)
results = DailySummary.get_for_period(self.garmin_db, start_ts, end_ts)
Expand Down
49 changes: 0 additions & 49 deletions garmindb/config.py

This file was deleted.

Loading

0 comments on commit dd71124

Please sign in to comment.