ExpansionDownloader.Service.DownloaderService.NotifyUpdateBytes C# (CSharp) Method

NotifyUpdateBytes() public method

Calculating a moving average for the speed so we don't get jumpy calculations for time etc.
public NotifyUpdateBytes ( long totalBytesSoFar ) : void
totalBytesSoFar long /// The total Bytes So Far. ///
return void
        public void NotifyUpdateBytes(long totalBytesSoFar)
        {
            long timeRemaining;
            long currentTime = SystemClock.UptimeMillis();
            if (0 != this.millisecondsAtSample)
            {
                // we have a sample.
                long timePassed = currentTime - this.millisecondsAtSample;
                long bytesInSample = totalBytesSoFar - this.bytesAtSample;
                float currentSpeedSample = bytesInSample / (float)timePassed;
                if (Math.Abs(0 - this.averageDownloadSpeed) > SmoothingFactor)
                {
                    float smoothSpeed = SmoothingFactor * currentSpeedSample;
                    float averageSpeed = (1 - SmoothingFactor) * this.averageDownloadSpeed;
                    this.averageDownloadSpeed = smoothSpeed + averageSpeed;
                }
                else
                {
                    this.averageDownloadSpeed = currentSpeedSample;
                }

                timeRemaining = (long)((this.TotalLength - totalBytesSoFar) / this.averageDownloadSpeed);
            }
            else
            {
                timeRemaining = -1;
            }

            this.millisecondsAtSample = currentTime;
            this.bytesAtSample = totalBytesSoFar;
            this.downloadNotification.OnDownloadProgress(
                new DownloadProgressInfo(this.TotalLength, totalBytesSoFar, timeRemaining, this.averageDownloadSpeed));
        }