Calculate a smoothed upload ETA
Estimate remaining upload time with an EWMA rate that resists unstable progress jumps.Description
Requirements
Export a callable calculateSmoothedUploadEta function from src/App.js.
Fold interval byte rates into an EWMA with the newest rate weighted by alpha.
Return Math.ceil(remainingBytes / smoothedBytesPerSecond).
Use all valid intervals in order so short-lived rate changes do not replace the estimate outright.
Return zero when the latest loaded byte count equals totalBytes.
Return null when fewer than two valid samples or no positive transfer rate are available.
Throw RangeError for invalid totals, alpha, byte counts, regressions, or non-increasing timestamps.
Do not mutate or reorder the sample array or its objects.
Smoothed intervals
[{loaded:0,timeMs:0},{loaded:100,timeMs:1000},{loaded:300,timeMs:2000}], total 700, alpha 0.53
Rates of 100 and 200 bytes/second smooth to 150; 400 bytes remain, so the ceiling is three seconds.
Insufficient history
One valid sample
null
At least one elapsed interval is required to estimate a rate.
Constraints
alpha must be greater than zero and at most oneloaded values are finite bytes between zero and totalBytestimeMs values must increase strictly
Hints
Hint 1
Convert each byte delta and millisecond delta into bytes per second.
Hint 2
Seed the EWMA with the first interval rate, then combine later rates using alpha.
Hint 3
Validate the full sequence before returning early for completion.