Calculation of Time Estimate

Asked

Viewed 504 times

2

I am making a calculator for calculating Time for any distance on my site, but my question is in the execution algorithm.

The formula is as follows::

tempo previsto = tempo real x distância prevista / distância do tempo real elevada a 1.07.

But when I do this calculation in the calculator comes a broken result that I don’t know how I’m going to turn into an algorithm that returns hours, minutes and seconds. The source is the following link: http://www.penoasfalto.com.br/calculos.html

  1. Weather forecast for any distance:
  • You are using JAVASCRIPT or what programming language?

  • Jquery, a calculation condition is real time = 1h, predicted distance = 12, current distance = 11 km, estimated time of :1,097573872, this is the result in the calculator, now on the site the result is: 1h 05m 5q sec.

  • Convert the values to common units, do the calculation and then convert them to hours again. I suggest seconds (which is the smallest).

1 answer

1


https://jsfiddle.net/axgucsy6/

function calcularTempoTotalPrevisto( horas, minutos, segundos, distanciaPrevista, distanciaPercorrida ) {
  var horasTotalOcorrido = horas + ( (minutos * 60 + segundos) / 3600 );

  var horasTotalPrevisto = Math.pow( ( distanciaPrevista / distanciaPercorrida ), 1.07 ) * horasTotalOcorrido;

  var horasPrevisto = Math.floor( horasTotalPrevisto );
  var segundosPrevisto = ( horasTotalPrevisto - horasPrevisto ) * 3600;
  var minutosPrevisto = Math.floor( segundosPrevisto / 60 );
  segundosPrevisto = Math.round( segundosPrevisto - minutosPrevisto * 60 );

  return { "h": horasPrevisto, "m": minutosPrevisto, "s": segundosPrevisto }
}
  • Thanks I performed a similar calculation and by the way, it works only lack the implementation in jquery, thanks!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.