Skip to content

WindowedMetric ​

python
WindowedMetric(window_size: int) -> None

Tracks 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.

Source

Methods ​

add ​

python
add(outcome: str) -> None

Add 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").

Source

get_count ​

python
get_count(outcome: str) -> int

Get 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.

Source

get_percentage ​

python
get_percentage(outcome: str) -> float

Get 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.

Source

size ​

python
size() -> int

Get the current size of the window.

Returns:

  • int – The number of outcomes currently in the window.

Source