Skip to content

stress si: segment at gaps like cvhr does - #70

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/stress-si-gap-aware
Sep 19, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/stress-si-gap-aware

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

baevsky stress index had no gap-awareness - it just slides a 256-beat window over the raw nn array. a straddling window across a charging/off-wrist hole picks up the pre/post-gap RR jump as MxDMn, same failure mode cvhr_apnea.dart already fixed (its header even documents the 80.0/h -> 53.3/h bug this caused there).

adds optional nnTimesMs + maxGapSec (default 30s, same as cvhr) to baevskyStressIndex, segments at gaps before sliding the window, concatenates per-segment window stats before the median. no-times callers are byte-identical (single implicit segment).

test added mirroring cvhr's own gap regression test.

Summary by Sourcery

Segment Baevsky stress-index calculations at recording gaps before computing sliding-window statistics.

New Features:

  • Add optional beat-time inputs and configurable gap thresholds to make Baevsky stress index calculations gap-aware.

Bug Fixes:

  • Prevent sliding windows from crossing charging or off-wrist gaps and treating cross-gap RR discontinuities as within-segment variability.

Tests:

  • Add a regression test covering segmentation across a large gap and preserving the existing untimed behavior.

baevsky stress index had no way to tell a charging/off-wrist hole from
real physiology - it just slid a window over the raw nn array. a
straddling window picks up the pre/post-gap RR jump as MxDMn, same bug
class cvhr_apnea already fixed. add optional nnTimesMs + maxGapSec,
segment first, no-times callers unchanged.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @abdulsaheel, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 7 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 631b38e9-ded1-434f-baeb-ac8d4eb5fdbc

📥 Commits

Reviewing files that changed from the base of the PR and between 9db819b and 47847fa.

📒 Files selected for processing (2)
  • lib/src/onehz/clinical/stress_si.dart
  • test/onehz/clinical_test.dart

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Makes Baevsky stress index gap-aware by segmenting timestamped RR data before applying 256-beat sliding windows, preventing cross-gap RR jumps from inflating MxDMn while preserving untimed behavior; adds a regression test covering the charging-hole case.

Sequence diagram for gap-safe stress index calculation

sequenceDiagram
    participant Caller
    participant baevskyStressIndex
    participant Segmentation
    participant Windowing
    participant SI as _siOfSegment

    Caller->>baevskyStressIndex: baevskyStressIndex(nnMs, nnTimesMs, maxGapSec)
    baevskyStressIndex->>baevskyStressIndex: Filter RR intervals
    alt Valid nnTimesMs supplied
        baevskyStressIndex->>Segmentation: Detect timestamp gaps over maxGapSec
        Segmentation-->>baevskyStressIndex: Per-segment RR ranges
    else No valid timestamps
        baevskyStressIndex->>Segmentation: Use one implicit segment
    end
    loop Each segment and sliding window
        baevskyStressIndex->>Windowing: Create 256-beat window
        Windowing->>SI: _siOfSegment(segWin, minRangeMs)
        SI-->>Windowing: Window stress statistics
        Windowing-->>baevskyStressIndex: Collect statistics
    end
    baevskyStressIndex-->>Caller: Median StressIndex or absent metric
Loading

Flow diagram for gap-aware Baevsky stress index

flowchart TD
    A[RR intervals and optional timestamps] --> B[Filter RR intervals to 300-2000 ms]
    B --> C{Valid timestamps with gap over maxGapSec?}
    C -- No --> D[Use one implicit segment]
    C -- Yes --> E[Split into segments at gaps]
    D --> F[Apply 256-beat sliding windows]
    E --> F
    F --> G[Compute _siOfSegment for each window]
    G --> H[Aggregate window statistics and median]
    H --> I[Return StressIndex or absent metric]
Loading

File-Level Changes

Change Details Files
Add optional timestamp-based gap segmentation before Baevsky SI windowing.
  • Add nnTimesMs and configurable maxGapSec inputs, defaulting to 30 seconds.
  • Filter RR values while preserving corresponding timestamps, then split the data at detected gaps.
  • Compute window statistics independently per segment and combine them before taking the median.
  • Retain the existing single-segment behavior when timestamps are absent or length-mismatched.
lib/src/onehz/clinical/stress_si.dart
Add regression coverage for charging/off-wrist gaps between RR segments.
  • Build two stationary RR segments at different baselines with a two-minute timestamp gap.
  • Verify gap-aware SI remains within the range of the independently computed segment SIs.
  • Verify the legacy untimed path remains present and differs on the straddling-window fixture.
test/onehz/clinical_test.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@abdulsaheel
abdulsaheel merged commit 46b3f5f into main Sep 19, 2026
4 checks passed
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.

1 participant