WindowedMetric
python
WindowedMetric(window_size: int) -> NoneTracks occurrences of categorical outcomes over a rolling window.
This class maintains a circular buffer of outcome strings and efficiently tracks counts for each category to enable O(1) percentage calculations.
Initialize the windowed metric tracker.
Parameters:
window_size(int) – Maximum number of outcomes to track in the rolling window.
Methods
add
python
add(outcome: str) -> NoneAdd a new outcome to the rolling window.
If the window is full, the oldest outcome is removed and its count is decremented before the new outcome is added.
Parameters:
outcome(str) – The outcome category to add (for example, "win", "loss", "truncated").
get_count
python
get_count(outcome: str) -> intGet the count of a specific outcome in the current window.
Parameters:
outcome(str) – The outcome category to query.
Returns:
int– The count of the specified outcome in the window.
get_percentage
python
get_percentage(outcome: str) -> floatGet the percentage of a specific outcome in the current window.
Parameters:
outcome(str) – The outcome category to query.
Returns:
float– The percentage (0-100) of the specified outcome in the window.
size
python
size() -> intGet the current size of the window.
Returns:
int– The number of outcomes currently in the window.