fix(analytics): normalize weight units (kg/lbs) in exercise stats - #227
Open
evan188199-tech wants to merge 1 commit into
Open
evan188199-tech wants to merge 1 commit into
evan188199-tech wants to merge 1 commit into
Conversation
The weight-progression, volume, and one-rep-max statistics routes all read the raw weight value (valuesInt[weightIndex]) and never consulted units[weightIndex], so a 50 lb set and a 50 kg set both read as 50 and a mid-history unit switch made the trend line jump. Normalize each weight to kg via the existing convertWeight() before aggregating, in all three routes. Fixes Snouzy#226
|
Someone is attempting to deploy a commit to the Workoutcool Team Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
此 PR 由 GLM-5.2 修复。 |
This branch has not been 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.
What
All three exercise statistics routes plot/aggregate raw weight values without normalizing units, so a user who switches between kg and lb (or mixes them across sessions) gets a misleading trend line. A 50 lb set and a 50 kg set both read as "50", and a 110 lb set sits far below a 50 kg set on the same axis.
Bug found while auditing the analytics code — not covered by any existing issue/PR.
Root cause
Each route reads the weight straight out of the value array and never consults
units[weightIndex]:weight-progression/route.ts:const weight = set.valuesInt[weightIndex]volume/route.ts:volume = reps × set.valuesInt[weightIndex]one-rep-max/route.ts:const weight = set.valuesInt[weightIndex]The set stores its unit (
"kg"/"lbs") atunits[weightIndex], but it's ignored. The app already shipsconvertWeight()/WEIGHT_CONVERSIONinsrc/shared/lib/weight-conversion.ts.Fix
Normalize each weight to kg before aggregating, in all three routes:
Now a 50 lb and a 50 kg set are no longer treated as equal, and mid-history unit switches don't make the line jump. Aggregates (per-session max weight, total volume, estimated 1RM) become unit-consistent.
Fixes #226.