All files / src/tools estimate-workout-time.ts

100% Statements 21/21
100% Branches 10/10
100% Functions 1/1
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44      1x     1x                   1x 30x 30x   27x   29x 85x   85x 265x   265x   265x 180x 180x 265x     85x 58x 58x 85x   27x 27x  
import type { PrescribedExercise } from '@strengthsys/shared';
 
/** Estimated seconds per rep of working time. */
const SECONDS_PER_REP = 3;
 
/** Transition time between exercises in seconds. */
const TRANSITION_SECONDS = 60;
 
/**
 * Estimate total workout time in minutes.
 *
 * For each non-backup exercise, sums:
 * - Working time: reps × SECONDS_PER_REP per set
 * - Rest time: rest_seconds per set (no rest after the last set of an exercise)
 * - Transition time between exercises
 */
export function estimateWorkoutTime(exercises: PrescribedExercise[]): number {
  const primary = exercises.filter((e) => !e.is_backup);
  if (primary.length === 0) return 0;
 
  let totalSeconds = 0;
 
  for (let i = 0; i < primary.length; i++) {
    const ex = primary[i];
 
    for (let s = 0; s < ex.sets.length; s++) {
      const set = ex.sets[s];
      // Working time
      totalSeconds += set.target_reps * SECONDS_PER_REP;
      // Rest after every set except the last set of each exercise
      if (s < ex.sets.length - 1) {
        totalSeconds += set.rest_seconds;
      }
    }
 
    // Transition time between exercises
    if (i < primary.length - 1) {
      totalSeconds += TRANSITION_SECONDS;
    }
  }
 
  return Math.round(totalSeconds / 60);
}