feat(chart): кнопка графика прогрессии упражнения
SVG-график максимального веса по завершённым тренировкам с объединением вариантов одной группы, подсказками на точках и списком последних результатов.
This commit is contained in:
@@ -151,6 +151,41 @@ export function getExerciseHistory(exerciseName, clientId = null, excludeWorkout
|
||||
return history.slice(0, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Полная история для графика (без среза в 5 записей): варианты из одной
|
||||
* группы складывают в одну прогрессию.
|
||||
*/
|
||||
export function getExerciseChart(exerciseName, clientId = null) {
|
||||
const variantNames = refVariantNames(exerciseName);
|
||||
const targetClient = normalizeClientId(clientId);
|
||||
const points = [];
|
||||
|
||||
for (const w of state.workouts) {
|
||||
if (!isSameClient(w.client_id, targetClient)) continue;
|
||||
if (!w.endTime) continue; // активная тренировка ещё не результат
|
||||
|
||||
for (const ex of w.exercises || []) {
|
||||
if (!variantNames.has(normalizeName(ex.name))) continue;
|
||||
let maxWeight = 0, totalReps = 0;
|
||||
for (const s of ex.sets || []) {
|
||||
const wgt = s.isDropset && s.subSets?.length
|
||||
? Math.max(...s.subSets.map(x => parseFloat(x.weight) || 0))
|
||||
: (parseFloat(s.weight) || 0);
|
||||
if (wgt > maxWeight) maxWeight = wgt;
|
||||
totalReps += s.isDropset && s.subSets?.length
|
||||
? s.subSets.reduce((a, x) => a + (parseInt(x.reps) || 0), 0)
|
||||
: (parseInt(s.reps) || 0);
|
||||
}
|
||||
if (maxWeight > 0 || totalReps > 0) {
|
||||
points.push({ date: w.startTime, name: ex.name, maxWeight, totalReps });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
points.sort((a, b) => new Date(a.date) - new Date(b.date));
|
||||
return points;
|
||||
}
|
||||
|
||||
window.EL = {
|
||||
addExercise,
|
||||
toggleExercise,
|
||||
|
||||
Reference in New Issue
Block a user