katgpucbf.fgpu.accum module
Compute statistics by bucketing into windows.
- class katgpucbf.fgpu.accum.Accum(window_size: int, zero: T)[source]
Bases:
GenericAccumulator for a single statistic.
The statistic is a linear measurement over intervals of time. Measurements over small intervals are provided to this class, which accumulates them. Time is divided into fixed “windows” (all the same length), with a total produced for each window for which at least some data is provided. If a window is missing some data, either because it was not provided or it was explicitly indicated that it was missing, then the window measurement will instead indicate that the sum is unknown.
Time is considered to be discrete (integer). Window intervals are timestamps that are multiples of window_size. Data cannot be added for intervals that cross window boundaries.
- Parameters:
window_size – Factor that divides timestamp window boundaries
zero – Value to initialise the accumulator to
- add(start_timestamp: int, end_timestamp: int, value: T | None) Measurement | None[source]
Add new data.
If the new data falls into a new window compared to the existing data or it completes the current window, then an instance of
Measurementis returned with the total for the previous window. Note that if both occur, the result for the old window is simply discarded.- Parameters:
start_timestamp – The time range for the extension
end_timestamp – The time range for the extension
value – The statistic measured over the given time range, or None if there was missing data in the range.
- Raises:
ValueError – If start_timestamp > end_timestamp
ValueError – If the new data overlaps or preceeds previous data
ValueError – If [start_timestamp, end_timestamp) crosses a window boundary