Class WindowAccumulator
java.lang.Object
com.amalgamasimulation.utils.windowaccumulator.WindowAccumulator
- All Implemented Interfaces:
IWindowAccumulator
A class implementing a window accumulator for a sliding window of a fixed
size. It accumulates values added within a certain time window and allows
querying of statistical properties like sum, average, maximum, and minimum
for the values within this window.
- Author:
- Alexey Kirillov
-
Constructor Summary
ConstructorsConstructorDescriptionWindowAccumulator(double timeWindowSize) Standard constructor for the sliding window accumulator. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double time, double value) Adds a new statistical element to the accumulator.voidclear()Clears all the data from the accumulator.voidcompress(double time) Removes all outdated values relative to the specified time from the accumulator, effectively compressing the stored data to fit within the current time window.doubleget()Returns the sum of all values currently stored in the accumulator.doubleget(double time) Returns the sum of elements in the accumulator whose time of addition does not exceed the specified time.doublegetAvg()Returns the average value of all elements currently stored in the accumulator.doublegetAvg(double time) Returns the average value among all elements in the accumulator whose time of addition does not exceed the specified time.doublegetMax(double time) Returns the maximum value among all elements in the accumulator whose time of addition does not exceed the specified time.doublegetMin(double time) Returns the minimum value among all elements in the accumulator whose time of addition does not exceed the specified time.
-
Constructor Details
-
WindowAccumulator
public WindowAccumulator(double timeWindowSize) Standard constructor for the sliding window accumulator.- Parameters:
timeWindowSize- The duration (length) of the time window.
-
-
Method Details
-
add
public void add(double time, double value) Description copied from interface:IWindowAccumulatorAdds a new statistical element to the accumulator.- Specified by:
addin interfaceIWindowAccumulator- Parameters:
time- The time associated with the statistical element.value- The value of the statistical element.
-
get
public double get(double time) Description copied from interface:IWindowAccumulatorReturns the sum of elements in the accumulator whose time of addition does not exceed the specified time.- Specified by:
getin interfaceIWindowAccumulator- Parameters:
time- The maximum time up to which values are accumulated.- Returns:
- The sum of elements added to the accumulator up to the specified time.
-
get
public double get()Returns the sum of all values currently stored in the accumulator.- Returns:
- The total sum of all values in the accumulator.
-
getAvg
public double getAvg(double time) Description copied from interface:IWindowAccumulatorReturns the average value among all elements in the accumulator whose time of addition does not exceed the specified time.- Specified by:
getAvgin interfaceIWindowAccumulator- Parameters:
time- The maximum time up to which values are considered for averaging.- Returns:
- The average value of elements up to the specified time.
-
getAvg
public double getAvg()Returns the average value of all elements currently stored in the accumulator.- Returns:
- The average of all values in the accumulator.
-
getMax
public double getMax(double time) Description copied from interface:IWindowAccumulatorReturns the maximum value among all elements in the accumulator whose time of addition does not exceed the specified time.- Specified by:
getMaxin interfaceIWindowAccumulator- Parameters:
time- The maximum time up to which values are considered for finding the maximum.- Returns:
- The maximum value of elements up to the specified time.
-
getMin
public double getMin(double time) Description copied from interface:IWindowAccumulatorReturns the minimum value among all elements in the accumulator whose time of addition does not exceed the specified time.- Specified by:
getMinin interfaceIWindowAccumulator- Parameters:
time- The maximum time up to which values are considered for finding the minimum.- Returns:
- The minimum value of elements up to the specified time.
-
compress
public void compress(double time) Removes all outdated values relative to the specified time from the accumulator, effectively compressing the stored data to fit within the current time window.- Parameters:
time- The reference time for the compression operation.
-
clear
public void clear()Description copied from interface:IWindowAccumulatorClears all the data from the accumulator.- Specified by:
clearin interfaceIWindowAccumulator
-