Skip to content

feat(measurements): import Apple workout effort and physical effort - #1416

Closed
camiracode wants to merge 3 commits into
MBombeck:mainfrom
camiracode:cursor/apple-health-effort-scores-8f55
Closed

camiracode wants to merge 3 commits into
MBombeck:mainfrom
camiracode:cursor/apple-health-effort-scores-8f55

Conversation

@camiracode

@camiracode camiracode commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Apple Health workout effort and physical effort were in the deferred set, so an import skipped them. They are stored as their own measurement types now. The logged workout effort score and the watch’s estimate are separate 0–10 score types, so a day mean never blends them. Physical effort is kept as a rate in kcal/(hr·kg), and is not added to active or resting energy. Existing rows are unchanged.

Type of change

  • New feature (non-breaking change that adds functionality)
  • Bug fix (non-breaking change that fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only
  • Test / CI / tooling
  • Refactor (no functional change)

Apple types

HealthKit identifier Measurement type Stored unit Range Aggregation
HKQuantityTypeIdentifierWorkoutEffortScore (iOS 18) WORKOUT_EFFORT_SCORE score 0–10 mean
HKQuantityTypeIdentifierEstimatedWorkoutEffortScore (iOS 18) ESTIMATED_WORKOUT_EFFORT_SCORE score 0–10 mean
HKQuantityTypeIdentifierPhysicalEffort (iOS 17) PHYSICAL_EFFORT kcal/(hr·kg) 0–50 mean

The HealthKit unit for the scores is count. The HealthKit unit for physical effort is kcal/(hr*kg); there is no sibling unit to convert from. Apple’s published effort scale is 1–10. The stored band starts at 0 so a zero is kept, and stops at 10 so a slipped unit is refused.

The logged score and the estimate are two types. Samples stay distinct by their own external ids. Neither type is summed into a day total, and neither has a personal-record direction.

Workout effort follows the workouts module. Physical effort stays ungated, like active energy: it is an intensity sample, not a workout session.

CHANGELOG.md is left out; the release commit writes it.

Migration

0514_apple_health_effort (rebased on main after 0513) adds WORKOUT_EFFORT_SCORE, ESTIMATED_WORKOUT_EFFORT_SCORE and PHYSICAL_EFFORT to measurement_type with ADD VALUE IF NOT EXISTS, in one DO block with the lock-timeout marker. No rows are rewritten. PostgreSQL cannot drop an enum value, so there is no down migration.

Test plan

  • pnpm typecheck
  • pnpm lint (changed sources)
  • pnpm test (unit). Mapping fixture: src/lib/measurements/__tests__/fixtures/apple-health-effort-samples.json.
  • pnpm openapi:generate (spec committed)
  • pnpm test:integration — tests/integration/apple-health-effort-ingest.test.ts covers the batch route, acceptedTypes, a backup round-trip, and out-of-range skips. Not run in the environment that prepared this branch (no Docker).

Screenshots (UI changes only)

No screen changes beyond the existing measurement list, charts, and report selection picking up two new activity types.

Checklist

  • Targets the main branch (trunk-based — see CONTRIBUTING.md)
  • pnpm typecheck passes locally
  • pnpm lint passes locally
  • pnpm test passes locally
  • pnpm format:check passes locally
  • pnpm build passes locally (not run for this branch)
  • User-facing strings go through t("key") with both messages/en.json and messages/de.json updated (and the other shipped locales)
  • No secrets, personal data, or maintainer-name references in committed files
  • Updated CHANGELOG.md if user-visible
  • Updated docs/integrations/apple-health.md and docs/integrations/data-import.md

Linked issues

None.

@MBombeck

MBombeck commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

@camiracode Thanks, this is a careful piece of work. A few things before it can go in:

  1. Migration number. Main now has 0510_symptom_apple_health_ingest and 0511_apple_health_v2_types from 1.48.2. The next patch takes 0512 and 0513, so please rebase on main and rename yours to 0514_…, written like the recent migrations (the DO block and the lock-timeout marker), so migration-lock-timeout-guard.test.ts passes.
  2. CHANGELOG.md. Please leave it out; the release commit writes it, and the hunk will conflict.
  3. Logged score vs. the watch's estimate. Both land in one type, so a workout that has both gets a day mean that blends them. Either give the estimate its own type, or keep the logged score when both exist. I'd lean toward two types, since they mean different things.
  4. Integration test. If you can't run it locally, that's fine, CI will once I approve the runs after the rebase.

I'll merge it by hand afterwards so the branch name doesn't end up in the history.

The logged workout-effort score and the watch's estimate are separate
types, so a day mean of one cannot blend the other. Physical effort is
its own rate in kcal/(hr·kg), never added to energy. Migration 0514 adds
the three enum values inside a lock-bounded DO block.

Co-authored-by: Cambreo, LLC <[email protected]>
@camiracode
camiracode force-pushed the cursor/apple-health-effort-scores-8f55 branch from 723d52d to 9408940 Compare November 20, 2026 01:45
@camiracode

Copy link
Copy Markdown
Contributor Author

@MBombeck Thanks for the review. All four are addressed: rebased on main (after 0513), migration renamed to 0514_apple_health_effort with the DO block and lock-timeout marker (migration-lock-timeout-guard, migration-number-uniqueness pass), CHANGELOG.md dropped, and the watch's estimate now has its own type ESTIMATED_WORKOUT_EFFORT_SCORE so it never blends with the logged score. Unit tests and typecheck pass; the new integration test apple-health-effort-ingest.test.ts is ready for CI. The description is updated to match.

@MBombeck

Copy link
Copy Markdown
Owner

@camiracode Thanks, the rebase and the four points look good. CI ran now and one integration test fails, in tests/integration/apple-health-effort-ingest.test.ts (around line 143):

orderBy: { type: "asc" } sorts a Postgres enum by its declaration order in the schema, not alphabetically. WORKOUT_EFFORT_SCORE is declared before ESTIMATED_WORKOUT_EFFORT_SCORE, so the rows come back as WORKOUT, ESTIMATED, PHYSICAL and the toEqual misses. Sorting the mapped rows by type in the test (or comparing with expect.arrayContaining plus a length check) fixes it. Everything else in the shard passed.

camiracode and others added 2 commits November 20, 2026 09:55
PostgreSQL orders an enum column by declaration order, not alphabetically, so the ingest test sorts the stored rows by type name before comparing. Fixes the integration shard 3/4 failure.
@MBombeck

Copy link
Copy Markdown
Owner

@camiracode Thanks, the sort fix does it. After 1.48.4 the branch had a one-line conflict in the function-size baseline, so I merged main into it; CI is green now. This goes into the next release together with migration 0514.

MBombeck added a commit that referenced this pull request Nov 21, 2026
…cores-8f55

# Conflicts:
#	src/__tests__/baselines/source-function-lines.json
@MBombeck MBombeck mentioned this pull request Nov 21, 2026
@camiracode camiracode closed this by deleting the head repository Nov 23, 2026
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.

3 participants