Skip to content

Stress Nerd Stats: show the index, level and score behind the score - #632

Merged
abdulsaheel merged 4 commits into
OpenStrap:mainfrom
Riedel-David:feat/store-stress-si
Oct 31, 2026
Merged

abdulsaheel merged 4 commits into
OpenStrap:mainfrom
Riedel-David:feat/store-stress-si

Conversation

@Riedel-David

@Riedel-David Riedel-David commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Stress Nerd Stats now shows the index, level and score behind the stress score.

A score clamped to 0 gave no hint why. The stored stress block has the unclamped facts: the Baevsky index (SI), the level and the score. This reads them from the viewed day's own payload and shows them as a "Stress index" table. The payload is decoded in an isolate.

  • No schema change, no new series key (stress_si stays absent on purpose), no kAlgoVersion bump, and no change to how stress is computed.
  • Rows with absent or non-finite values are dropped rather than shown as 0. An unknown level token is hidden. A payload that will not decode gives no table, not a failed screen.
  • Strings added in all 7 languages.

Part of #631. This only makes the cause visible. The score still reads 0 when SI is below 20; the follow-up discussed in the issue is a baseline-relative score.

Tests: test/investigate_stress_index_test.dart (widget) and test/investigate_stress_load_test.dart (DB load path). low_readiness_* and health_workout_export_delete_gate_test also fail on main and are unrelated.

Summary by Sourcery

Expose the underlying stress index and level so users can understand the score shown for a viewed day.

New Features:

  • Show the viewed day's Baevsky stress index, level, and score alongside the stress metric.

Bug Fixes:

  • Preserve stress investigation screen loading when the day's payload is malformed or contains missing, non-finite, or unknown stress values.

Enhancements:

  • Read stress details from the viewed day's own payload without changing stress computation or the data schema.
  • Localize the new stress index table across all supported languages.

Tests:

  • Add widget and database-load coverage for stress detail display, localization, day-specific payload selection, invalid values, imports, and malformed payloads.

Summary by CodeRabbit

  • New Features
    • Investigation details now show the stress index, recognized stress level, and score on a 0–100 scale when available.
    • Stress details are localized in English, German, Spanish, French, Hindi, Russian, and Chinese.
    • Unavailable or unrecognized stress values are shown as dashes.

A score clamped to 0 left nothing on screen to say why. The index and level are
the unclamped facts; read from the viewed day's own payload, no new series key.
@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR adds a localized Stress index table to Nerd Stats by decoding each viewed day’s own stress payload off the UI isolate, without changing stress computation, schema, series keys, or algorithm version; it also hardens missing-data handling and adds widget/database-path tests.

Sequence diagram for loading and displaying viewed-day stress facts

sequenceDiagram
    participant User
    participant Investigate as InvestigateScreen
    participant Load as InvestigateData.load
    participant Isolate
    participant DB as LocalRepository

    User->>Investigate: Open stress Nerd Stats
    Investigate->>Load: load(repo, stress, day)
    Load->>DB: Read viewed day payload_json
    DB-->>Load: payload_json
    Load->>Isolate: Isolate.run(_stressFacts(payload))
    Isolate->>Isolate: jsonDecode(payload)
    Isolate-->>Load: stress block, imported, source
    Load-->>Investigate: InvestigateData(stress)
    Investigate->>Investigate: _stressPanels(context, data)
    Investigate-->>User: Localized Stress index table
Loading

Flow diagram for stress index table data handling

flowchart TD
    A[Viewed day stress payload] --> B{Payload decodes?}
    B -- No --> C[Show no stress table]
    B -- Yes --> D{Finite SI present?}
    D -- No --> C
    D -- Yes --> E[Show Index SI]
    E --> F[Show localized known level or dash]
    E --> G[Show finite score or dash]
    F --> H[Stress index table]
    G --> H
Loading

File-Level Changes

Change Details Files
Expose the unclamped stress facts behind the displayed score in the stress investigation view.
  • Read the viewed day’s stress block directly from its payload, rather than using substitute/latest-day data.
  • Decode the payload in an isolate and tolerate malformed payloads by omitting the optional table.
  • Render SI, localized level, and score while dropping absent or non-finite values and hiding unknown levels.
  • Add localized labels for the stress index table and stress-level bands across all supported languages.
