net.i2p.stat

## Class Frequency

- java.lang.Object
- - net.i2p.stat.Frequency

-     public class Frequency
      extends Object

  Manage the calculation of a moving average event frequency over a certain period. This provides lifetime, and rolling average, frequency counts. Unlike Rate, it does not support "bucketed" averages. There is no tracking of the event frequency in the current or last bucket. There are no buckets at all. Depending on what you want, a rolling average might be better than buckets. Or not.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Frequency(long period)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `eventOccurred()` Take note that a new event occurred, recalculating all the averages and frequencies
    `double` | `getAverageEventsPerPeriod()` Calculate how many events would occur in a period given the current (rolling) average.
    `double` | `getAverageInterval()` on average over the last $period, after how many milliseconds are events coming in, as calculated during the last event occurrence?
    `long` | `getEventCount()` how many events have occurred within the lifetime of this stat?
    `double` | `getMaxAverageEventsPerPeriod()` Calculate how many events would occur in a period given the maximum rolling average.
    `long` | `getPeriod()` how long is this frequency averaged over? (ms)
    `double` | `getStrictAverageEventsPerPeriod()` using the strict average interval, how many events occur within an average period?
    `double` | `getStrictAverageInterval()` Over the lifetime of this stat, without any decay or weighting, what was the average interval between events? (ms)
    `void` | `recalculate()` Recalculate the averages
    `(package private) void` | `store(StringBuilder dest)` Appends the data of this frequency to the specified StringBuilder

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Frequency

          public Frequency(long period)

      Parameters:
        `period` - ms

  - ### Method Detail

    - #### eventOccurred

          public void eventOccurred()

      Take note that a new event occurred, recalculating all the averages and frequencies

    - #### getAverageEventsPerPeriod

          public double getAverageEventsPerPeriod()

      Calculate how many events would occur in a period given the current (rolling) average. Use getStrictAverageInterval() for the real lifetime average.

    - #### getAverageInterval

          public double getAverageInterval()

      on average over the last $period, after how many milliseconds are events coming in, as calculated during the last event occurrence?
      Returns:
        milliseconds; returns period + 1 if no events in previous period

    - #### getEventCount

          public long getEventCount()

      how many events have occurred within the lifetime of this stat?

    - #### getMaxAverageEventsPerPeriod

          public double getMaxAverageEventsPerPeriod()

      Calculate how many events would occur in a period given the maximum rolling average. Use getStrictAverageEventsPerPeriod() for the real lifetime average.

    - #### getPeriod

          public long getPeriod()

      how long is this frequency averaged over? (ms)

    - #### getStrictAverageEventsPerPeriod

          public double getStrictAverageEventsPerPeriod()

      using the strict average interval, how many events occur within an average period?

    - #### getStrictAverageInterval

          public double getStrictAverageInterval()

      Over the lifetime of this stat, without any decay or weighting, what was the average interval between events? (ms)
      Returns:
        milliseconds; returns Double.MAX_VALUE if no events ever

    - #### recalculate

          public void recalculate()

      Recalculate the averages

    - #### store

          void store(StringBuilder dest)

      Appends the data of this frequency to the specified StringBuilder
      Parameters:
        `dest` - to append data to