From 2ef6460853c9889b891f45f2731ecf8c499d081e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 1 Sep 2022 15:22:14 -0400 Subject: [PATCH] Add `Feed.get_ds_info()` to detect/compute sample rates --- piker/data/feed.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/piker/data/feed.py b/piker/data/feed.py index a2b64c44..13495178 100644 --- a/piker/data/feed.py +++ b/piker/data/feed.py @@ -1245,12 +1245,10 @@ class Feed: @asynccontextmanager async def index_stream( self, - delay_s: Optional[int] = None + delay_s: int = 1, ) -> AsyncIterator[int]: - delay_s = 1 #delay_s or self._max_sample_rate - # XXX: this should be singleton on a host, # a lone broker-daemon per provider should be # created for all practical purposes @@ -1276,6 +1274,34 @@ class Feed: async def resume(self) -> None: await self.stream.send('resume') + def get_ds_info( + self, + ) -> tuple[float, float, float]: + ''' + Compute the "downsampling" ratio info between the historical shm + buffer and the real-time (HFT) one. + + Return a tuple of the fast sample period, historical sample + period and ratio between them. + + ''' + times = self.hist_shm.array['time'] + end = pendulum.from_timestamp(times[-1]) + start = pendulum.from_timestamp(times[times != times[-1]][-1]) + hist_step_size_s = (end - start).seconds + + times = self.rt_shm.array['time'] + end = pendulum.from_timestamp(times[-1]) + start = pendulum.from_timestamp(times[times != times[-1]][-1]) + rt_step_size_s = (end - start).seconds + + ratio = hist_step_size_s / rt_step_size_s + return ( + rt_step_size_s, + hist_step_size_s, + ratio, + ) + @asynccontextmanager async def install_brokerd_search(