Sliding Window
Circular buffer implementation for real-time motion data streaming.
This module provides the SlidingWindow class, a thread-safe circular buffer designed for high-frequency motion data. It maintains a fixed-size history of samples and supports dynamic resizing.
SlidingWindow
Thread-safe sliding window buffer for storing samples with timestamps.
This class implements a circular buffer that maintains a fixed-size window
of the most recent samples. When the buffer is full, new samples overwrite
the oldest ones. The internal data shape is strictly maintained as a 3D
tensor: (Time, Signals, Dimensions).
| Parameters: |
|
|---|
Examples:
>>> window = SlidingWindow(max_length=100, n_signals=1, n_dims=3)
>>> window.append([1.0, 2.0, 3.0])
>>> window.append([4.0, 5.0, 6.0], timestamp=1234567890.0)
>>> data, timestamps = window.to_tensor()
>>> print(window.is_full) # False
Source code in pyeyesweb/data_models/sliding_window.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
is_full
property
Check if the sliding window buffer is at maximum capacity.
max_length
property
writable
Maximum capacity of the buffer.
n_dims
property
The number of dimensions per node.
n_signals
property
The number of entities (signals) tracked by the window.
__len__()
__repr__()
Return a concise representation showing state and shape.
Source code in pyeyesweb/data_models/sliding_window.py
append(sample, timestamp=None)
Append a new sample to the sliding window.
Accepts scalars, flat lists, or shaped numpy arrays, and automatically
reshapes them to fit the configured (n_signals, n_dims) structure.
| Parameters: |
|
|---|
Source code in pyeyesweb/data_models/sliding_window.py
reset()
Clear all data from the window and reset buffers with NaNs.
to_flat_array()
Return the contents flattened to (Time, Signals * Dimensions).
| Returns: |
|
|---|
Source code in pyeyesweb/data_models/sliding_window.py
to_tensor()
Return the contents as a 3D tensor of shape (Time, Signals, Dimensions).
| Returns: |
|
|---|