def test_summary_json_file_import(self):
     db_params_dict = GarminDBConfigManager.get_db_params(test_db=True)
     gjsd = GarminJsonSummaryData(db_params_dict, 'test_files/json/activity/summary', latest=False, measurement_system=Fit.field_enums.DisplayMeasure.statute, debug=2)
     if gjsd.file_count() > 0:
         gjsd.process()
     self.check_not_none_cols(GarminDB.ActivitiesDB(db_params_dict),
         {GarminDB.Activities : [GarminDB.Activities.name, GarminDB.Activities.type, GarminDB.Activities.sport, GarminDB.Activities.sub_sport]}
     )
 def summary_json_file_import(self):
     gjsd = GarminJsonSummaryData(
         self.test_db_params,
         'test_files/json/activity/summary',
         latest=False,
         measurement_system=self.measurement_system,
         debug=2)
     if gjsd.file_count() > 0:
         gjsd.process()
Example #3
0
def import_data(debug, test, latest, weight, monitoring, sleep, rhr,
                activities):
    """Import previously downloaded Garmin data into the database."""
    db_params_dict = GarminDBConfigManager.get_db_params(test_db=test)

    gp = GarminProfile(db_params_dict,
                       GarminDBConfigManager.get_fit_files_dir(), debug)
    if gp.file_count() > 0:
        gp.process()

    garmindb = GarminDB.GarminDB(db_params_dict)
    measurement_system = GarminDB.Attributes.measurements_type(garmindb)

    if weight:
        weight_dir = GarminDBConfigManager.get_weight_dir()
        gwd = GarminWeightData(db_params_dict, weight_dir, latest,
                               measurement_system, debug)
        if gwd.file_count() > 0:
            gwd.process()

    if monitoring:
        monitoring_dir = GarminDBConfigManager.get_monitoring_base_dir()
        gsd = GarminSummaryData(db_params_dict, monitoring_dir, latest,
                                measurement_system, debug)
        if gsd.file_count() > 0:
            gsd.process()
        ged = GarminMonitoringExtraData(db_params_dict, monitoring_dir, latest,
                                        debug)
        if ged.file_count() > 0:
            ged.process()
        gfd = GarminMonitoringFitData(monitoring_dir, latest,
                                      measurement_system, debug)
        if gfd.file_count() > 0:
            gfd.process_files(db_params_dict)

    if sleep:
        sleep_dir = GarminDBConfigManager.get_sleep_dir()
        gsd = GarminSleepData(db_params_dict, sleep_dir, latest, debug)
        if gsd.file_count() > 0:
            gsd.process()

    if rhr:
        rhr_dir = GarminDBConfigManager.get_rhr_dir()
        grhrd = GarminRhrData(db_params_dict, rhr_dir, latest, debug)
        if grhrd.file_count() > 0:
            grhrd.process()

    if activities:
        activities_dir = GarminDBConfigManager.get_activities_dir()
        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()

        ged = GarminActivitiesExtraData(db_params_dict, activities_dir, latest,
                                        debug)
        if ged.file_count() > 0:
            ged.process()

        gtd = GarminTcxData(activities_dir, latest, measurement_system, debug)
        if gtd.file_count() > 0:
            gtd.process_files(db_params_dict)

        gfd = GarminActivitiesFitData(activities_dir, latest,
                                      measurement_system, debug)
        if gfd.file_count() > 0:
            gfd.process_files(db_params_dict)
Example #4
0
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)