This commit is contained in:
Linrador 2026-05-06 21:11:03 +02:00
parent 5679d19b30
commit 2d5e522475

View File

@ -2025,8 +2025,10 @@ export default function TrainingTab(props: {
const etaSmoothingRef = useRef<{ const etaSmoothingRef = useRef<{
lastAt: number lastAt: number
lastRawEtaMs: number
}>({ }>({
lastAt: 0, lastAt: 0,
lastRawEtaMs: 0,
}) })
const [trainingNowMs, setTrainingNowMs] = useState(() => Date.now()) const [trainingNowMs, setTrainingNowMs] = useState(() => Date.now())
@ -2505,6 +2507,7 @@ export default function TrainingTab(props: {
if (!trainingRunning) { if (!trainingRunning) {
etaSmoothingRef.current = { etaSmoothingRef.current = {
lastAt: 0, lastAt: 0,
lastRawEtaMs: 0,
} }
setSmoothedTrainingEtaMs(0) setSmoothedTrainingEtaMs(0)
@ -3189,6 +3192,7 @@ export default function TrainingTab(props: {
if (!trainingRunning || rawTrainingEtaMs <= 0) { if (!trainingRunning || rawTrainingEtaMs <= 0) {
etaSmoothingRef.current = { etaSmoothingRef.current = {
lastAt: 0, lastAt: 0,
lastRawEtaMs: 0,
} }
setSmoothedTrainingEtaMs(0) setSmoothedTrainingEtaMs(0)
@ -3196,32 +3200,41 @@ export default function TrainingTab(props: {
} }
setSmoothedTrainingEtaMs((previous) => { setSmoothedTrainingEtaMs((previous) => {
const lastAt = etaSmoothingRef.current.lastAt || trainingNowMs const state = etaSmoothingRef.current
const lastAt = state.lastAt || trainingNowMs
const elapsed = Math.max(0, trainingNowMs - lastAt) const elapsed = Math.max(0, trainingNowMs - lastAt)
// Anzeige zählt zwischen Backend-Updates weiter runter. // 1) Immer erstmal echte Anzeige runterzählen.
const countedDown = previous > 0 const countedDown =
? Math.max(0, previous - elapsed) previous > 0
: rawTrainingEtaMs ? 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. let next = countedDown
const factor = diff > 0 ? 0.08 : 0.18
let next = countedDown + diff * factor if (rawChanged) {
const diff = rawTrainingEtaMs - countedDown
// Harte Sprünge zusätzlich begrenzen. // Neue Backend-Schätzung einblenden, aber nicht hart springen.
if (diff > 0) { if (diff > 0) {
next = Math.min(next, countedDown + 10_000) // Restzeit wurde höher neu berechnet: langsam nach oben.
} else { next = countedDown + Math.min(diff * 0.20, 15_000)
next = Math.max(next, countedDown - 20_000) } else {
// Restzeit wurde niedriger neu berechnet: schneller nach unten.
next = countedDown + diff * 0.45
}
} }
next = Math.max(0, next) next = Math.max(0, next)
etaSmoothingRef.current = { etaSmoothingRef.current = {
lastAt: trainingNowMs, lastAt: trainingNowMs,
lastRawEtaMs: rawTrainingEtaMs,
} }
return next return next