rescaleProgress now deals with two-element and non-tuple yields

This commit is contained in:
David Vierra 2015-09-10 16:26:36 -10:00
parent 800ab23427
commit c7b009b59c

View File

@ -12,15 +12,26 @@ def rescaleProgress(iterable, start, end):
Given an iterable that yields (current, maximum, status) tuples, rescales current and maximum
to fit within the range [start, end]. `current` is assumed to start at zero.
Use rescaleProgress to combine multiple progress-yielding iterables by assigning
a different range to each iterable.
:param iterable:
:param start:
:param end:
:return:
"""
d = end - start
status = ""
for current, maximum, status in iterable:
yield start + current * d / maximum, end, status
for progress in iterable:
if isinstance(progress, tuple):
current, maximum = progress[:2]
if len(progress) > 2:
status = progress[2]
yield start + current * d / maximum, end, status
else:
yield progress
def enumProgress(collection, start, end=None):
@ -28,6 +39,9 @@ def enumProgress(collection, start, end=None):
Iterate through a collection, yielding (progress, value) tuples. `progress` is the value
between `start` and `end` proportional to the progress through the collection.
Use enumProgress to report the progress of iterating through a collection, scaled
to a fixed amount of progress.
:param collection:
:param progress:
:return: