Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make current download speed and ETA smoother #166

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/KKManager.Updater/Windows/ModUpdateProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public static ModUpdateProgressDialog CreateUpdateDialog(UpdateSourceBase[] upda

private async void ModUpdateProgress_Shown(object sender, EventArgs e)
{
var averageDownloadSpeed = new MovingAverage(20);
var averageDownloadSpeed = new MovingAverage(25);
var averageDownloadSpeedFast = new MovingAverage(4);
var downloadStartTime = DateTime.Now;
UpdateDownloadCoordinator downloader = null;

Expand Down Expand Up @@ -112,6 +113,7 @@ void DoStatusLabelUpdate(object o, EventArgs args)
var downloadedSinceLast = FileSize.FromKilobytes((long)((_completedSize - lastCompletedSize).GetKbSize() / secondsPassed));
lastCompletedSize = _completedSize;
averageDownloadSpeed.Sample(downloadedSinceLast.GetKbSize());
averageDownloadSpeedFast.Sample(downloadedSinceLast.GetKbSize());
var etaSeconds = (_overallSize - _completedSize).GetKbSize() / (double)averageDownloadSpeed.GetAverage();
var eta = double.IsNaN(etaSeconds) || etaSeconds < 0 || etaSeconds > TimeSpan.MaxValue.TotalSeconds
? KKManager.Properties.Resources.Unknown
Expand All @@ -122,7 +124,7 @@ void DoStatusLabelUpdate(object o, EventArgs args)
var uploadSpeed = TorrentUpdater.GetCurrentUpload();
if (uploadSpeed.HasValue) text += $" | Seeding: {FileSize.FromBytes(uploadSpeed.Value)}/s";

text += $"\r\nSpeed: {downloadedSinceLast}/s (ETA: {eta})";
text += $"\r\nSpeed: {FileSize.FromKilobytes(averageDownloadSpeedFast.GetAverage())}/s (ETA: {eta})";

labelPercent.Text = text;

Expand Down
Loading