Use timestamp windows for activity power curve - #1569
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
Asherlc has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
📝 WalkthroughWalkthroughThe activity power curve dbt model is reworked to compute duration windows from per-sample timestamp segments rather than fixed sample-rate assumptions, deriving a per-activity gap threshold and filtering candidate windows by elapsed time and max gap. A new integration test suite validates the read model against regular, gapped, and varying-power activity fixtures. ChangesTimestamp-based power curve windowing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Test
participant ActivitySensorStore
participant ClickHouse
participant ReadModelSQL
Test->>Test: insertActivity into fitness.activity
Test->>ClickHouse: insert powerSampleRows
Test->>ActivitySensorStore: sync
Test->>ReadModelSQL: query rendered activity_power_curve.sql
ReadModelSQL-->>Test: best_power, is_deleted
Assessment against linked issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Storybook previews for This comment updates automatically on each PR push. |
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Confidence score: 5/5
- Safe to merge after the addressed issues were fixed.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Replace naive avg(power) with timestamp-window-based arithmetic that correctly computes average power across each candidate duration window. The old query averaged sample power values which is incorrect when samples are irregularly spaced or when a moving window spans partial samples.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
Asherlc has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@analytics/models/read_models/activity_power_curve.sql`:
- Around line 124-126: The `avg_power` calculation in `activity_power_curve.sql`
is still based on sample count, so replace the
`window_sample.cumulative_sum`/`row_number_delta` formula with a time-weighted
average that uses the available duration information (for example,
`segment.segment_seconds` and/or elapsed time between samples) in the same
SELECT. Keep the change localized to the query expression that computes
`avg_power`, and verify the surrounding windowing logic still references the
correct symbols (`start_sample`, `window_sample`, `segment`) after switching
from count-weighting to time-weighting.
In
`@packages/server/src/routers/activity-power-curve-read-model.integration.test.ts`:
- Around line 168-198: The varying-power fixture in the activity power curve
integration test currently ends too early, so it never truly exercises the
5-second path in the activity power curve read model. Update the power sample
set built with powerSampleRows for varyingActivityId to include an
offsetSeconds: 5 sample, and then adjust the expected best_power in the rows
assertion to match the actual 5-second average produced by
activity_power_curve.sql and the rendered SQL query.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 6c22a49f-e1c1-4ff8-ac1d-2367a84bfa20
📒 Files selected for processing (2)
analytics/models/read_models/activity_power_curve.sqlpackages/server/src/routers/activity-power-curve-read-model.integration.test.ts
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Test seeds 6 samples over 5 seconds so the 5-second power curve window qualifies (elapsed_seconds >= duration_seconds). Also filter by activity_id to avoid picking up other test data.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
Asherlc has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
Re-trigger cubic
Replace count-based mean with time-weighted average using segment duration. The old formula (cumulative_sum / row_count) gave equal weight to each sample regardless of spacing. The new formula weights each sample by the time it was held (segment_seconds from power_segments), so irregularly-spaced data produces correct average power values. Simplifies GROUP BY by removing cumulative_sum, power, row_number from candidate_duration_windows since they're no longer needed.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
Asherlc has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
… segment cross-product in avg_power Each (start_sample, window_sample, duration) triple is now its own group, so segments are counted exactly once per window instead of being multiplied across all matching window_samples.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
Asherlc has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Requires human review: Changes core power curve calculation logic; requires human review to verify correctness and handling of edge cases.
Re-trigger cubic
Summary
Validation
Fixes #1532
Summary by cubic
Compute best-power using timestamp-based windows in
activity_power_curveand time-weighted average power for accurate results with irregular samples. Fixes Linear #1532.window_sample.row_number; add ClickHouse integration tests (regular, gapped, and 5s varying-power filtered byactivity_id).Written for commit 2e5e228. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests