Class ProgressSpeedSampler
- Namespace
- Archiver.Core.Services
- Assembly
- Archiver.Core.dll
EMA-smoothed transfer-speed sampler shared between Archiver.App's status line and
Archiver.Shell's progress dialog (T-F142) — extracted from what was private, untested
arithmetic inline in Archiver.App's MainViewModel.UpdateOperationStatus. Public (not internal),
matching Archiver.Core.IO.Crc32's own precedent for a dependency-free algorithm needed by
multiple frontends. Sampling only: byte/speed string formatting (localization-adjacent in the
App, plain text in the Shell dialog) and ETA (derived from Percent, not bytes — works already,
isn't shared) both stay separate per frontend, not folded in here. Callers gate on
TotalBytes > 0 themselves before calling Sample(long, DateTime) — a report with no real
byte total carries no speed signal at all, and deciding to skip it is the caller's job, not
this sampler's, so it stays a pure function of (bytes, time). Construct a fresh instance per
operation (Archive/Extract) rather than reusing one across operations — there is no
Reset() by design, so a stale carried-over speed from reusing an instance across two
operations is not possible.
public sealed class ProgressSpeedSampler
- Inheritance
-
ProgressSpeedSampler
- Inherited Members
Constructors
ProgressSpeedSampler(DateTime?)
Starts a fresh sampler — construct one per operation (see class remarks).
public ProgressSpeedSampler(DateTime? startTimeUtc = null)
Parameters
startTimeUtcDateTime?
Methods
Sample(long, DateTime)
Updates the running EMA from a new (bytesTransferred, nowUtc) sample and returns the current smoothed bytes/sec (0 until the first valid sample). A sample is only folded in once at least Archiver.Core.Services.ProgressSpeedSampler.MinSampleIntervalSeconds has elapsed since the last one AND bytesTransferred has actually advanced — this also means a non-increasing or repeated bytesTransferred (an out-of-order report, or the same report delivered twice) is tolerated by construction: it is simply ignored, never treated as a negative delta or a spike, and the last known smoothed value is returned unchanged.
public double Sample(long bytesTransferred, DateTime nowUtc)