Skip to content

Commit

Permalink
Make current download speed and ETA smoother (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco authored May 27, 2024
1 parent 4f31901 commit 392a007
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit 392a007

Please sign in to comment.