def download_data(overwite, latest, stats): """Download selected activity types from Garmin Connect and save the data in files. Overwrite previously downloaded data if indicated.""" logger.info("___Downloading %s Data___", 'Latest' if latest else 'All') db_params_dict = GarminDBConfigManager.get_db_params() download = Download() if not download.login(): logger.error("Failed to login!") sys.exit() if Statistics.activities in stats: if latest: activity_count = gc_config.latest_activity_count() else: activity_count = gc_config.all_activity_count() activities_dir = GarminDBConfigManager.get_or_create_activities_dir() root_logger.info("Fetching %d activities to %s", activity_count, activities_dir) download.get_activity_types(activities_dir, overwite) download.get_activities(activities_dir, activity_count, overwite) if Statistics.monitoring in stats: date, days = __get_date_and_days(GarminDB.MonitoringDB(db_params_dict), latest, GarminDB.MonitoringHeartRate, GarminDB.MonitoringHeartRate.heart_rate, 'monitoring') if days > 0: root_logger.info("Date range to update: %s (%d) to %s", date, days, GarminDBConfigManager.get_monitoring_base_dir()) download.get_daily_summaries(GarminDBConfigManager.get_or_create_monitoring_dir, date, days, overwite) download.get_hydration(GarminDBConfigManager.get_or_create_monitoring_dir, date, days, overwite) download.get_monitoring(GarminDBConfigManager.get_or_create_monitoring_dir, date, days) root_logger.info("Saved monitoring files for %s (%d) to %s for processing", date, days, GarminDBConfigManager.get_monitoring_base_dir()) if Statistics.sleep in stats: date, days = __get_date_and_days(GarminDB.GarminDB(db_params_dict), latest, GarminDB.Sleep, GarminDB.Sleep.total_sleep, 'sleep') if days > 0: sleep_dir = GarminDBConfigManager.get_or_create_sleep_dir() root_logger.info("Date range to update: %s (%d) to %s", date, days, sleep_dir) download.get_sleep(sleep_dir, date, days, overwite) root_logger.info("Saved sleep files for %s (%d) to %s for processing", date, days, sleep_dir) if Statistics.weight in stats: date, days = __get_date_and_days(GarminDB.GarminDB(db_params_dict), latest, GarminDB.Weight, GarminDB.Weight.weight, 'weight') if days > 0: weight_dir = GarminDBConfigManager.get_or_create_weight_dir() root_logger.info("Date range to update: %s (%d) to %s", date, days, weight_dir) download.get_weight(weight_dir, date, days, overwite) root_logger.info("Saved weight files for %s (%d) to %s for processing", date, days, weight_dir) if Statistics.rhr in stats: date, days = __get_date_and_days(GarminDB.GarminDB(db_params_dict), latest, GarminDB.RestingHeartRate, GarminDB.RestingHeartRate.resting_heart_rate, 'rhr') if days > 0: rhr_dir = GarminDBConfigManager.get_or_create_rhr_dir() root_logger.info("Date range to update: %s (%d) to %s", date, days, rhr_dir) download.get_rhr(rhr_dir, date, days, overwite) root_logger.info("Saved rhr files for %s (%d) to %s for processing", date, days, rhr_dir)
def copy_data(overwrite, latest, weight, monitoring, sleep, rhr, activities): """Copy data from a mounted Garmin USB device to files.""" copy = Copy(gc_gonfig.device_mount_dir()) if activities: activities_dir = GarminDBConfigManager.get_or_create_activities_dir() root_logger.info("Copying activities to %s", activities_dir) copy.copy_activities(activities_dir, latest) if monitoring: monitoring_dir = GarminDBConfigManager.get_or_create_monitoring_dir( datetime.datetime.now().year) root_logger.info("Copying monitoring to %s", monitoring_dir) copy.copy_monitoring(monitoring_dir, latest)
def copy_data(overwite, latest, stats): """Copy data from a mounted Garmin USB device to files.""" logger.info("___Copying Data___") copy = Copy(gc_config.device_mount_dir()) settings_dir = GarminDBConfigManager.get_or_create_fit_files_dir() root_logger.info("Copying settings to %s", settings_dir) copy.copy_settings(settings_dir) if Statistics.activities in stats: activities_dir = GarminDBConfigManager.get_or_create_activities_dir() root_logger.info("Copying activities to %s", activities_dir) copy.copy_activities(activities_dir, latest) if Statistics.monitoring in stats: monitoring_dir = GarminDBConfigManager.get_or_create_monitoring_dir(datetime.datetime.now().year) root_logger.info("Copying monitoring to %s", monitoring_dir) copy.copy_monitoring(monitoring_dir, latest) if Statistics.sleep in stats: monitoring_dir = GarminDBConfigManager.get_or_create_monitoring_dir(datetime.datetime.now().year) root_logger.info("Copying sleep to %s", monitoring_dir) copy.copy_sleep(monitoring_dir, latest)
def download_data(overwrite, latest, weight, monitoring, sleep, rhr, activities): """Download selected activity types from Garmin Connect and save the data in files. Overwrite previously downloaded data if indicated.""" db_params_dict = GarminDBConfigManager.get_db_params() download = Download() if not download.login(): logger.error("Failed to login!") sys.exit() if activities: if latest: activity_count = gc_gonfig.latest_activity_count() else: activity_count = gc_gonfig.all_activity_count() activities_dir = GarminDBConfigManager.get_or_create_activities_dir() root_logger.info("Fetching %d activities to %s", activity_count, activities_dir) download.get_activity_types(activities_dir, overwrite) download.get_activities(activities_dir, activity_count, overwrite) download.unzip_files(activities_dir) if monitoring: date, days = __get_date_and_days( GarminDB.MonitoringDB(db_params_dict), latest, GarminDB.MonitoringHeartRate, GarminDB.MonitoringHeartRate.heart_rate, 'monitoring') if days > 0: monitoring_dir = GarminDBConfigManager.get_or_create_monitoring_dir( date.year) root_logger.info("Date range to update: %s (%d) to %s", date, days, monitoring_dir) download.get_daily_summaries(monitoring_dir, date, days, overwrite) download.get_monitoring(date, days) download.unzip_files(monitoring_dir) root_logger.info( "Saved monitoring files for %s (%d) to %s for processing", date, days, monitoring_dir) if sleep: date, days = __get_date_and_days(GarminDB.GarminDB(db_params_dict), latest, GarminDB.Sleep, GarminDB.Sleep.total_sleep, 'sleep') if days > 0: sleep_dir = GarminDBConfigManager.get_or_create_sleep_dir() root_logger.info("Date range to update: %s (%d) to %s", date, days, sleep_dir) download.get_sleep(sleep_dir, date, days, overwrite) root_logger.info( "Saved sleep files for %s (%d) to %s for processing", date, days, sleep_dir) if weight: date, days = __get_date_and_days(GarminDB.GarminDB(db_params_dict), latest, GarminDB.Weight, GarminDB.Weight.weight, 'weight') if days > 0: weight_dir = GarminDBConfigManager.get_or_create_weight_dir() root_logger.info("Date range to update: %s (%d) to %s", date, days, weight_dir) download.get_weight(weight_dir, date, days, overwrite) root_logger.info( "Saved weight files for %s (%d) to %s for processing", date, days, weight_dir) if rhr: date, days = __get_date_and_days( GarminDB.GarminDB(db_params_dict), latest, GarminDB.RestingHeartRate, GarminDB.RestingHeartRate.resting_heart_rate, 'rhr') if days > 0: rhr_dir = GarminDBConfigManager.get_or_create_rhr_dir() root_logger.info("Date range to update: %s (%d) to %s", date, days, rhr_dir) download.get_rhr(rhr_dir, date, days, overwrite) root_logger.info( "Saved rhr files for %s (%d) to %s for processing", date, days, rhr_dir)
def import_data(debug, latest, stats): """Import previously downloaded Garmin data into the database.""" logger.info("___Importing %s Data___", 'Latest' if latest else 'All') db_params_dict = GarminDBConfigManager.get_db_params() ignore_dev_fields = gc_config.ignore_dev_fields() # Import the user profile and/or settings FIT file first so that we can get the measurement system and some other things sorted out first. fit_files_dir = GarminDBConfigManager.get_or_create_fit_files_dir() gp = GarminProfile(db_params_dict, fit_files_dir, debug) if gp.file_count() > 0: gp.process() gsfd = GarminSettingsFitData(fit_files_dir, ignore_dev_fields, debug) if gsfd.file_count() > 0: gsfd.process_files(db_params_dict) garmindb = GarminDB.GarminDB(db_params_dict) measurement_system = GarminDB.Attributes.measurements_type(garmindb) if Statistics.weight in stats: weight_dir = GarminDBConfigManager.get_or_create_weight_dir() gwd = GarminWeightData(db_params_dict, weight_dir, latest, measurement_system, debug) if gwd.file_count() > 0: gwd.process() if Statistics.monitoring in stats: monitoring_dir = GarminDBConfigManager.get_or_create_monitoring_base_dir() gsd = GarminSummaryData(db_params_dict, monitoring_dir, latest, measurement_system, debug) if gsd.file_count() > 0: gsd.process() ghd = GarminHydrationData(db_params_dict, monitoring_dir, latest, measurement_system, debug) if ghd.file_count() > 0: ghd.process() gfd = GarminMonitoringFitData(monitoring_dir, latest, measurement_system, ignore_dev_fields, debug) if gfd.file_count() > 0: gfd.process_files(db_params_dict) if Statistics.sleep in stats: sleep_dir = GarminDBConfigManager.get_or_create_sleep_dir() gsd = GarminSleepData(db_params_dict, sleep_dir, latest, debug) if gsd.file_count() > 0: gsd.process() if Statistics.rhr in stats: rhr_dir = GarminDBConfigManager.get_or_create_rhr_dir() grhrd = GarminRhrData(db_params_dict, rhr_dir, latest, debug) if grhrd.file_count() > 0: grhrd.process() if Statistics.activities in stats: activities_dir = GarminDBConfigManager.get_or_create_activities_dir() # Tcx fields are less precise than the JSON files, so load Tcx first and overwrite with better JSON values. gtd = GarminTcxData(activities_dir, latest, measurement_system, debug) if gtd.file_count() > 0: gtd.process_files(db_params_dict) gjsd = GarminJsonSummaryData(db_params_dict, activities_dir, latest, measurement_system, debug) if gjsd.file_count() > 0: gjsd.process() gdjd = GarminJsonDetailsData(db_params_dict, activities_dir, latest, measurement_system, debug) if gdjd.file_count() > 0: gdjd.process() gfd = GarminActivitiesFitData(activities_dir, latest, measurement_system, ignore_dev_fields, debug) if gfd.file_count() > 0: gfd.process_files(db_params_dict)
def test_copy_activity(self): activities_dir = GarminDBConfigManager.get_or_create_activities_dir(test_dir=True) logger.info("Copying activities to %s", activities_dir) self.copy.copy_activities(activities_dir)