Skip to content

fix: relativeOdi denominators dilute on contact-loss dropouts - #68

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/relative-odi-analyzed-hours
Sep 19, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/relative-odi-analyzed-hours

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

odiPerHour and burdenPct in relativeOdi() were dividing by the raw wall-clock span, not by time that actually produced a usable ratio-of-ratios sample. dcRed==0/dcIr==0/rIr<=0 turn part of relR into NaN on a contact-loss dropout (arm tucked, band shifted), and that gap was still charged to analyzedHours/spanSec, so the rate gets diluted downward instead of reported over the monitored time.

same shape as the IS fix in #67, and cvhr_apnea.dart in this same family already builds analyzedHours only from segments with usable data for exactly this reason.

fix scales analyzedHours/spanSec by trustedCoverage (the already-computed fraction of non-NaN ratio samples) before the odiPerHour/burdenPct divisions. trustedCoverage itself is unchanged, still reported as-is.

not wired into edge yet so no caller-visible behavior change, just fixes the metric before anything starts consuming it.

Summary by Sourcery

Calculate relative ODI rates and burden over trusted monitored time rather than the full wall-clock span.

Bug Fixes:

  • Prevent relative ODI rate and burden metrics from being diluted by contact-loss periods that do not produce usable ratio samples.

Enhancements:

  • Report relative ODI analyzed time using trusted sample coverage while preserving the existing trusted coverage value and reporting.

…not raw span

same bug shape as the IS fix (#67). a contact-loss dropout (arm tucked,
band shifted) turns part of the ratio-of-ratios NaN, but odiPerHour and
burdenPct still divided by the full wall-clock span, diluting the rate
instead of reporting it over the time that actually had usable samples.
now scales the denominator by trustedCoverage, same idea cvhr_apnea.dart
already uses.

@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 38 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: 414d249a-af28-4043-a4ac-3c9fa42c635f

📥 Commits

Reviewing files that changed from the base of the PR and between 2ed09d2 and 0b2c182.

📒 Files selected for processing (1)
  • lib/src/onehz/respiration/relative_odi.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 (collapsed on small PRs)

Reviewer's Guide

Corrects relative ODI rate and burden calculations so unusable ratio-of-ratios samples from contact-loss dropouts do not dilute results; the change is isolated to metric computation and is not yet wired into edge callers.

Flow diagram for trusted relative ODI denominator calculation

flowchart TD
    A[relR ratio-of-ratios samples] --> B{Sample is usable}
    B -->|yes| C[trustedCoverage]
    B -->|no: NaN| C
    C --> D[validSpanSec = spanSec * trustedCoverage]
    D --> E[validHours = validSpanSec / 3600]
    E --> F[odiPerHour = dipCount / validHours]
    D --> G[burdenPct = totalDipSec / validSpanSec]
    C --> H[trustedCoverage reported unchanged]
Loading

File-Level Changes

Change Details Files
Use trusted ratio-sample coverage to exclude contact-loss gaps from rate and burden denominators.
  • Count NaN relative-ratio samples and derive trusted coverage.
  • Scale the wall-clock span by trusted coverage to compute valid analyzed hours.
  • Use the coverage-adjusted duration for odiPerHour, analyzedHours, and burdenPct while preserving trustedCoverage reporting.
lib/src/onehz/respiration/relative_odi.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 9f82ccf into main Sep 19, 2026
4 checks passed
abdulsaheel added a commit that referenced this pull request Sep 19, 2026
…nflict

combined #68's per-sample trustedCoverage scaling with #69's gap
segmentation: each segment now computes its own trustedCoverage and
scales its own hours contribution before summing into analyzedHours,
instead of one global scale applied after the fact. odiPerHour and
burdenPct both key off that combined analyzedHours.
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