This commit is contained in:
Dominik Klarkowski
2026-06-16 11:11:19 +02:00
parent 36407f534b
commit 21e5db3409
4 changed files with 158 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
import type { StrengthExercise, StrengthWorkout } from "@/lib/models/strength";
export function exerciseVolumeKg(exercise: StrengthExercise): number {
return exercise.sets.reduce((sum, set) => sum + (set.weightKg ?? 0) * (set.reps ?? 0), 0);
}
@@ -11,6 +12,17 @@ export function exerciseTopWeightKg(exercise: StrengthExercise): number | undefi
return weights.length > 0 ? Math.max(...weights) : undefined;
}
// Epley formula: weight × (1 + reps / 30). Returns best e1rm across all sets.
export function exerciseE1rm(exercise: StrengthExercise): number | undefined {
let best: number | undefined;
for (const set of exercise.sets) {
if (set.weightKg == null || set.reps == null || set.reps < 1) continue;
const e1rm = set.weightKg * (1 + set.reps / 30);
if (best === undefined || e1rm > best) best = e1rm;
}
return best !== undefined ? Math.round(best * 10) / 10 : undefined;
}
export function workoutVolumeKg(workout: StrengthWorkout): number {
return workout.exercises.reduce((sum, exercise) => sum + exerciseVolumeKg(exercise), 0);
}
@@ -19,6 +31,7 @@ export type ExerciseHistoryPoint = {
date: Date;
volumeKg: number;
topWeightKg?: number;
e1rmKg?: number;
};
/**
@@ -38,6 +51,7 @@ export function getExerciseHistory(
date: workout.date,
volumeKg: exerciseVolumeKg(exercise),
topWeightKg: exerciseTopWeightKg(exercise),
e1rmKg: exerciseE1rm(exercise),
});
}