How can I eliminate jitter from my calculation of the estimated time (and ETA)?

I have an application that, when performing a background task, shows a progress bar with an estimated "estimated time" (for example, "the remaining 5 seconds") and an "estimated completion time" (for example, "completed at 12: 59:59"), or, as I call it, ETA.

The calculation algorithm of this ETA basically takes a "moving average" of progress over time:
1. Each progress event is added to the queue with the current time.
2. After a certain duration (for example, 10 seconds), items are removed from the queue.
3. ETA is extrapolated from the first and last elements in the queue.
Source code is available if you are interested: ETACalculator.cs

However, there is a jitter problem. As each progress event is added to the calculation, the ETA will be updated slightly. Let's say that the ETA only changes by 0.1s . This little shake makes ETA flutter easily. For example, instead of seeing a smooth progression from 5s, 4s, 3s, etc., I see 5-5-5-4-5-4-5-4-5-4-4-4-4.

I thought that I simply reduce updates to 1 per second, but then the progress indicator is less smooth, and I would really like the "actual" slowdowns to be displayed in real time.

I'm having trouble with a simple algorithm that reduces this jittery jitter. How to remove jitter?

+6
source share
2 answers

Divide actual erratic progress and displayed progress into two separate variables.

Update unsustainable progress as it is now.

At a regular (relatively fast) interval, update the displayed progress to get closer to the actual progress.

A simple approach algorithm would average two values

 display_progress = (display_progress + actual_progress) / 2 

This will decrease the value to reflect past values, not just the immediate value.

You can also improve smoothness by using:

 display_progress = (P) * display_progress + (1.0-P) * actual_progress 

Where P is a constant value between 0.0 and 1.0 .

Edit:

This is one of many filters that you can use. This is good because it does not require a lot of bookkeeping.

However, getting great output would not be an option, because the flaw is in your input . The difference between β€œjitter” and β€œactual slowdown” is observed only after this has occurred.

+9
source

It's not entirely clear in your algorithm without seeing the code, but when you update your ETA, first check the current ETA and update it only if the new value is less than the old.

+2
source

Source: https://habr.com/ru/post/906033/


All Articles