@VisibleForTesting
    long value(long time) {
      // We expect that the data time positions are strictly increasing and the time is greater than
      // any of the data position time. This is ensured by using System.nanoTime().
      long sum = 0L;
      long lastTime = time;
      long minTime = lastTime - windowTimeSize;
      int pos = nextPos - 1;
      do {
        // Loop the window
        if (pos < 0) {
          pos = windowDataSize - 1;
        }
        // If we are at the end of the window
        if (data[pos].nanoTime < minTime) {
          sum += (lastTime - minTime) * data[pos].value;
          break;
        }
        sum += (lastTime - data[pos].nanoTime) * data[pos].value;
        lastTime = data[pos].nanoTime;
        pos--;
      } while (pos != nextPos - 1);
      // If we exited the loop and we did not have enough data point estimate the data with the last
      // known point
      if (pos == nextPos - 1 && data[nextPos].nanoTime > minTime) {
        sum += (lastTime - minTime) * data[nextPos].value;
      }
      return Math.round((double)sum / (double)windowTimeSize);
    }
Calculates the average for the last windowTimeSize window.
@return The average
llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonExecutorMetrics.java