From 9b14bf6826655e295b2540832e9debc964f31e7b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 4 Apr 2020 23:42:20 +0200 Subject: [PATCH] [unpackfs] Rework progress reporting - Slice overall progress into chunks, with each chunk of equal size (as long as we have no overall count information) and place the progress of the current chunk into its own slice. --- src/modules/unpackfs/main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 350a01a69..6398109ea 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -269,19 +269,27 @@ class UnpackOperation: """ progress = float(0) - done = 0 + done = 0 # Done and total apply to the entry now-unpacking total = 0 - complete = 0 + complete = 0 # This many are already finished for entry in self.entries: if entry.total == 0: + # Total 0 hasn't counted yet continue - total += entry.total - done += entry.copied if entry.total == entry.copied: complete += 1 + else: + # There is at most *one* entry in-progress + total = entry.total + done = entry.copied + break if done > 0 and total > 0: - progress = 0.05 + (0.90 * done / total) + (0.05 * complete / len(self.entries)) + # Pretend that each entry represents an equal amount of work; + # the complete ones count as 100% of their own fraction + # (and have *not* been counted in total or done), while + # total/done represents the fraction of the current fraction. + progress = ( 1.0 * complete / len(self.entries) ) + ( ( 1.0 / len(self.entries) ) * done / total ) job.setprogress(progress)