pysatl_tsp.core.scrubber.abstract
Module Contents
Classes
Abstract base class for handlers that produce window views of time series data. |
|
A sliding window container for time series data processing. |
Data
API
- class pysatl_tsp.core.scrubber.abstract.Scrubber(source: pysatl_tsp.core.Handler[Any, pysatl_tsp.core.T] | None = None)[source]
Bases:
pysatl_tsp.core.Handler[pysatl_tsp.core.T,pysatl_tsp.core.scrubber.abstract.ScrubberWindow[pysatl_tsp.core.T]]Abstract base class for handlers that produce window views of time series data.
Scrubbers consume individual data points and produce windows (sections) of the data stream. They are essential components for algorithms that need to analyze multiple data points together, such as moving averages, pattern detection, or feature extraction.
Concrete implementations of this class define specific windowing strategies such as fixed-size sliding windows, tumbling windows, or context-based windows.
- Parameters:
source – The handler providing input data, defaults to None
- Example:
# Example with a fixed-size sliding window scrubber (implementation not shown) # Create a data source data_source = SimpleDataProvider([10, 20, 30, 40, 50, 60, 70, 80]) # Create a sliding window scrubber with window size 3 window_scrubber = SlidingWindowScrubber(window_size=3, source=data_source) # Process windows for window in window_scrubber: # Each window is a ScrubberWindow instance print(f"Window values: {list(window.values)}") print(f"Window indices: {list(window.indices)}") # Calculate window statistics avg = sum(window.values) / len(window) print(f"Window average: {avg}") # Output: # Window values: [10, 20, 30] # Window indices: [0, 1, 2] # Window average: 20.0 # # Window values: [20, 30, 40] # Window indices: [1, 2, 3] # Window average: 30.0 # # ... and so on
Initialization
Initialize a scrubber.
- Parameters:
source – The handler providing input data, defaults to None
- abstractmethod __iter__() collections.abc.Iterator[pysatl_tsp.core.scrubber.abstract.ScrubberWindow[pysatl_tsp.core.T]][source]
Create an iterator that yields window views of the input data.
Concrete implementations define specific windowing strategies.
- Returns:
Iterator yielding ScrubberWindow instances
- class pysatl_tsp.core.scrubber.abstract.ScrubberWindow(values: collections.deque[pysatl_tsp.core.T] | None = None, indices: collections.deque[int] | None = None)[source]
Bases:
typing.Generic[pysatl_tsp.core.T]A sliding window container for time series data processing.
ScrubberWindow provides a specialized container for holding a window of time series data values along with their corresponding indices. It’s optimized for efficient append and remove operations at the ends of the window, making it suitable for sliding window algorithms in time series processing.
This class manages two parallel deques: one for the actual data values and another for their corresponding indices or positions in the original data stream.
- Parameters:
values – Deque containing the data values, defaults to None (empty deque)
indices – Deque containing the indices corresponding to values, defaults to None (if not provided, sequential indices starting from 0 are used)
- Raises:
ValueError – If the lengths of values and indices don’t match
- Example:
# Create an empty window window = ScrubberWindow() # Add values with automatic indices window.append(10.5) window.append(11.2) window.append(9.8) # Add value with explicit index window.append(12.1, index=100) # Get value by position in window first_value = window[0] # 10.5 # Get a slice of the window sub_window = window[1:3] # Contains 11.2 and 9.8 # Iterate through values for value in window: print(value) # Get original position of a value third_value_index = window.indices[2] # 2 fourth_value_index = window.indices[3] # 100
Initialization
Initialize a scrubber window.
- Parameters:
values – Deque containing the data values, defaults to None (empty deque)
indices – Deque containing the indices corresponding to values, defaults to None (if not provided, sequential indices starting from 0 are used)
- Raises:
ValueError – If the lengths of values and indices don’t match
- __eq__(other: object) bool[source]
Check if this window equals another window.
- Parameters:
other – Another object to compare with
- Returns:
True if other is a ScrubberWindow with equal values and indices
- __getitem__(key: int | slice) pysatl_tsp.core.T | pysatl_tsp.core.scrubber.abstract.ScrubberWindow[pysatl_tsp.core.T][source]
Get a value or sub-window by index or slice.
- Parameters:
key – Integer index or slice to retrieve
- Returns:
Single value (if key is int) or sub-window (if key is slice)
- Raises:
TypeError – If key is not an int or slice
- __iter__() collections.abc.Iterator[pysatl_tsp.core.T][source]
Create an iterator over the values in the window.
- Returns:
Iterator yielding window values
- __repr__() str[source]
Get a string representation of the window.
- Returns:
String representation showing values and indices
- append(value: pysatl_tsp.core.T, index: int | None = None) None[source]
Add a new value to the end of the window.
- Parameters:
value – The data value to append
index – The index/position of the value in the original data stream, defaults to None (auto-assigned as len(self))
- copy() pysatl_tsp.core.scrubber.abstract.ScrubberWindow[pysatl_tsp.core.T][source]
Create a deep copy of the window.
- Returns:
A new ScrubberWindow with copies of the values and indices
- pysatl_tsp.core.scrubber.abstract.__all__ = ['Scrubber', 'ScrubberWindow', 'T']