round 2: hr ceiling edge-motion fix + dedupe util helpers - #56
round 2: hr ceiling edge-motion fix + dedupe util helpers#56abdulsaheel wants to merge 1 commit into
Conversation
…ile helpers sessionHrCeiling averaged motion over the whole hold, which dilutes a real burst at the edges of an otherwise-quiet window right back below the gate. corroboration now checks a short trailing sub-window instead, so a burst anywhere in the hold still counts. also swapped a few hand-rolled median/stddev/percentile statics in advanced_stager, load_trimp and hr_zones for the shared util.dart helpers that already do the same math, and pointed the readme at the tool/ validation harnesses since nothing else mentioned they exist.
Reviewer's GuideThe PR fixes HR ceiling corroboration for edge-localized motion by scanning a bounded trailing sub-window, consolidates duplicated statistical helpers onto shared utilities, and documents the four real-corpus validation harnesses. Sequence diagram for trailing-window HR ceiling corroborationsequenceDiagram
participant Rows as HR and motion rows
participant Session as sessionHrCeiling
participant Candidate as Candidate hold
Rows->>Session: sessionHrCeiling(rows)
loop Each candidate start and bounded span
Session->>Candidate: Extend hold and update lo
Session->>Candidate: Add motion to trailing 3000 ms window
Candidate-->>Session: Remove samples outside trailing window
alt hold duration qualifies and trailing motion >= gate
Session->>Session: Record HrCeiling with full-hold motionG
Session-->>Rows: Accept corroborated ceiling
else motion gate not met
Session->>Candidate: Continue scanning within maxSpanMs
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="lib/src/onehz/workout/observed_max_hr.dart" line_range="176-188" />
<code_context>
count++;
+ trailSum += rows[j].motion;
+ trailCount++;
+ while (rows[j].ts - rows[trailStart].ts > corrobMs) {
+ trailSum -= rows[trailStart].motion;
+ trailCount--;
+ trailStart++;
+ }
final span = rows[j].ts - rows[i].ts;
if (span < holdMs) continue;
if (span > maxSpanMs) break; // gave this start its fair shot
// The window qualifies on duration. `lo` is the bpm sustained across
- // all of it. Only stop once the motion actually corroborates — that's
- // the earliest point extending further can only lower `lo` for no gain.
- final motion = motionSum / count;
- if (motion >= gate) {
+ // all of it. Only stop once a short burst of real motion actually
+ // corroborates it, checked against the trailing few seconds rather
+ // than the whole hold's average.
+ if (trailSum / trailCount >= gate) {
if (best == null || lo > best.bpm) {
best = HrCeiling(
</code_context>
<issue_to_address>
**issue (bug_risk):** A motion burst that occurs before the hold reaches `holdMs` is discarded before the candidate can qualify: the trailing window moves past it, and only the current trailing window is tested once `span >= holdMs`. A burst at the beginning or middle of a 15-second hold therefore produces no ceiling unless another burst occurs near the qualifying endpoint.
**Triggers:** When corroborating motion occurs only at the leading edge or middle of an otherwise-quiet hold.
**Suggested fix:** Track whether any trailing sub-window has crossed the motion gate and preserve that result until the duration threshold is reached, or evaluate the historical maximum trailing-window motion when the hold qualifies.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: lib/src/onehz/workout/observed_max_hr.dart:188
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| while (rows[j].ts - rows[trailStart].ts > corrobMs) { | ||
| trailSum -= rows[trailStart].motion; | ||
| trailCount--; | ||
| trailStart++; | ||
| } | ||
| final span = rows[j].ts - rows[i].ts; | ||
| if (span < holdMs) continue; | ||
| if (span > maxSpanMs) break; // gave this start its fair shot | ||
| // The window qualifies on duration. `lo` is the bpm sustained across | ||
| // all of it. Only stop once the motion actually corroborates — that's | ||
| // the earliest point extending further can only lower `lo` for no gain. | ||
| final motion = motionSum / count; | ||
| if (motion >= gate) { | ||
| // all of it. Only stop once a short burst of real motion actually | ||
| // corroborates it, checked against the trailing few seconds rather | ||
| // than the whole hold's average. | ||
| if (trailSum / trailCount >= gate) { |
There was a problem hiding this comment.
issue (bug_risk): A motion burst that occurs before the hold reaches holdMs is discarded before the candidate can qualify: the trailing window moves past it, and only the current trailing window is tested once span >= holdMs. A burst at the beginning or middle of a 15-second hold therefore produces no ceiling unless another burst occurs near the qualifying endpoint.
Triggers: When corroborating motion occurs only at the leading edge or middle of an otherwise-quiet hold.
Suggested fix: Track whether any trailing sub-window has crossed the motion gate and preserve that result until the duration threshold is reached, or evaluate the historical maximum trailing-window motion when the hold qualifies.
|
squashed into #59 for one clean review — closing this round. |
fixes from the round 2 audit pass:
ran the onehz test tree, all green.
Summary by Sourcery
Improve edge-motion corroboration for heart-rate ceiling detection and standardize statistical helper usage across the one-hertz analyzers.
Bug Fixes:
Enhancements:
Documentation:
Tests: