Esempio n. 1
0
 def __init__(self, output_func=logger.info, debug=False):
     """Return an instance of the CheckUp class."""
     self.db_params = ConfigManager.get_db_params()
     self.output_func = output_func
     self.debug = debug
     self.garmin_db = GarminDb(self.db_params)
     self.measurement_system = Attributes.measurements_type(self.garmin_db)
     self.unit_strings = fitfile.units.unit_strings[self.measurement_system]
Esempio n. 2
0
 def setUpClass(cls):
     db_params = ConfigManager.get_db_params()
     db = summarydb.SummaryDb(db_params)
     table_dict = {
         'months_table': summarydb.MonthsSummary,
         'weeks_table': summarydb.WeeksSummary,
         'days_table': summarydb.DaysSummary
     }
     super().setUpClass(db, table_dict)
Esempio n. 3
0
 def setUpClass(cls):
     cls.garmin_act_db = ActivitiesDb(ConfigManager.get_db_params())
     table_dict = {
         'activities_table': Activities,
         'activity_laps_table': ActivityLaps,
         'activity_records_table': ActivityRecords,
         'run_activities_table': StepsActivities,
         'paddle_activities_table': PaddleActivities,
         'cycle_activities_table': CycleActivities,
     }
     super().setUpClass(cls.garmin_act_db, table_dict,
                        {Activities: [Activities.activity_id]})
     cls.test_db_params = ConfigManager.get_db_params(test_db=True)
     cls.plugin_manager = PluginManager(
         ConfigManager.get_or_create_plugins_dir(), cls.test_db_params)
     cls.test_mon_db = GarminDb(cls.test_db_params)
     cls.test_act_db = ActivitiesDb(cls.test_db_params, debug_level=1)
     cls.measurement_system = fitfile.field_enums.DisplayMeasure.statute
     print(f"db params {repr(cls.test_db_params)}")
 def setUpClass(cls):
     db_params = ConfigManager.get_db_params()
     db = GarminSummaryDb(db_params)
     table_dict = {
         'summary_table': Summary,
         'months_table': MonthsSummary,
         'weeks_table': WeeksSummary,
         'days_table': DaysSummary
     }
     super().setUpClass(db, table_dict)
Esempio n. 5
0
 def test_parse_uprofile(self):
     db_params = ConfigManager.get_db_params(test_db=True)
     gp = GarminProfile(db_params, self.file_path, debug=2)
     if gp.file_count() > 0:
         gp.process()
     gdb = GarminDb(db_params)
     measurement_system = Attributes.measurements_type(gdb)
     self.assertEqual(
         measurement_system, fitfile.field_enums.DisplayMeasure.statute,
         'DisplayMeasure expected %r found %r' %
         (fitfile.field_enums.DisplayMeasure.statute, measurement_system))
Esempio n. 6
0
 def setUpClass(cls):
     db_params = ConfigManager.get_db_params()
     cls.plugin_manager = PluginManager(
         ConfigManager.get_or_create_plugins_dir(), db_params)
     cls.garmin_mon_db = MonitoringDb(db_params)
     table_dict = {
         'monitoring_info_table': MonitoringInfo,
         'monitoring_hr_table': MonitoringHeartRate,
         'monitoring_intensity_table': MonitoringIntensity,
         'monitoring_climb_table': MonitoringClimb,
         'monitoring_table': Monitoring,
     }
     super().setUpClass(cls.garmin_mon_db, table_dict)
