Skip to main content

Filters

This class implements filters used by the robot:

filters.py
loading...

Time Series Filter

This class manages a dictionary of keys and filter pools, allowing for multiple time series filters to be run in parallel. The class looks for a running sequence of data events over a given timespan.

The time series filter describes by four parameters:

  • threshold - this is the count of events in any filter pool that must be reached to fire the time series notification
  • timespan - this is the window over which a time series is evaluated
  • ignorespan - after firing, this is the period when the filter ignores new events for a given key
  • notification - this is the callable method that is fired when a filter pool reaches the threshold count of events

Objects are added to this filter with the add method:

Adding events to the filter pool

The filter first checks if there is a filter pool for the given key and if not, a filter pool is created. The data is then added to the filter pool. When adding to a filter pool, a check is made to see if the pool is in an ignore state. During the ignore timespan the add method ignores any objects passed. If not in an ignore state, the current event is added to the pool.

Next the filter prunes all filter pools. This removes any events that were recorded prior to the filter window.

Finally the filter pool is checked against the threshold. If we have reached the threshold for this time series, the notification for this filter is raised and the pool is reset.