Add timestamp fuzzy matching and rename field to @timestamp
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Lauri Võsandi 2022-12-12 19:56:56 +02:00
parent 6bdd9e0fbf
commit 02d38d12ef

View File

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