Skip to content

sleep: tag each night observation with the window it was staged over - #110

Merged
abdulsaheel merged 1 commit into
mainfrom
feat/observation-bounds
Nov 16, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
feat/observation-bounds

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

a recorded night observation only carried its epoch count, so a caller that stages several sessions in one search window (the night it wants plus a longer session of the day before) could not tell which observation was which. edge picked the longest one, which can fold the wrong night into the rolling profile.

each observation now has startTsSec / endTsSec, the window it was staged over, from cardioStager (the accel timestamps) and from the epoch-rows path (the pooled runs). both are null when a caller does not know them, so nothing changes for existing callers.

Summary by Sourcery

Tag recorded sleep observations with their staging windows so callers can reliably match each observation to the intended night.

New Features:

  • Associate each recorded sleep observation with the start and end timestamps of the window used to stage it.

Bug Fixes:

  • Prevent callers from selecting the wrong night when multiple sessions with different lengths are staged in one search window.

Enhancements:

  • Preserve compatibility by leaving observation window timestamps unset when the staging source does not provide them.

Tests:

  • Add coverage confirming cardio-staged observations retain their source window timestamps.

Summary by CodeRabbit

  • New Features
    • Sleep observations now include optional start and end timestamps, helping identify the time span covered by each observation.

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

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

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add optional staged-window timestamps to each night observation so callers can identify which night it represents.

  • lib/src/onehz/sleep/cardio_stager.dart L341-349, L362-363

API

Extend the epoch-classification interface to accept the staged window timestamps.

  • lib/src/onehz/sleep/cardio_stager.dart L1013-1014

Uses of the API

Pass the pooled epoch-run bounds into classification on the epoch-rows path.

  • lib/src/onehz/sleep/epoch_rows.dart L559-561

Implementation

Derive the observation window from accelerometer timestamps and attach it when recording the observation.

  • lib/src/onehz/sleep/cardio_stager.dart L442-449, L1362-1363

Tests

Verify that an observation records the bounds of the accelerometer window staged by cardioStager.

  • test/onehz/sleep_user_profile_test.dart L117-138

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

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Sleep cardio observations now include optional start and end timestamps. The staging paths derive or pass window bounds to the classifier, and a test checks the recorded timestamps.

Changes: Sleep observation time bounds

Layer / File(s) Summary
Pass staged-window bounds
lib/src/onehz/sleep/cardio_stager.dart, lib/src/onehz/sleep/epoch_rows.dart, test/onehz/sleep_user_profile_test.dart
SleepNightObservation and classifyCardioEpochs now support optional start and end timestamps. cardioStager derives bounds from acceleration timestamps, using floor for the start and ceiling for the end; empty or non-finite bounds are null. EpochRows.stageWindow passes the first and last selected run bounds, or null when no runs are selected. The test checks the observation’s recorded endpoints.

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

Change: Feature

Suggested reviewers: mikenrafter, sourcery-ai

Merge Risk: Minimal · up to 24317

This change records optional start and end timestamps on night observations. Existing callers keep their current behavior because both values default to null. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: each night observation is now tagged with the window over which it was staged. The raw summary confirms new startTsSec and endTsSec fields on SleepNightObservation, de…
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.
Full details: Title check

Explanation

The title names the main change: each night observation is now tagged with the window over which it was staged. The raw summary confirms new startTsSec and endTsSec fields on SleepNightObservation, derived in cardioStager and passed from EpochRows.stageWindow. The title is short, specific, and matches the changeset and the PR objectives.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1057ccc3-81ec-4679-8e09-a77b9a9b23c1
Commits

Reviewing files that changed from the base of the PR and between 614a48e and 2431763.

Files selected for processing: 3

  • lib/src/onehz/sleep/cardio_stager.dart
  • lib/src/onehz/sleep/epoch_rows.dart
  • test/onehz/sleep_user_profile_test.dart

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

@abdulsaheel
abdulsaheel merged commit a438df4 into main Nov 16, 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