feat(polar): ✨ adding Polar Flow #52#134
Open
dvorka wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Polar Flow integration to MyTraL, covering both incremental sync of newly recorded exercises via Polar AccessLink (transaction model) and historical backfill via the Polar GDPR export ZIP, integrated into the UI, background tasks, and import plugin architecture.
Changes:
- Added Polar Flow AccessLink API client + OAuth flow, plus tasks to sync new activities and purge/re-sync.
- Added Polar GDPR export ZIP parser + import task, wired into Tools > Import UI.
- Added activity-type mapping for Polar sports, feature-flag gating, and a test suite covering credentials, rate limiting, transaction semantics, import mapping, and dedup.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_tool_polar_flow.py | New tests for Polar Flow client/task utilities (credentials, rate-limit backoff, transaction behavior, dedup). |
| tests/test_plugin_import_polar_flow.py | New tests validating plugin mappings for API summaries and GDPR export sessions. |
| mytral/templates/tools-import.html | Adds Polar Flow as an import source plus GDPR export ZIP upload UI (feature-flagged). |
| mytral/templates/polar-flow-secrets.html | New page for configuring Polar Flow client credentials. |
| mytral/templates/polar-flow-developer.html | New developer dashboard for Polar Flow auth status and sync actions. |
| mytral/templates/layout.html | Adds a Polar Flow navbar shortcut icon when feature-flagged and configured. |
| mytral/tasks/do/polar_flow_sync.py | New background task to sync newly available Polar exercises via transactions. |
| mytral/tasks/do/polar_flow_resync_all.py | New background task to purge all Polar-sourced activities and re-pull from AccessLink. |
| mytral/tasks/do/polar_flow_export_import.py | New background task to import historical data from a GDPR export ZIP. |
| mytral/tasks/do/polar_flow_commons.py | Shared sync/pull utilities including recording import and cross-channel dedup. |
| mytral/settings.py | Extends UserProfile persistence model to store Polar Flow credentials/linking fields. |
| mytral/run.py | Registers the new Polar Flow URI space blueprint in the server entrypoint. |
| mytral/run_desktop.py | Registers the new Polar Flow URI space blueprint in the desktop entrypoint. |
| mytral/releng.py | Adds POLAR_FLOW_IMPORT feature flag (default off). |
| mytral/integrations/polar_flow.py | New Polar AccessLink client + OAuth helpers + import plugins for API summaries. |
| mytral/integrations/polar_flow_export.py | New GDPR export ZIP/directory parser that normalizes sessions to AccessLink-like summaries. |
| mytral/integrations/icommons.py | Adds Polar sport-to-activity-type mapping helper. |
| mytral/forms.py | Adds forms for Polar secrets configuration and GDPR export ZIP upload + conflict strategy. |
| mytral/blueprints/polar_flow_uri_space.py | New Polar Flow routes for secrets, auth, sync, resync, and export import task submission. |
| mytral/blueprints/import_uri_space.py | Wires the new Polar export form into the import page rendering context. |
| docs/ARCHITECTURE.md | Updates architecture docs to include Polar Flow as an external integration. |
| CREDITS.md | Adds attribution for Polar AccessLink example repo used as a reference. |
| CHANGELOG.md | Adds release notes describing the new Polar Flow integration and feature flag. |
Comment on lines
+111
to
+114
| if flask.request.method == "POST" and form.validate_on_submit(): | ||
| user_profile.polar_flow_client_id = form.client_id.data.strip() | ||
| user_profile.polar_flow_client_secret = form.client_secret.data.strip() | ||
| ds.update_profile(user_profile) |
Comment on lines
+259
to
+264
| logger.debug("Polar auth-code exchange succeeded") | ||
| user_profile.polar_flow_access_token = str(tokens["access_token"]) | ||
| if tokens.get("x_user_id"): | ||
| user_profile.polar_flow_user_id = str(tokens["x_user_id"]) | ||
| ds.update_profile(user_profile) | ||
|
|
Comment on lines
+33
to
+35
| <p class="mb-0"> | ||
| Your secrets are stored encrypted on disk and are <strong>never</strong> displayed again after saving. | ||
| </p> |
| ## External Integrations & Plugins | ||
|
|
||
| MyTraL integrates with external ecosystems through `integrations/*` and `plugins.py`, including Strava and other import/sync sources used by both direct import routes and background tasks. This component adapts third-party payloads to internal entities so downstream analytics and UI features remain consistent. | ||
| MyTraL integrates with external ecosystems through `integrations/*` and `plugins.py`, including Strava, Polar (both the legacy Precision Performance `.hrm`/`.pdd` files and Polar Flow via the AccessLink API plus the GDPR data export ZIP), and other import/sync sources used by both direct import routes and background tasks. This component adapts third-party payloads to internal entities so downstream analytics and UI features remain consistent. See `POLAR_FLOW.md` for the Polar Flow design. |
Comment on lines
+11
to
+16
| - Added a Polar Flow integration: sync new training from Polar Flow | ||
| (flow.polar.com) via the official Polar AccessLink API (transaction model, no | ||
| duplicates), and backfill full history from the Polar "Download your data" | ||
| (GDPR) export ZIP. Gated behind the `MYTRAL_FF_POLAR_FLOW_IMPORT` feature flag. | ||
| See `POLAR_FLOW.md` for the design and setup steps. This is separate from the | ||
| existing Polar Precision Performance (.hrm/.pdd) import. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR brings Polar Flow integration.
Related: