Skip to content

feat(today): gate lookback card on collected-data span#143

Merged
abdulsaheel merged 2 commits into
OpenStrap:mainfrom
dannymcc:fix/lookback-data-gate
Jul 24, 2026
Merged

feat(today): gate lookback card on collected-data span#143
abdulsaheel merged 2 commits into
OpenStrap:mainfrom
dannymcc:fix/lookback-data-gate

Conversation

@dannymcc

@dannymcc dannymcc commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What

The Lookback / "Your day" card on the Today screen appeared immediately, even with only minutes of collected data, so on first run it was empty and misleading.

This gates the card's appearance on having a meaningful span of collected data (~a full day). Below the threshold the card is hidden cleanly — no empty "No data yet today" placeholder.

How

  • Data-span signal: the span from the earliest decoded record (MIN(rec_ts) via the existing LocalDb.firstAndLastRecordTs()) to now, loaded best-effort in fetch() and held in _dataSpanHours.
  • Threshold: a documented, tunable const kLookbackMinDataHours = 18 (localhoop's lower bound for a meaningful day; the ~18–24h band).
  • Gate: a pure, testable helper shouldShowLookback(double? dataSpanHours) wraps the card's collection-if in _content(). Null span (no data yet) → hidden.

Scope is deliberately just the card's appearance on the Today screen — this does not touch journey_screen.dart (day-navigation inside the JourneyScreen is a separate concern).

Tests

Added test/lookback_gate_test.dart covering the gate helper: null/minutes-of-data → hidden, just-below threshold → hidden, at/above threshold → shown, and that the threshold sits in the documented ~18–24h band.

No Flutter/Dart SDK was available in this environment, so the change is inspection-verified; the pure-helper tests are provided for CI to run.

Closes #140
Reported in #102.

Summary by CodeRabbit

  • New Features

    • The “Lookback / Your day” card now appears only after enough activity data has been collected.
    • The card remains hidden when no data, limited first-run data, or insufficient history is available.
  • Bug Fixes

    • Prevented the Lookback card from appearing prematurely with incomplete daily data.
  • Tests

    • Added coverage for empty, insufficient, threshold, and sufficient data scenarios.

The Lookback / "Your day" card appeared immediately on the Today screen,
even with only minutes of data, so it was empty and misleading on first
run (OpenStrap#140, reported in OpenStrap#102).

Gate its visibility on the span of collected data — from the earliest
decoded record (MIN(rec_ts)) to now — loaded best-effort in fetch() and
compared against a documented, tunable threshold (kLookbackMinDataHours,
~18h, localhoop's lower bound for a meaningful day). Below the threshold
the card is hidden entirely rather than rendering a bare "No data yet"
placeholder. The gate is a pure helper (shouldShowLookback) with tests.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@dannymcc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 72b89cd1-574c-4cdc-80e3-375c63058b2c

📥 Commits

Reviewing files that changed from the base of the PR and between 7cecde9 and f3e3304.

📒 Files selected for processing (2)
  • lib/ui/today/today_screen.dart
  • test/lookback_gate_test.dart
📝 Walkthrough

Walkthrough

TodayScreen now computes the collected-data span during fetch() and displays the Lookback card only when that span reaches the configured minimum. A dedicated test suite covers null, insufficient, boundary, and threshold-configuration cases.

Changes

Lookback visibility

Layer / File(s) Summary
Compute data span and gate Lookback
lib/ui/today/today_screen.dart, test/lookback_gate_test.dart
TodayScreen derives _dataSpanHours, defines an 18-hour shouldShowLookback threshold, conditionally renders the Lookback card, and tests null, insufficient, boundary, and configured-threshold behavior.

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

Suggested reviewers: abdulsaheel

🚥 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 is concise and accurately reflects gating the Lookback card on collected-data span.
Linked Issues check ✅ Passed The change hides the Lookback panel until collected data reaches about 18 hours, matching issue #140.
Out of Scope Changes check ✅ Passed The PR stays focused on Today-screen lookback gating and related tests, with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/ui/today/today_screen.dart`:
- Around line 141-153: The `_dataSpanHours` value is only recomputed during
`fetch()`, so it becomes stale when decoded data changes. Update the
decoded-count change handling to recompute the same first-record-to-now span
used in `fetch()` whenever counts change, or invoke a shared refresh helper from
that path, while preserving the existing mounted `setState` behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c7ad5589-8929-4c70-9670-8d3c263cfa8d

📥 Commits

Reviewing files that changed from the base of the PR and between 533d110 and 7cecde9.

📒 Files selected for processing (2)
  • lib/ui/today/today_screen.dart
  • test/lookback_gate_test.dart

Comment thread lib/ui/today/today_screen.dart
Store the earliest record timestamp rather than a span precomputed in
fetch(), and derive `now - earliest` in the build path. The card now
appears as soon as the collected span crosses kLookbackMinDataHours by
elapsed wall-clock time, instead of waiting for the next loader refresh
to recompute the span (CodeRabbit, OpenStrap#143).

shouldShowLookback takes the earliest timestamp plus a live `now`; the
test drives the "just crossed 18h on the clock alone" case.
@abdulsaheel
abdulsaheel merged commit 756696e into OpenStrap:main Jul 24, 2026
1 check 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.

Lookback "Your day" panel should only appear once there's ~18–24h of data

2 participants