Health Data Service

Use the Health Data Service to get user data and generated metrics from the Point database.

User Data

Use HealthDataService/getUserData() to retrieve basic information about your User.

func getUser() async -> User? {
    do {
        return try await Point.healthDataService.getUserData()
    } catch {
        print("Error retrieving user data: \(error.localizedDescription)")
        return nil
    }
}

The User object also contains some information related to their health journey, like their Goal or SpecificGoal, the current GoalProgress, and their last Workout.

Currently, personal information such as name and email are not stored in any of our databases for privacy reasons.

Goals

Goals are used by the Health Data Service to know what is the main objective of your user while working out. This is used to generate recommendations and insights that help the user reach their objectives.

We highly recommend setting a goal. Not setting a goal will greatly decrease the number of insights generated.

Setting a User Goal

Call HealthDataService/syncUserGoal(goal:) to set the user Goal.

func setUserGoal(goal: Goal) async {
    do {
        let result = try await Point.healthDataService.syncUserGoal(goal: goal)
        print(result)
    } catch {
        print(error.localizedDescription)
    }
}

Currently, the two options are Goal/athleticPerformance and Goal/weightLoss. You are free to use them as you wish, as long one of them is set for each user. You can hardcode the same goal for all users, present them as two options to choose from, or present a larger set of more specific goals that map to one of these two options. Your choice depends on your app's audience.

The SDK also provides a set of SpecificGoals (all values are only aliases to a Goal). Call HealthDataService/syncUserSpecificGoal(specificGoal:) to set the user SpecificGoal. If you use the specific goals you don't need to call syncUserGoal.

func setUserSpecificGoal(goal: SpecificGoal) async {
    do {
        let result = try await Point.healthDataService.syncUserSpecificGoal(specificGoal: goal)
        print(result)
    } catch {
        print(error.localizedDescription)
    }
}

Checking the Goal Progress

You can also check their current GoalProgress, which are scores ranging from 0 to 1, generated by the Point Health Data Service. The goal progress is divided into four different scores: GoalProgress/overall, GoalProgress/endurance, GoalProgress/recovery and GoalProgress/strength.

func printCurrentGoalProgress() async {
    do {
        guard let user = try await Point.healthDataService.getUserData() else { return }
        print("Overall Value: \(user.goalProgress.overall.value)")
        print("Endurance Value: \(user.goalProgress.endurance.value)")
        print("Recovery Value: \(user.goalProgress.recovery.value)")
        print("Strength Value: \(user.goalProgress.strength.value)")
    } catch {
        print("Error retrieving user data: \(error.localizedDescription)")
        return nil
    }
}

For more information about the goal scoring system, check Point Data Science Overview. Note that you can have your own ways of interpreting the scores and creating an overall score.

User Workouts

Use HealthDataService/getUserWorkouts(offset:) to retrieve a list of the User's last 16 Workouts, in descending order. The offset is meant to be used as a pagination, and if no value is passed, it is defaulted to 0.

func retrieveUserWorkouts(offset: Int = 0) async -> [Workout]? {
    do {
        return try await Point.healthDataService.getUserWorkouts(offset: offset)
    } catch {
        print("Error retrieving user workouts: \(error.localizedDescription)")
        return nil
    }
}

Retrieves a single Workout for the given id.

func retrieveWorkout(id: Int) async -> Workout? {
    do {
        return try await Point.healthDataService.getWorkout(id: id)
    } catch {
        print("Error retrieving workout: \(error.localizedDescription)")
        return nil
    }
}

Workout Rating

You can allow users to rate their past workouts. A workout rating is divided in "Difficulty", "Energy" and "Instructor" ratings. Each field can be rated from 1 to 5, defaulting to 0 if a value is not set.

func rateWorkout(workout: Workout) async -> Workout {
    let ratings = WorkoutRatings(difficulty: 4, energy: 5, instructor: 3)
    do {
        let newWorkout = try await healthDataService.rate(workout: workout, ratings: ratings)
        return newWorkout
    } catch {
        print("Error when rating workout: \(error.localizedDescription)")
        return workout
    }
}

We recommend you to rate a workout only once.

Daily History

Use HealthDataService/getDailyHistory(offset:) to retrieve a list of the User's last 16 days worth of DailyHistory, in descending order. The DailyHistory is composed of daily total calories, exertion rate and total workout duration.

