Skip to content

fix: IS divisor uses populated hour-bins instead of epochsPerDay - #67

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/is-divisor-epochsperday
Sep 19, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/is-divisor-epochsperday

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

found this while going through the circadian stuff. _nonparam's IS calc divides profVar by profile.length (count of hour-of-day bins that have at least one sample) instead of the fixed epochsPerDay. circadian_np.dart already does this right with p = epochsPerDay.

the bug only shows up when some hour-of-day is never sampled across the whole window, e.g. charging at the same hour every day (this file's own header calls that scenario out). that hour gets dropped from profile, profile.length < epochsPerDay, and IS gets inflated by epochsPerDay/profile.length. when every hour has a sample it's a no-op since profile.length == epochsPerDay, which is why it's been hiding.

added a test with 14 days of hourly data and hour 3 permanently missing. confirmed it fails on the old code (1.0 clamped) and passes on the fix (0.9583, matches the predicted 24/23 inflation factor).

Summary by Sourcery

Fix nonparametric interdaily stability normalization for sampling windows with missing hour-of-day bins.

Bug Fixes:

  • Correct the nonparametric interdaily stability calculation to normalize profile variance by the fixed number of epochs per day, preventing inflated values when hour-of-day bins are permanently unpopulated.

Tests:

  • Add a regression test covering a permanently missing hour-of-day bin and verifying the corrected interdaily stability value.

Summary by CodeRabbit

  • Bug Fixes

    • Improved circadian stability calculations when certain hours lack samples, preventing inflated stability scores.
    • Corrected results for datasets with recurring gaps at specific times of day.
  • Tests

    • Added coverage for circadian stability calculations with consistently missing hourly data.

phase-locked missing data (charging at the same hour every day) leaves
a hour-of-day bin permanently unsampled, so profile.length < epochsPerDay
and the old profVar/profile.length divisor inflated interdailyStability
by epochsPerDay/profile.length. matches circadian_np.dart's p=epochsPerDay.

@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 8 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: c2e01aae-191e-4315-9329-0d9c50203128

📥 Commits

Reviewing files that changed from the base of the PR and between def6999 and be6cfc6.

📒 Files selected for processing (2)
  • lib/src/onehz/wellness/temp_circadian.dart
  • test/onehz/wellness_test.dart

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The interdaily-stability calculation now divides profile variance by epochsPerDay. A regression test covers a permanently unpopulated hour-of-day bin and verifies the expected stability value.

Changes

Circadian stability calculation

Layer / File(s) Summary
Normalize IS variance and validate missing bins
lib/src/onehz/wellness/temp_circadian.dart, test/onehz/wellness_test.dart
The calculation uses epochsPerDay instead of the populated profile length. The test covers 14 days with one missing hourly bin and expects an IS value near 0.9583.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: correcting the IS divisor from populated hour-bins to the fixed epochsPerDay value.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Fixes nonparametric interdaily stability normalization by dividing profile variance by fixed epochsPerDay rather than the number of populated hour bins, with regression coverage for phase-locked sampling gaps.

Flow diagram for fixed epochs-per-day IS normalization

flowchart TD
    A["Hourly samples across analysis window"] --> B["Build hour-of-day profile"]
    B --> C["One hour bin is permanently unpopulated"]
    C --> D["Compute profile variance"]
    D --> E["Divide by fixed epochsPerDay"]
    E --> F["Calculate interdaily stability"]
Loading

File-Level Changes

Change Details Files
Correct IS normalization to use the fixed number of daily epochs.
  • Replace the populated-bin count divisor with epochsPerDay.
  • Align the normalization with the existing circadian implementation and prevent phase-locked sampling gaps from inflating IS.
lib/src/onehz/wellness/temp_circadian.dart
Add regression coverage for permanently missing hour-of-day bins.
  • Generate 14 days of hourly samples with hour 3 consistently absent.
  • Assert the corrected IS is below the prior clamp-to-1 result and matches the expected value near 0.9583.
test/onehz/wellness_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 2ed09d2 into main Sep 19, 2026
4 checks passed
abdulsaheel added a commit that referenced this pull request Sep 19, 2026
…not raw span (#68)

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.
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