Skip to content

Commit

Permalink
fixed percent reporting when limiting reads
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljon committed May 20, 2022
1 parent 64d1b39 commit 6bd79d0
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Utils/TimedSequenceProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@ public TimedSequenceProgressBar(ISequenceReader sequenceReader) : base(100, "Pro

public void Update(bool force = false)
{
var read = sequenceReader.SequencesRead;
var percent = sequenceReader.ApproximateCompletion;
var sequencesRead = sequenceReader.SequencesRead;
var approximateCompletion = sequenceReader.ApproximateCompletion;

if (force || read % CliOptions.UpdatePeriod == 0)
if (force || sequencesRead % CliOptions.UpdatePeriod == 0)
{
if (percent > 0)
// if we're limiting the number of reads then the reader's
// approximation will be incorrect (it's based on file positions),
// so we'll do the math ourselves
if (CliOptions.Settings.ReadLimit < ulong.MaxValue)
{
var remainingTime = elapsedTime.ElapsedMilliseconds / percent * 100.0;
approximateCompletion = 100.0 * sequencesRead / CliOptions.Settings.ReadLimit;
}

if (approximateCompletion > 0)
{
var remainingTime = elapsedTime.ElapsedMilliseconds / approximateCompletion * 100.0;
EstimatedDuration = TimeSpan.FromMilliseconds(remainingTime);
}

AsProgress<double>().Report(percent / 100.0);
Message = $"{read.WithSsiUnits()} sequences completed";
AsProgress<double>().Report(approximateCompletion / 100.0);
Message = $"{sequencesRead.WithSsiUnits()} sequences completed";
}
}
}
Expand Down

0 comments on commit 6bd79d0

Please sign in to comment.