Skip to content

fix(analytics): include minutes for time-based set volume stats#223

Open
evan188199-tech wants to merge 1 commit into
Snouzy:mainfrom
evan188199-tech:fix/volume-stats-drop-minutes-for-time-sets
Open

fix(analytics): include minutes for time-based set volume stats#223
evan188199-tech wants to merge 1 commit into
Snouzy:mainfrom
evan188199-tech:fix/volume-stats-drop-minutes-for-time-sets

Conversation

@evan188199-tech

Copy link
Copy Markdown

What

Per-exercise volume statistics (/api/exercises/[id]/statistics/volume) dropped the minutes for time-based sets and read from the wrong array index, so time-based exercises got wildly wrong volume numbers — a 3:00 plank showed 0 volume while a 0:30 plank showed 30.

This is a bug I found while auditing the analytics code (not covered by any existing issue/PR).

Root cause

A TIME column stores two values at the same column index (see workout-session-set.tsx):

  • valuesInt[columnIndex] = minutes
  • valuesSec[columnIndex] = seconds

The volume route read time-based sets like this:

} else if (timeIndex !== -1 && set.valuesSec && set.valuesSec[0]) {
  volume = set.valuesSec[0];
}

Two problems:

  1. Hardcoded valuesSec[0] — wrong when TIME isn't the first column (types: ["REPS","TIME"] keeps seconds at valuesSec[1]).
  2. Minutes ignored entirely. A 3:00 plank (valuesInt:[3], valuesSec:[0]) hit the falsy set.valuesSec[0] guard and was skipped (volume = 0), while a 0:30 plank got volume = 30.

Fix

} else if (timeIndex !== -1 && (set.valuesInt || set.valuesSec)) {
  const minutes = set.valuesInt?.[timeIndex] ?? 0;
  const seconds = set.valuesSec?.[timeIndex] ?? 0;
  volume = minutes * 60 + seconds;
}

Reads from timeIndex (not a hardcoded 0), adds the minutes back in, and uses a non-falsy guard so a whole-minute entry isn't dropped. The downstream volume > 0 check still correctly skips genuinely-empty entries (0 min + 0 sec).

Fixes #222.

The per-exercise volume route read time-based sets as `set.valuesSec[0]`,
which had two problems:

1. Hardcoded index 0 — wrong when TIME isn't the first column (e.g.
   types ["REPS","TIME"] keeps seconds at valuesSec[1]).
2. Only seconds were counted; valuesInt[timeIndex] (the minutes) was
   dropped entirely. A 3:00 plank (valuesInt:[3], valuesSec:[0]) read
   valuesSec[0] = 0 and was skipped by the volume > 0 guard, so it
   contributed zero volume while a 0:30 plank contributed 30.

Compute the full duration in seconds (minutes*60 + seconds) and read it
from the correct timeIndex.

Fixes Snouzy#222
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Workoutcool Team Team on Vercel.

A member of the Team first needs to authorize it.

@evan188199-tech

Copy link
Copy Markdown
Author

此 PR 由 GLM-5.2 修复。

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.

Bug: Exercise volume stats drop minutes for time-based sets (e.g. 3:00 plank → 0 volume)

1 participant