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<{
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