|
| 1 | +from pathlib import Path |
| 2 | +import asyncio |
| 3 | +import contextlib |
| 4 | +import sys |
| 5 | + |
| 6 | +from hat import aio |
| 7 | + |
| 8 | +from hat.event import common |
| 9 | +import hat.event.backends.lmdb |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + with contextlib.suppress(asyncio.CancelledError): |
| 14 | + aio.run_asyncio(async_main()) |
| 15 | + |
| 16 | + |
| 17 | +async def async_main(): |
| 18 | + db_path = Path(sys.argv[1]) |
| 19 | + |
| 20 | + server_id = 1 |
| 21 | + group_id = 0 |
| 22 | + point_count = 2000 |
| 23 | + interval = 5 |
| 24 | + retention = 24 * 60 * 60 |
| 25 | + |
| 26 | + conf = {'db_path': str(db_path), |
| 27 | + 'identifier': None, |
| 28 | + 'flush_period': 1, |
| 29 | + 'cleanup_period': 1, |
| 30 | + 'conditions': [], |
| 31 | + 'latest': {'subscriptions': []}, |
| 32 | + 'timeseries': [{'order_by': 'SOURCE_TIMESTAMP', |
| 33 | + 'subscriptions': [['eds', 'timeseries', |
| 34 | + str(group_id), '?']], |
| 35 | + 'limit': {'duration': retention}}]} |
| 36 | + |
| 37 | + backend = await aio.call(hat.event.backends.lmdb.info.create, conf, None, |
| 38 | + None) |
| 39 | + |
| 40 | + try: |
| 41 | + t = 0 |
| 42 | + session_id = 0 |
| 43 | + |
| 44 | + while t < retention: |
| 45 | + session_id += 1 |
| 46 | + events = [common.Event(id=common.EventId(server_id, session_id, |
| 47 | + point_id + 1), |
| 48 | + type=('eds', 'timeseries', str(group_id), |
| 49 | + str(point_id)), |
| 50 | + timestamp=common.Timestamp(t, 0), |
| 51 | + source_timestamp=common.Timestamp(t, 0), |
| 52 | + payload=None) |
| 53 | + for point_id in range(point_count)] |
| 54 | + await backend.register(events) |
| 55 | + |
| 56 | + t += interval |
| 57 | + |
| 58 | + finally: |
| 59 | + await aio.uncancellable(backend.async_close()) |
| 60 | + |
| 61 | + |
| 62 | +if __name__ == '__main__': |
| 63 | + main() |
0 commit comments