lib/ui2/screens/investigate.dart
lib/l10n/display_text.dart
lib/l10n/app_de.arb
lib/l10n/app_en.arb
lib/l10n/app_es.arb
lib/l10n/app_fr.arb
lib/l10n/app_hi.arb
lib/l10n/app_ru.arb
lib/l10n/app_zh.arb
Centralize stress-level localization for reuse across wellness and investigation screens.
  • Move the stress-level token mapper into shared display-text localization helpers.
  • Update the wellness screen to use the shared mapper.
lib/l10n/display_text.dart
lib/ui2/screens/wellness_screen.dart
Add coverage for stress-index rendering and payload-loading behavior.
  • Test clamped scores, formatting, localization, missing/non-finite fields, invalid levels, and absent stress blocks.
  • Verify viewed-day isolation, imported metadata handling, key-specific loading, and malformed-payload resilience.
test/investigate_stress_index_test.dart
test/investigate_stress_load_test.dart

Possibly linked issues


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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: OpenStrap/edge
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 0900983
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3cf6e5dd-1c21-4f6b-8f9d-c7d35633c993
Commits

Reviewing files that changed from the base of the PR and between 7baeecc and 66566c1.

Files ignored due to path filters: 2
  • test/investigate_stress_index_test.dart is excluded by !test/**
  • test/investigate_stress_load_test.dart is excluded by !test/**
Files selected for processing: 8
  • lib/l10n/app_de.arb
  • lib/l10n/app_en.arb
  • lib/l10n/app_es.arb
  • lib/l10n/app_fr.arb
  • lib/l10n/app_hi.arb
  • lib/l10n/app_ru.arb
  • lib/l10n/app_zh.arb
  • lib/ui2/screens/investigate.dart

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

Walkthrough

The investigation screen now loads stress-index data for the stress metric and displays its index, level, and score. Seven localization files provide labels for these details.

Changes: Stress details and localization

Layer / File(s) Summary
Load stress details
lib/ui2/screens/investigate.dart
The screen decodes stress data and import metadata in an isolate and passes the stress map through InvestigateData.
Display and localize stress details
lib/ui2/screens/investigate.dart, lib/l10n/app_{de,en,es,fr,hi,ru,zh}.arb
The screen displays finite SI values, recognized stress levels, and finite scores. The localization files add labels for the stress section and its values.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant InvestigateScreen
  participant Isolate
  participant InvestigateData
  InvestigateScreen->>Isolate: Decode stress payload and import metadata
  Isolate-->>InvestigateScreen: Return stress facts
  InvestigateScreen->>InvestigateData: Store loaded stress map
Loading

Suggested reviewers: abdulsaheel

Merge Risk: Minimal · up to 66566

The stress details are ready to merge after normal checks.

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: the Stress Nerd Stats section now shows the Baevsky stress index, the stress level, and the 0-100 score. The raw summary confirms that the investigate screen now displ…
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: the Stress Nerd Stats section now shows the Baevsky stress index, the stress level, and the 0-100 score. The raw summary confirms that the investigate screen now displays these rows, and the PR objectives state the same goal. The title is specific and matches the changeset.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • 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

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="lib/ui2/screens/investigate.dart" line_range="178" />
<code_context>
+      // An optional side table: a payload that will not decode is an absent
+      // table, not a screen that fails to load.
+      try {
+        final f = await Isolate.run(() => _stressFacts(payload));
+        stress = (f['stress'] as Map).cast<String, dynamic>();
+        if (f['imported'] == true) {
</code_context>
<issue_to_address>
**Stress facts bypass repository seam**

When the investigation screen loads the `stress` key for a day with a payload, `InvestigateData.load` decodes the viewed day’s payload through `_stressFacts` in the screen layer, so the new stress shape is built outside the repository read seam.

Move the viewed-day stress extraction behind the `LocalRepositoryImpl` read seam and have `InvestigateData.load` consume that screen-ready shape.
</issue_to_address>

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread lib/ui2/screens/investigate.dart Resolved
@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@abdulsaheel
abdulsaheel merged commit 797a9a4 into OpenStrap:main Oct 31, 2026
3 checks passed
@Riedel-David
Riedel-David deleted the feat/store-stress-si branch October 31, 2026 09:58
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.

2 participants