Repository navigation
Fix browser-side worst_sleep always being 0 - #3
Merged
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the browser-side summary computation,
worst_sleepwasreduce((a,b)=>Math.min(a,b), null).Math.min(null, x)coercesnullto0, soworst_sleepwas always 0 for uploads parsed in the browser.best_sleephad the same null-seed pattern but was masked because sleep hours are positive.Fix
computeSummaryStats(allDays)inindex.html.nullwhen there is no sleep data.avg*andbest_steps_daywere checked and don't have the bug.parse_health.pycompute_summary_statswas checked and is correct (filtersNone, returnsNonewhen empty).Tests
node --test tests/js/summary_stats.test.mjs(extracts the function fromindex.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 = 0in their stored summary until they re-upload.🤖 Generated with Claude Code