Esempio n. 7
0
def main(argv):
    """Import into a DB and summarize CSV formatted FitBit export data."""
    parser = argparse.ArgumentParser()
    parser.add_argument("-v",
                        "--version",
                        help="print the program's version",
                        action='version',
                        version=format_version(sys.argv[0]))
    parser.add_argument("-t",
                        "--trace",
                        help="Turn on debug tracing",
                        type=int,
                        default=0)
    modes_group = parser.add_argument_group('Modes')
    modes_group.add_argument(
        "-i",
        "--input_file",
        help="Specifiy the CSV file to import into the database")
    modes_group.add_argument(
        "--rebuild_db",
        help="Delete FitBit db files and rebuild the database.",
        action="store_true",
        default=False)
    modes_group.add_argument("--delete_db",
                             help="Delete FitBit db file.",
                             action="store_true",
                             default=False)
    args = parser.parse_args()

    root_logger = logging.getLogger()
    if args.trace > 0:
        root_logger.setLevel(logging.DEBUG)
    else:
        root_logger.setLevel(logging.INFO)

    db_params = ConfigManager.get_db_params()

    if args.delete_db or args.rebuild_db:
        FitBitDb.delete_db(db_params)
        if args.delete_db:
            sys.exit()

    fitbit_dir = ConfigManager.get_or_create_fitbit_dir()
    metric = ConfigManager.get_metric()
    fd = FitBitData(args.input_file, fitbit_dir, db_params, metric, args.trace)
    if fd.file_count() > 0:
        fd.process_files()

    analyze = Analyze(db_params)
    analyze.get_years()
    analyze.summary()
Esempio n. 8
0
 def setUpClass(cls):
     db_params = ConfigManager.get_db_params()
     cls.garmin_db = GarminDb(db_params)
     table_dict = {
         'attributes_table': Attributes,
         'device_table': Device,
         'device_info_table': DeviceInfo,
         'file_table': File,
         'weight_table': Weight,
         'stress_table': Stress,
         'sleep_table': Sleep,
         'sleep_events_table': SleepEvents,
         'resting_heart_rate_table': RestingHeartRate
     }
     super().setUpClass(cls.garmin_db, table_dict)
Esempio n. 9
0
 def test_summary_json_file_import(self):
     db_params = ConfigManager.get_db_params(test_db=True)
     gjsd = GarminSummaryData(
         db_params,
         'test_files/json/monitoring/summary',
         latest=False,
         measurement_system=fitfile.field_enums.DisplayMeasure.statute,
         debug=2)
     if gjsd.file_count() > 0:
         gjsd.process()
     table_not_none_cols_dict = {
         DailySummary: [
             DailySummary.rhr, DailySummary.distance, DailySummary.steps,
             DailySummary.floors_goal
         ]
     }
     self.check_not_none_cols(GarminDb(db_params), table_not_none_cols_dict)
Esempio n. 10
0
 def test_fit_file_import(self):
     db_params = ConfigManager.get_db_params(test_db=True)
     self.profile_function('fit_mon_import', self.fit_file_import,
                           db_params)
     test_mon_db = GarminDb(db_params)
     self.check_db_tables_exists(test_mon_db, {'device_table': Device})
     self.check_db_tables_exists(test_mon_db, {
         'file_table': File,
         'device_info_table': DeviceInfo
     }, self.gfd_file_count)
     table_not_none_cols_dict = {
         Monitoring: [
             Monitoring.timestamp, Monitoring.activity_type,
             Monitoring.duration
         ]
     }
     self.check_not_none_cols(MonitoringDb(db_params),
                              table_not_none_cols_dict)
Esempio n. 11
0
 def setUpClass(cls):
     cls.db_params = ConfigManager.get_db_params(test_db=True)
     cls.garmin_db = GarminDb(cls.db_params)
Esempio n. 12
0
from garmindb import GarminProfile, GarminWeightData, GarminSummaryData, GarminMonitoringFitData, GarminSleepData, GarminRhrData, GarminSettingsFitData, GarminHydrationData
from garmindb import GarminJsonSummaryData, GarminJsonDetailsData, GarminTcxData, GarminActivitiesFitData
from garmindb import ActivityExporter

from garmindb import ConfigManager, GarminConnectConfigManager, PluginManager
from garmindb import Statistics
from garmindb import OpenWithBaseCamp, OpenWithGoogleEarth


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

gc_config = GarminConnectConfigManager()
db_params_dict = ConfigManager.get_db_params()
plugin_manager = PluginManager(ConfigManager.get_or_create_plugins_dir(), db_params_dict)


stats_to_db_map = {
    Statistics.monitoring            : MonitoringDb,
    Statistics.steps                 : MonitoringDb,
    Statistics.itime                 : MonitoringDb,
    Statistics.sleep                 : GarminDb,
    Statistics.rhr                   : GarminDb,
    Statistics.weight                : GarminDb,
    Statistics.activities            : ActivitiesDb
}

summary_dbs = [GarminSummaryDb, SummaryDb]