First commit
This commit is contained in:
commit
dd9f68198c
4 changed files with 62 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
venv
|
||||||
|
env
|
||||||
|
dumps
|
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FROM python:3.12-alpine3.19
|
||||||
|
|
||||||
|
WORKDIR /simulator
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD ["python","-u","simulator.py"]
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
websockets
|
49
simulator.py
Executable file
49
simulator.py
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
from websockets.server import serve
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
teams = {"5a:45:55:53:00:01","5a:45:55:53:00:02","5a:45:55:53:00:03","5a:45:55:53:00:04","5a:45:55:53:00:06","5a:45:55:53:00:07","5a:45:55:53:00:09","5a:45:55:53:00:0a","5a:45:55:53:00:0b","5a:45:55:53:00:0c","5a:45:55:53:00:0d","5a:45:55:53:00:0f","5a:45:55:53:00:10","5a:45:55:53:00:11","5a:45:55:53:00:12","5a:45:55:53:00:14","5a:45:55:53:00:15","5a:45:55:53:00:16","5a:45:55:53:00:18"}
|
||||||
|
|
||||||
|
start = int(os.getenv('START',1682499937))
|
||||||
|
clock = start
|
||||||
|
step = 0.01
|
||||||
|
|
||||||
|
async def run_clock():
|
||||||
|
global clock
|
||||||
|
|
||||||
|
while True:
|
||||||
|
clock += step
|
||||||
|
await asyncio.sleep(step)
|
||||||
|
|
||||||
|
async def ws(ws, path):
|
||||||
|
global clock
|
||||||
|
id = json.loads(await ws.recv())["lastId"]
|
||||||
|
|
||||||
|
|
||||||
|
with open(f"dumps{path}.json") as f:
|
||||||
|
detections = json.loads(f.read())['detections']
|
||||||
|
|
||||||
|
for i in range(len(detections) - 1):
|
||||||
|
if detections[i]["id"] >= id and detections[i]["mac"] in teams and detections[i]["detection_timestamp"] > start:
|
||||||
|
timestamp = detections[i]["detection_timestamp"]
|
||||||
|
|
||||||
|
while timestamp > clock: await asyncio.sleep(timestamp - clock)
|
||||||
|
await ws.send(json.dumps([detections[i]]))
|
||||||
|
|
||||||
|
|
||||||
|
async def run_serve():
|
||||||
|
async with serve(ws, "0.0.0.0", 8080):
|
||||||
|
await asyncio.Future() # run forever
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
_ = asyncio.create_task(run_clock())
|
||||||
|
_ = asyncio.create_task(run_serve())
|
||||||
|
await asyncio.Future() # run forever
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
Loading…
Reference in a new issue