feat: preserve speed history and improve account setup

This commit is contained in:
Sucukdeluxe
2026-08-09 14:59:52 +02:00
parent 403051e3cf
commit 29bdf589eb
13 changed files with 279 additions and 132 deletions
+24
View File
@@ -0,0 +1,24 @@
export interface DownloadSpeedHistoryState {
history: number[];
display: number;
}
export const DOWNLOAD_SPEED_MAX_SAMPLES = 160;
export function updateDownloadSpeedHistory(
state: DownloadSpeedHistoryState,
target: number,
maxSamples = DOWNLOAD_SPEED_MAX_SAMPLES
): DownloadSpeedHistoryState {
const safeTarget = Math.max(0, Number.isFinite(target) ? target : 0);
const alpha = safeTarget > state.display ? 0.45 : 0.12;
let display = state.display + (safeTarget - state.display) * alpha;
if (display < 1) {
display = 0;
}
const history = [...state.history, display];
if (history.length > maxSamples) {
history.splice(0, history.length - maxSamples);
}
return { history, display };
}