Add `Feed.get_ds_info()` to detect/compute sample rates

history_view
Tyler Goodlet 2022-09-01 15:22:14 -04:00
parent 5e98a30537
commit 2ef6460853
1 changed files with 29 additions and 3 deletions

View File

@ -1245,12 +1245,10 @@ class Feed:
@asynccontextmanager @asynccontextmanager
async def index_stream( async def index_stream(
self, self,
delay_s: Optional[int] = None delay_s: int = 1,
) -> AsyncIterator[int]: ) -> AsyncIterator[int]:
delay_s = 1 #delay_s or self._max_sample_rate
# XXX: this should be singleton on a host, # XXX: this should be singleton on a host,
# a lone broker-daemon per provider should be # a lone broker-daemon per provider should be
# created for all practical purposes # created for all practical purposes
@ -1276,6 +1274,34 @@ class Feed:
async def resume(self) -> None: async def resume(self) -> None:
await self.stream.send('resume') 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 @asynccontextmanager
async def install_brokerd_search( async def install_brokerd_search(