From 2d5e52247531739da899061d9e5d96be8afbf32b Mon Sep 17 00:00:00 2001 From: Linrador <68631622+Linrador@users.noreply.github.com> Date: Wed, 6 May 2026 21:11:03 +0200 Subject: [PATCH] bugfixes --- frontend/src/components/ui/TrainingTab.tsx | 41 ++++++++++++++-------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/ui/TrainingTab.tsx b/frontend/src/components/ui/TrainingTab.tsx index ba9bd8f..26fdfd1 100644 --- a/frontend/src/components/ui/TrainingTab.tsx +++ b/frontend/src/components/ui/TrainingTab.tsx @@ -2025,8 +2025,10 @@ export default function TrainingTab(props: { const etaSmoothingRef = useRef<{ lastAt: number + lastRawEtaMs: number }>({ lastAt: 0, + lastRawEtaMs: 0, }) const [trainingNowMs, setTrainingNowMs] = useState(() => Date.now()) @@ -2505,6 +2507,7 @@ export default function TrainingTab(props: { if (!trainingRunning) { etaSmoothingRef.current = { lastAt: 0, + lastRawEtaMs: 0, } setSmoothedTrainingEtaMs(0) @@ -3189,6 +3192,7 @@ export default function TrainingTab(props: { if (!trainingRunning || rawTrainingEtaMs <= 0) { etaSmoothingRef.current = { lastAt: 0, + lastRawEtaMs: 0, } setSmoothedTrainingEtaMs(0) @@ -3196,32 +3200,41 @@ export default function TrainingTab(props: { } setSmoothedTrainingEtaMs((previous) => { - const lastAt = etaSmoothingRef.current.lastAt || trainingNowMs + const state = etaSmoothingRef.current + + const lastAt = state.lastAt || trainingNowMs const elapsed = Math.max(0, trainingNowMs - lastAt) - // Anzeige zählt zwischen Backend-Updates weiter runter. - const countedDown = previous > 0 - ? Math.max(0, previous - elapsed) - : rawTrainingEtaMs + // 1) Immer erstmal echte Anzeige runterzählen. + const countedDown = + previous > 0 + ? Math.max(0, previous - elapsed) + : rawTrainingEtaMs - const diff = rawTrainingEtaMs - countedDown + const rawChanged = + state.lastRawEtaMs <= 0 || + Math.abs(rawTrainingEtaMs - state.lastRawEtaMs) > 1000 - // Nach oben sehr vorsichtig glätten, nach unten etwas schneller. - const factor = diff > 0 ? 0.08 : 0.18 + let next = countedDown - let next = countedDown + diff * factor + if (rawChanged) { + const diff = rawTrainingEtaMs - countedDown - // Harte Sprünge zusätzlich begrenzen. - if (diff > 0) { - next = Math.min(next, countedDown + 10_000) - } else { - next = Math.max(next, countedDown - 20_000) + // Neue Backend-Schätzung einblenden, aber nicht hart springen. + if (diff > 0) { + // Restzeit wurde höher neu berechnet: langsam nach oben. + next = countedDown + Math.min(diff * 0.20, 15_000) + } else { + // Restzeit wurde niedriger neu berechnet: schneller nach unten. + next = countedDown + diff * 0.45 + } } next = Math.max(0, next) etaSmoothingRef.current = { lastAt: trainingNowMs, + lastRawEtaMs: rawTrainingEtaMs, } return next