Better index step value scanning by checking with our expected set
parent
adeb969810
commit
7ec30efff4
|
@ -217,6 +217,9 @@ def render_baritems(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_sample_rates: set[float] = {1, 60}
|
||||||
|
|
||||||
|
|
||||||
class Viz(msgspec.Struct): # , frozen=True):
|
class Viz(msgspec.Struct): # , frozen=True):
|
||||||
'''
|
'''
|
||||||
(Data) "Visualization" compound type which wraps a real-time
|
(Data) "Visualization" compound type which wraps a real-time
|
||||||
|
@ -284,15 +287,33 @@ class Viz(msgspec.Struct): # , frozen=True):
|
||||||
reset: bool = False,
|
reset: bool = False,
|
||||||
|
|
||||||
) -> float:
|
) -> float:
|
||||||
|
|
||||||
|
# attempt to dectect the best step size by scanning a sample of
|
||||||
|
# the source data.
|
||||||
if self._index_step is None:
|
if self._index_step is None:
|
||||||
|
|
||||||
index = self.shm.array[self.index_field]
|
index = self.shm.array[self.index_field]
|
||||||
isample = index[:16]
|
isample = index[:16]
|
||||||
mxdiff = np.diff(isample).max()
|
|
||||||
|
mxdiff: None | float = None
|
||||||
|
for step in np.diff(isample):
|
||||||
|
if step in _sample_rates:
|
||||||
|
if (
|
||||||
|
mxdiff is not None
|
||||||
|
and step != mxdiff
|
||||||
|
):
|
||||||
|
raise ValueError(
|
||||||
|
f'Multiple step sizes detected? {mxdiff}, {step}'
|
||||||
|
)
|
||||||
|
mxdiff = step
|
||||||
|
|
||||||
self._index_step = max(mxdiff, 1)
|
self._index_step = max(mxdiff, 1)
|
||||||
if (
|
if (
|
||||||
mxdiff < 1
|
mxdiff < 1
|
||||||
or 1 < mxdiff < 60
|
or 1 < mxdiff < 60
|
||||||
):
|
):
|
||||||
|
# TODO: remove this once we're sure the above scan loop
|
||||||
|
# is rock solid.
|
||||||
breakpoint()
|
breakpoint()
|
||||||
|
|
||||||
return self._index_step
|
return self._index_step
|
||||||
|
|
Loading…
Reference in New Issue