You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank you to the developers for creating and maintaining Rich! It's an incredibly powerful and visually appealing library that has made working with terminal applications a joy.
Feature Description
I'd like to propose adding smoothing functionality for the speed and time_remaining metrics in Rich's progress tasks. Currently, these values can appear jittery, especially when tasks involve variable workloads or uneven progress updates. Smoothing these metrics would make the progress bars look more polished and provide a better user experience.
Inspiration from Other Libraries
Other progress bar libraries, such as alive-progress and tqdm, already implement smoothing techniques to address this issue. For example:
defgen_simple_exponential_smoothing(alpha: float, fn: Callable[[float, float], float]):
"""Implements a generator with a simple exponential smoothing of some function. Given alpha and y_hat (t-1), we can calculate the next y_hat: y_hat = alpha * y + (1 - alpha) * y_hat y_hat = alpha * y + y_hat - alpha * y_hat y_hat = y_hat + alpha * (y - y_hat) Args: alpha: the smoothing coefficient fn: the function Returns: """p= (0.,)
whileany(x==0.forxinp):
p=yield0.y_hat=fn(*p)
whileTrue:
p=yieldy_haty=fn(*p)
y_hat+=alpha* (y-y_hat)
tqdm/tqdm/std.py at 0ed5d7f18fa3153834cbac0aa57e8092b217cc16 · tqdm/tqdm
classEMA(object):
""" Exponential moving average: smoothing to give progressively lower weights to older values. Parameters ---------- smoothing : float, optional Smoothing factor in range [0, 1], [default: 0.3]. Increase to give more weight to recent values. Ranges from 0 (yields old value) to 1 (yields new value). """def__init__(self, smoothing=0.3):
self.alpha=smoothingself.last=0self.calls=0def__call__(self, x=None):
""" Parameters ---------- x : float New value to include in EMA. """beta=1-self.alphaifxisnotNone:
self.last=self.alpha*x+beta*self.lastself.calls+=1returnself.last/ (1-beta**self.calls) ifself.callselseself.last
Proposed Implementation
I suggest adding an optional smoothing parameter to the Progress class or Progress.add_task() method, which could be enabled and configured by the user. For example:
importtimefromrich.progressimporttrackforiintrack(range(20), description="Processing...", smoothing=0.3):
time.sleep(1) # Simulate work being done
Problem This Solves
The jittery behavior of speed and time_remaining can be distracting and make the progress bar feel less reliable. Smoothing these values would make the progress bar more useful for tasks with variable workloads, where raw values might fluctuate significantly.
Additional Considerations
The smoothing algorithm should be optional and configurable (e.g., via a smoothing parameter).
Thank you for considering this feature! I'd be happy to provide more details or assist with implementation if needed.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First of all, thank you to the developers for creating and maintaining Rich! It's an incredibly powerful and visually appealing library that has made working with terminal applications a joy.
Feature Description
I'd like to propose adding smoothing functionality for the
speed
andtime_remaining
metrics in Rich's progress tasks. Currently, these values can appear jittery, especially when tasks involve variable workloads or uneven progress updates. Smoothing these metrics would make the progress bars look more polished and provide a better user experience.Inspiration from Other Libraries
Other progress bar libraries, such as
alive-progress
andtqdm
, already implement smoothing techniques to address this issue. For example:alive-progress/alive_progress/utils/timing.py at 35853799b84ee682af121f7bc5967bd9b62e34c4 · rsalmei/alive-progress
tqdm/tqdm/std.py at 0ed5d7f18fa3153834cbac0aa57e8092b217cc16 · tqdm/tqdm
Proposed Implementation
I suggest adding an optional smoothing parameter to the
Progress
class orProgress.add_task()
method, which could be enabled and configured by the user. For example:Problem This Solves
The jittery behavior of
speed
andtime_remaining
can be distracting and make the progress bar feel less reliable. Smoothing these values would make the progress bar more useful for tasks with variable workloads, where raw values might fluctuate significantly.Additional Considerations
smoothing
parameter).Thank you for considering this feature! I'd be happy to provide more details or assist with implementation if needed.
Beta Was this translation helpful? Give feedback.
All reactions