# Should I go take my coffee now?

Published on  2019-08-20

# Should I go take my coffee now? Computing data...


Sometimes, as you launch a script, your eyes dive into these 3 final dots on the screen meaning the task will take a while.

Computing data...


As the time pass, you wonder if you might kill your function to add a remaining time indicator (or ETA: Estimated Time of Arrival) or keep waiting until, in an undetermined amount of time, it ends.

Coffee meter for the next parts:

So you get back to your desk, coffee in hand to see the result you seek and…

Computing data...


As you kill this annoying task you ask yourself what's a simple way to get the ETA.

## Linear progress ETA

In this case, making n% will always take the same amount of time.

Let's represent the time-cost like this:

• horizontal axis is the progress between 0 and 1
• vertical axis is the time cost We know the time taken at a given progress:
And we want to get the remaining time:

You quickly implement this function in your code and launch it again.

Computing data...
Computing data... (ETA: 20 s)
Computing data... (ETA: 1 min)
Computing data... (ETA: 3 min)
Computing data... (ETA: 10 min)


You kill it again, there must be a mistake somewhere… but you find nothing.

You understand quickly that, as the percentage goes, the time it takes increase as well like this: The vertical scale is in seconds here…

As you can see, the simple time indicator wasn't enough for this task.

If you want, you can simply go the end and skip all the fun.

First, we need to acknowledge the shape of the time-cost function: a trapezoid.

## Area of a trapezoid function It's a simple function like:
But we need to calculate its area.

We can apply this formula to the known cases:

Now we can use this formula to get what we want.

## Non-linear progress ETA

This time, a progress of n% will take more time over time. We know the time taken at 2 given progresses:
And we still want to get the remaining time:

We can now calculate our remaining time by calculating the intermediate values of and but we can also get rid of the first one.

Steps to simplify further the formula (click)

Let's verify that it's working for the simple case we saw before.

## Real data

On real data, we have more than 2 points so how do we get the ETA from a set of points?

You can use this formula as you want, but to get results quickly, you can get the mean of values calculated between the last point and every other point. Described like this ( being the index of the last point):

It will give you something like this: At the beginning, there will be a lot of variations but it will soon get close to the real remaining time.

Here's the final formula one more time:

With this tool, you can gauge at the logs and finally tell "now's the time to get a coffee!" Klemek
Junior software engineer

Go to top - Back to home -