Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple Health metrics: toothbrushing as sessions per day and as minutes per day #556

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

krugerk
Copy link
Contributor

@krugerk krugerk commented Dec 17, 2024

Summary

Users have requested beeminding toothbrushing and using Apple Health and the Beeminder iOS app to do so.
As is, this is an initial implementation adding toothbrushing to the app's apple health integration.

Supports

  • Number of minutes brushed (per day)
  • Number of teethbrushing sessions (per day)

Validation

Added data to Apple Health in the Simulator
Ran the app in the simulator. Set up a goal, linked it with Toothbrushing, let it log datapoints.

@krugerk
Copy link
Contributor Author

krugerk commented Dec 17, 2024

Once code has run with this and then another build of the app is used where the app does not yet support the metric, there are errors and warnings about the missing metric as well as crashes in places like RemoveHKMetricViewController where self.goal.humanizedAutodata is being force unwrapped.
Not only during development but also in the field, this scenario could happen, for example, where a user has multiple devices, upgraded one and not yet the other, or on the same device tried a TestFlight build of the app (with the metric) then reverted to the App Store build (without the metric).

Also, the app should report to the user that a goal configured for a metric is not being sourced as there is some issue.

@krugerk krugerk changed the title toothbrushing as seconds per day Apple Health metrics: toothbrushing as sessions per day and as seconds per day Dec 18, 2024
@krugerk krugerk force-pushed the feature/88-teethbrushing branch from d3de888 to 4eea411 Compare December 18, 2024 08:55
@krugerk krugerk changed the title Apple Health metrics: toothbrushing as sessions per day and as seconds per day Apple Health metrics: toothbrushing as sessions per day and as minutes per day Dec 18, 2024
@@ -12,6 +12,7 @@ public enum HealthKitCategory : String, CaseIterable {
case Heart = "Heart"
case Mindfulness = "Mindfulness"
case Nutrition = "Nutrition"
case SelfCare = "Self Care"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These categories map to the categorizations in the Health app. Toothbrushing is under "Other".

@@ -51,6 +51,10 @@ public enum HealthKitConfig {
QuantityHealthKitMetric(humanText: "Vitamin K", databaseString: "dietaryVitaminK", category: .Nutrition, hkQuantityTypeIdentifier: .dietaryVitaminK),
QuantityHealthKitMetric(humanText: "Water", databaseString: "water", category: .Nutrition, hkQuantityTypeIdentifier: .dietaryWater),

// Self care
ToothbrushingDailyMinutesHealthKitMetric.make(),
ToothbrushingDailySessionsHealthKitMetric.make(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to have multiple top level metrics for the same underlying metric. There are lots of metrics where this could make sense, and the list risks getting far too long.
The way I think this should work:

  1. There is one metric for toothbrushing.
  2. On the preview/confirm page, there are additional settings to refine exactly how the metric is logged. These are stored using additional attributes on the autodata key on the goal. The preview updates as these settings are changed.
  3. For toothbrushing in particular, this should be either "Aggregate Total Daily Minutes", or reporting each toothbrushing session as a separate data point with its number of minutes. People can count sessions via adjusting aggday.

Note this will require some tweaks to the sync code to allow multiple data points per day to be synced correctly. A while back the app started including requestid with these points to help facilitate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Customizing aggday is possible with a custom goal. A typical do more (hustler) goal type will have its how to aggregate the day set to sum.

category: HealthKitCategory.SelfCare)
}

override func recentDataPoints(days: Int, deadline: Int, healthStore: HKHealthStore) async throws -> [any BeeDataPoint] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than this, can probably just implement valueInAppropriateUnits

Copy link
Contributor Author

@krugerk krugerk Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was implemented for the purpose of specifying the healthkitMetric in the comment and yes, converting seconds to minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants