logica for calculation of average connection time in seconds

Asked

Viewed 112 times

0

for example: A telemarketing assistant takes 50 calls in a day. however there is a target of 330 seconds per call, which is 6 minutes maximum. What I want to do is an algorithm where I can put the connection time in the input, then calculate the media based on the first link, as I add the next few minutes of calls, would add up based on the number of times I put in the number of minutes of call. I’ve done something, it seems efficient but the question of the sum being relative to how many times I add the time of the links does not work, but help me?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>calculo de TMO</title>
</head>
<body>
  <section>
   
      <div class="centro">
          tempo de ligação van gogh:
          <input class="tempo" type="text"><br>
        
          <button onclick="clicar()">calcular</button>
          <p class="calcular"></p>
      
      </div>
  
  </section>
  <script>
    
      function clicar(){
          var tempo = document.querySelector(".tempo").value;
          var resultado = 0;
          for(var i = 0; i < 100; i++){
          resultado = parseInt(tempo) * i * 60 /  i ;
          }
          document.querySelector(".calcular").innerHTML = resultado;
      }
      
  </script>
</body>
</html>

  • It’s hard to understand what you want. Improve your Portuguese.

1 answer

0

From what I can understand, you want to calculate the average of the calls, and every time you click add, you want to calculate the average and show it right? First I added a few more things to have a better output to look more beautiful

 <div class="centro">
      tempo de ligação van gogh em segundos:
      <input class="tempo" type="text"><br>
    
      <button onclick="clicar()">calcular</button>
      <p>Foram efetuadas: <span class="numeroLigacoes">0</span> ligações </br>A media de tempo é: <span class="calcular">0</span> segundos. ou <span class="minutos">0</span> minutos. ou <span class="horas">0</span> horas</p>
  
  </div>

In javascript, I really can’t understand the logic you’re doing in your code, but if you’re going to calculate the average of the links, you’ll need to put all the links in an array, add them up and then divide by the number of existing links in the array.

var tempo_medio_segundos = 0;
var ligacoes = [];
    function clicar(){
        var tempo = document.querySelector(".tempo").value; //Pega o valor do input
        ligacoes.push(tempo); //Joga ele dentro de um array
        var media = 0; //Limpa a variavel media
        for (let i = 0; i < ligacoes.length; i++) {
            media = media + parseInt(ligacoes[i]); //Soma todas as ligações
        }
        tempo_medio_segundos = media / ligacoes.length; //Divide essa soma para ter a media
        tempo_medio_segundos.toFixed(1); //Não me lembro da função que faz isso, mas em teoria essa função corta os numeros depois da virgula
        document.querySelector(".calcular").innerHTML = tempo_medio_segundos;
        document.querySelector(".minutos").innerHTML = tempo_medio_segundos / 60; //conversao segundos para minutos
        document.querySelector(".horas").innerHTML = (tempo_medio_segundos / 60) / 60; //conversao segundos para horas
        document.querySelector(".numeroLigacoes").innerHTML = ligacoes.length; //quantas ligações foram efetuadas
    }

The array value must be declared outside the function so that when it is executed, it does not "Resete" its value. The input should be in seconds. If this code is totally contrary to what you wanted, please rephrase the issue for better understanding. If you’ve solved your problem, good night, if you have any other questions just call :)

Browser other questions tagged

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