function calculateStats(qt) {
  let median = 0;
  let average = 0;
  let percentile95th = 0;
  const stats = {};
  const length = qt.length;

  // sort the queue time array
  qt.sort((a, b) => a - b);

  // calculate sum of queue time
  const sum = qt.reduce((a, b) => a + b, ZERO);

  // calculate middle of array
  const middle = Math.floor(length / TWO);
  average = sum / length;

  // calculate median
  if (length % TWO) {
    median = qt[middle];
  } else {
    median = (qt[middle - ONE] + qt[middle]) / FLOAT_TWO;
  }

  // calculate 95th Percentile
  const index = Math.round(PERCENTILE_95TH * length);
  percentile95th = qt[index - ONE];

  // construct stats object
  stats.averageQueueTimeMillis = average.toFixed(TWO);
  stats.medianQueueTimeMillis = median.toFixed(TWO);
  stats.queueTime95thMillis = percentile95th;

  return stats;
}
/**
 * Calculate Statistics based on queue timing array.
 *
 * @param {array} qt - array of queue timings
 * @returns {object} stats - statistics based on queue timing array
 *     i.e median, average and 95th Percentile
 */
Calculate Statistics based on queue timing array.
@param {array} qt - array of queue timings
@returns {object} stats - statistics based on queue timing array
i.e median, average and 95th Percentile
Calculate Statistics based on queue timing array . @param { array } qt - array of queue timings @returns { object } stats - statistics based on queue timing array i . e median average and 95th Percentile
function calculateStats(qt) {
  let median = 0;
  let average = 0;
  let percentile95th = 0;
  const stats = {};
  const length = qt.length;
  qt.sort((a, b) => a - b);
  const sum = qt.reduce((a, b) => a + b, ZERO);
  const middle = Math.floor(length / TWO);
  average = sum / length;
  if (length % TWO) {
    median = qt[middle];
  } else {
    median = (qt[middle - ONE] + qt[middle]) / FLOAT_TWO;
  }
  const index = Math.round(PERCENTILE_95TH * length);
  percentile95th = qt[index - ONE];
  stats.averageQueueTimeMillis = average.toFixed(TWO);
  stats.medianQueueTimeMillis = median.toFixed(TWO);
  stats.queueTime95thMillis = percentile95th;
  return stats;
}
function calculateStats ( qt ) { let median = 0 ; let average = 0 ; let percentile95th = 0 ; const stats = { } ; const length = qt . length ; qt . sort ( ( a , b ) => a - b ) ; const sum = qt . reduce ( ( a , b ) => a + b , ZERO ) ; const middle = Math . floor ( length / TWO ) ; average = sum / length ; if ( length % TWO ) { median = qt [ middle ] ; } else { median = ( qt [ middle - ONE ] + qt [ middle ] ) / FLOAT_TWO ; } const index = Math . round ( PERCENTILE_95TH * length ) ; percentile95th = qt [ index - ONE ] ; stats . averageQueueTimeMillis = average . toFixed ( TWO ) ; stats . medianQueueTimeMillis = median . toFixed ( TWO ) ; stats . queueTime95thMillis = percentile95th ; return stats ; }
Calculate Statistics based on queue timing array.
Calculate Statistics based on queue timing array .
// sort the queue time array // calculate sum of queue time // calculate middle of array // calculate median // calculate 95th Percentile // construct stats object