From 6bd79d0fb4ec20589a70d6aed4f222cef0195209 Mon Sep 17 00:00:00 2001 From: Michaeljon Miller Date: Fri, 20 May 2022 11:20:41 -0700 Subject: [PATCH] fixed percent reporting when limiting reads --- Utils/TimedSequenceProgressBar.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Utils/TimedSequenceProgressBar.cs b/Utils/TimedSequenceProgressBar.cs index 71e8290..51247fc 100644 --- a/Utils/TimedSequenceProgressBar.cs +++ b/Utils/TimedSequenceProgressBar.cs @@ -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().Report(percent / 100.0); - Message = $"{read.WithSsiUnits()} sequences completed"; + AsProgress().Report(approximateCompletion / 100.0); + Message = $"{sequencesRead.WithSsiUnits()} sequences completed"; } } }