Skip to content

Fix browser-side worst_sleep always being 0 - #3

Merged
Meerav29 merged 1 commit into
masterfrom
fix/worst-sleep-null-seed
Oct 3, 2026
Merged

Meerav29 merged 1 commit into
masterfrom
fix/worst-sleep-null-seed

Conversation

@Meerav29

@Meerav29 Meerav29 commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Problem

In the browser-side summary computation, worst_sleep was reduce((a,b)=>Math.min(a,b), null). Math.min(null, x) coerces null to 0, so worst_sleep was always 0 for uploads parsed in the browser. best_sleep had the same null-seed pattern but was masked because sleep hours are positive.

Fix

  • Extract the summary computation into a pure computeSummaryStats(allDays) in index.html.
  • Compute min/max over non-null values only; return null when there is no sleep data.
  • avg* and best_steps_day were checked and don't have the bug.
  • parse_health.py compute_summary_stats was checked and is correct (filters None, returns None when empty).

Tests

node --test tests/js/summary_stats.test.mjs (extracts the function from index.html): [7, 6.5, 8] -> worst 6.5 / best 8, nulls ignored, empty/all-null -> null.

Note

Users who already uploaded keep the wrong worst_sleep = 0 in their stored summary until they re-upload.

🤖 Generated with Claude Code

Math.min(null, x) coerces null to 0, so the reduce seeded with null made
worst_sleep 0 for every upload parsed in the browser. Extract the summary
computation into computeSummaryStats() and compute min/max over the
non-null values, returning null when there is no sleep data. best_sleep had
the same null-seed pattern (only masked because values are positive) and
gets the same treatment. Add a node test that extracts the function from
index.html.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
somada Ready Ready Preview Oct 3, 2026 8:01pm UTC

@Meerav29
Meerav29 merged commit 87215d1 into master Oct 3, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2e1ba4cb Deployed Oct 3, 2026 by vercel[bot]
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