func getDailyHistory(offset: Int = 0) async -> [DailyHistory]? {
    do {
        return try await Point.healthDataService.getDailyHistory(offset: offset)
    } catch {
        print("Error retrieving daily history: \(error.localizedDescription)")
        return nil
    }
}

Tip: The offset is meant to be used as a pagination, and if no value is passed, it is defaulted to 0.

Insights

As your user goes through their health journey, Point automatically generates actionable health insights that will help your users achieve maximal health and wellness. These insights can be wrapped in custom copy text, so you can recommend helpful actions for them to take in your product or platform, using Point's real-time health intelligence system.

You can get the list of generated Insights using HealthDataService/getInsights(types:from:to:offset:). You must provide a list of InsightType. You can also filter the results based on a date interval using the from and to parameters.

Important: The result is limited to 16 insights. You can use the offset parameter for pagination. If not provided, it defaults to 0.

func getInsights() async {
    do {
        let insights = try await pointDataService.getInsights(types: Set(InsightType.allCases), from: nil, to: nil, offset: nil)
        let moreInsights = try await pointDataService.getInsights(types: Set(InsightType.allCases), from: nil, to: nil, offset: 16)
    } catch {
        print(error.localizedDescription)
    }
 }

To check the insight's content, you will need to parse Insight/additionalFields as a JSON. The JSON keys changes for each insight type. For example, the insight type InsightType/exertionOptimalPm has the keys change and pct_change, while type InsightType/mostEfficientWorkoutType has the keys workout_type and avg_value.

do {
    guard let exertionOptPmInsight = try await pointDataService.getInsights(types: [.exertionOptimalPm], from: nil, to: nil, offset: nil).first else { return }
    let metadata = yourMethodToParseJSON(string: exertionOptPmInsight.additionalFields)
    print("You work \(metadata["pct_change"]!)% harder in the evenings, night owl!")

    guard let mostEfficientWorkoutTypeInsight = try await pointDataService.getInsights(types: [.mostEfficientWorkoutType], from: nil, to: nil, offset: nil).first else { return }
    let otherMetadata = yourMethodToParseJSON(string: mostEfficientWorkoutTypeInsight.additionalFields)
    print("Your most efficient workout is \(otherMetadata["workout_type"]!)")
} catch {
    print(error.localizedDescription)
}

Tip: You can find detailed information about Insights here, including all JSON keys for each type (refer to the 'Metadata' column in each table).

User Health Metrics

You can get a set of user health metrics, which are a summary of the collected samples. Check HealthMetric to know all kinds of health metrics available.

func getUserHealthMetrics() async -> [HealthMetric]? {
    do {
        return try await Point.healthDataService.getHealthMetrics(
            filter: Set(HealthMetric.Kind.allCases),
            workoutId: nil,
            date: nil
        )
    } catch {
        print("Error retrieving user health metrics: \(error.localizedDescription)")
        return nil
    }
}

You can filter by type, workout or date.

Workout Recommendations

Retrieves a list of WorkoutRecommendation. Workout recommendations are generated weekly on the Point database, based in the user goal. The date parameter defines which week you will get recommendations from.

func getWorkoutsRecommendations(date: Date) async -> [WorkoutRecommendation]? {
    do {
        return try await Point.healthDataService.getWorkoutRecommendations(date: date)
    } catch {
        print("Error retrieving workout recommendations \(error.localizedDescription)")
        return nil
    }
}

Tip: Use the current date to get recommendations from the current week.

Saving a Workout Recommendation

You can use HealthDataService/saveWorkoutRecommendation(id:) to let your user choose which workout recommendations they wish to accomplish. By saving it, Point is able to check if the user accomplished this recommendation and use this information to improve the next recommendations given to this user.

func saveWorkoutRecommendation(recommendation: WorkoutRecommendation) async -> Bool {
    do {
        return try await pointDataService.saveWorkoutRecommendation(id: recommendation.id)
    } catch {
        print("Error saving workout recommendation: \(error.localizedDescription)")
        return false
    }
}

Download our App

Download the app on App Store

Connect with Us

Terms & Conditions | Privacy Policy © 2022 Point® (Key Point Technologies, Inc.)