Answer the question
In order to leave comments, you need to log in
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
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_display
is 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_display
update not instantly, but once in a fix. time interval (every 200 ms) we move it towards the current value finish_forecast
by 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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question