title: Smart progress bar ETA computation
body: <p>In many applications, we have some progress bar for a file download, for a compression task, for a search, etc. We all often use progress bars to let users know something is happening. And if we know some details like just how much work has been done and how much is left to do, we can even give a time estimate, often by extrapolating from how much time it's taken to get to the current progress level.</p>
  
  <p><a href="https://i.stack.imgur.com/QOIIx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QOIIx.png" alt="compression ETA screenshot"></a><br>
  <sub>(source: <a href="http://jameslao.com/wp-content/uploads/2008/01/winrar-progress-bar.png" rel="noreferrer">jameslao.com</a>)</sub>  </p>
  
  <p>But we've also seen programs which this Time Left "ETA" display is just comically bad. It claims a file copy will be done in 20 seconds, then one second later it says it's going to take 4 days, then it flickers again to be 20 minutes.  It's not only unhelpful, it's confusing!
  The reason the ETA varies so much is that the progress rate itself can vary and the programmer's math can be overly sensitive.</p>
  
  <p>Apple sidesteps this by just avoiding any accurate prediction and just giving vague estimates! 
  <a href="https://i.stack.imgur.com/Tu5Wf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Tu5Wf.png" alt="Apple&#39;s vague evasion"></a><br>
  <sub>(source: <a href="https://download.autodesk.com/esd/mudbox/help2009/images/MED/DaliSP1/English/Install_licensing/install_progress_MAC.png" rel="noreferrer">autodesk.com</a>)</sub>  </p>
  
  <p>That's annoying too, do I have time for a quick break, or is my task going to be done in 2 more seconds? If the prediction is too fuzzy, it's pointless to make any prediction at all.</p>
  
  <p><strong>Easy but wrong methods</strong></p>
  
  <p>As a first pass ETA computation, probably we all just make a function like if p is the fractional percentage that's done already, and t is the time it's taken so far, we output t*(1-p)/p as the estimate of how long it's going to take to finish.  This simple ratio works "OK" but it's also terrible especially at the end of computation. If your slow download speed keeps a copy slowly advancing happening overnight, and finally in the morning, something kicks in and the copy starts going at full speed at 100X faster, your ETA at 90% done may say "1 hour", and 10 seconds later you're at 95% and the ETA will say "30 minutes" which is clearly an embarassingly poor guess.. in this case "10 seconds" is a much, much, much better estimate.</p>
  
  <p>When this happens you may think to change the computation to use <strong>recent</strong> speed, not average speed, to estimate ETA. You take the average download rate or completion rate over the last 10 seconds, and use that rate to project how long completion will be. That performs quite well in the previous overnight-download-which-sped-up-at-the-end example, since it will give very good final completion estimates at the end.  But this still has big problems.. it causes your ETA to bounce wildly when your rate varies quickly over a short period of time, and you get the "done in 20 seconds, done in 2 hours, done in 2 seconds, done in 30 minutes" rapid display of programming shame.</p>
  
  <p><strong>The actual question:</strong></p>
  
  <p>What is the best way to compute an estimated time of completion of a task, given the time history of the computation?  I am not looking for links to GUI toolkits or Qt libraries.  I'm asking about the <strong>algorithm</strong> to generate the most sane and accurate completion time estimates.</p>
  
  <p>Have you had success with math formulas?  Some kind of averaging, maybe by using the mean of the rate over 10 seconds with the rate over 1 minute with the rate over 1 hour?  Some kind of artificial filtering like "if my new estimate varies too much from the previous estimate, tone it down, don't let it bounce too much"? Some kind of fancy history analysis where you integrate progress versus time advancement to find standard deviation of rate to give statistical error metrics on completion? </p>
  
  <p>What have you tried, and what works best?</p>