A
A
Atlllantis2018-04-17 21:27:55
Programming
Atlllantis, 2018-04-17 21:27:55

Algorithm for calculating the remaining time of the operation?

Hello.
There is some long (and not so long) operation, whether it's code execution or file upload (no difference).
In general, you need to somehow calculate the remaining time for the operation.
I take the data for the last 30 seconds and calculate the remaining time based on it.
It seems to have done everything, but the speed of execution is not constant and is constantly changing, hence the remaining time is constantly jumping.
Now it remains to somehow smooth out these fluctuations, but I just can’t figure out how to do it.
Who can tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-04-17
@sergiks

The forecast can be made inert.
On the progress update event (the next chunk has loaded), the value of the expected end changes abruptly finish_forecast.
The variable finish_forecast_displayis the predicted end time for the show. Based on it and the current time, we smoothly update the progress indicator.
To avoid jerks, we finish_forecast_displayupdate not instantly, but once in a fix. time interval (every 200 ms) we move it towards the current value finish_forecastby a delta proportional to the distance - the closer, the slower. The regularity of these display refresh intervals is important here.
So the speed of the progress bar will gradually accelerate or slow down, but there will be no jumps.
A similar effect in 2D was used insimulation of insect flight . There, a random point sets the goal towards which the fly is striving. In the example, however, not the fly itself, but in front of it are several more links of the invisible chain of pursuit. But the principle is the same:
T - just set a new moment of the end of the process total * time_passed / current_progress
C - we show the progress bar based on this expected moment of the end of the entire process
N - in the next "frame" C will take the value N.
N = C + (T - C) / 100

K
key don, 2018-04-17
@keydon2

  • Take an interval greater than 30 seconds (you can increase the interval in the process).
  • If the operations are approximately the same, then you can try to calculate stage 1 on the same hardware, calculate the total time.
    On the second iron, measure stage 1 and proportionally predict the total time (total time 2 = total time 1 * (stage 1 iron 2 / stage 1 iron 1).
  • Filter out fast changes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question