From 3a190a04918b049d8c8a0ab6bdfac8c5051675bd Mon Sep 17 00:00:00 2001 From: bea Date: Mon, 18 Nov 2024 11:53:08 -0600 Subject: [PATCH] fix duplicate msgs --- ptgctl/tools/mock.py | 5 ++++- ptgctl/util/__init__.py | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ptgctl/tools/mock.py b/ptgctl/tools/mock.py index 336b0a9..41a0595 100644 --- a/ptgctl/tools/mock.py +++ b/ptgctl/tools/mock.py @@ -36,6 +36,7 @@ async def video(api, src=0, pos=0, width=0.3, shape=None, fps=15, speed=1, stepb '''Send video (by default your webcam) to the API.''' sid = CAM_POS_SIDS[pos] sid = f'{prefix or ""}{sid}' + tlast = 0 async with api.data_push_connect(sid, batch=True) as ws: async for im in _video_feed(src, fps, shape, speed=speed): if pos: @@ -46,7 +47,9 @@ async def video(api, src=0, pos=0, width=0.3, shape=None, fps=15, speed=1, stepb # print(load(dump_v3(im))) if stepbystep: input() - await ws.send_data([dump_v3(im)], [sid], [util.format_epoch_time(time.time())]) + t=time.time() + await ws.send_data([dump_v3(im)], [sid], [util.format_epoch_time(t, tlast)]) + tlast = t def _img_dump(im, format='jpeg'): from PIL import Image diff --git a/ptgctl/util/__init__.py b/ptgctl/util/__init__.py index 191ffbf..cb0e1ce 100644 --- a/ptgctl/util/__init__.py +++ b/ptgctl/util/__init__.py @@ -51,8 +51,12 @@ def parse_epoch_time(tid: str): def format_time(dt: datetime.datetime): return format_epoch_time(dt.timestamp()) -def format_epoch_time(tid: float): - return f'{int(tid * 1000)}-0' +def format_epoch_time(tid: float, tlast=None): + tms = int(tid * 1000) + i = 0 + if tlast and tms == int(tlast * 1000): + i = int((tid*1000 - tms)*100) + return f'{tms}-{i}' # misc