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
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(