Add timestamp fuzzy matching and rename field to @timestamp
continuous-integration/drone Build is passing Details

This commit is contained in:
Lauri Võsandi 2022-12-12 19:56:56 +02:00
parent 6bdd9e0fbf
commit 02d38d12ef
1 changed files with 10 additions and 4 deletions

View File

@ -51,6 +51,7 @@ SOURCE_NAME = os.environ["SOURCE_NAME"]
SLIDE_WINDOW = 2
DCT_BLOCK_SIZE = 8
UPLOAD_FRAMESKIP = 3
CLOCK_SKEW_TOLERANCE = timedelta(seconds=3)
# Percentage of blocks active to consider movement in whole frame
THRESHOLD_RATIO = int(os.getenv("THRESHOLD_RATIO", "5"))
@ -273,11 +274,14 @@ async def motion_detector(reference_frame, download_queue, upload_queue):
# Handle event start
if motion_detected and not event_id:
result = await app.ctx.coll.find_one_and_update({
"timestamp": dt, # TODO: Account for clock skew
"@timestamp": {
"$lte": dt + CLOCK_SKEW_TOLERANCE,
"$gte": dt - CLOCK_SKEW_TOLERANCE,
},
"source": SOURCE_NAME,
}, {
"$setOnInsert": {
"timestamp": dt,
"@timestamp": dt,
"source": SOURCE_NAME,
"event": "motion-detected",
"started": dt,
@ -552,8 +556,10 @@ async def setup_db(app, loop):
app.ctx.db = AsyncIOMotorClient(MONGO_URI).get_default_database()
app.ctx.coll = app.ctx.db[MONGO_COLLECTION]
app.ctx.coll.create_index([
("timestamp", pymongo.ASCENDING),
("source", pymongo.ASCENDING)], unique=True)
("@timestamp", pymongo.ASCENDING)])
app.ctx.coll.create_index([
("source", pymongo.ASCENDING),
("@timestamp", pymongo.ASCENDING)], unique=True)
app.ctx.last_frame = None
app.ctx.event_frame = asyncio.Event()
app.ctx.event_id = None