store events in tinydb

This commit is contained in:
Blake Blackshear 2020-10-26 07:49:44 -05:00
parent d67a56d37e
commit 422cd52049
3 changed files with 16 additions and 2 deletions

View File

@ -32,7 +32,8 @@ RUN pip3 wheel --wheel-dir=/wheels \
paho-mqtt \
PyYAML \
matplotlib \
click
click \
tinydb
FROM scratch

View File

@ -42,7 +42,8 @@ RUN pip3 wheel --wheel-dir=/wheels \
paho-mqtt \
PyYAML \
matplotlib \
click
click \
tinydb
FROM scratch

View File

@ -7,6 +7,7 @@ import json
import datetime
import subprocess as sp
import queue
from tinydb import TinyDB
class EventProcessor(threading.Thread):
def __init__(self, config, camera_processes, cache_dir, clip_dir, event_queue, stop_event):
@ -19,6 +20,7 @@ class EventProcessor(threading.Thread):
self.event_queue = event_queue
self.events_in_process = {}
self.stop_event = stop_event
self.db = TinyDB(f"{os.path.join(self.clip_dir, 'events')}.json")
def refresh_cache(self):
cached_files = os.listdir(self.cache_dir)
@ -176,6 +178,16 @@ class EventProcessor(threading.Thread):
self.events_in_process[event_data['id']] = event_data
if event_type == 'end':
self.db.insert({
'id': event_data['id'],
'label': event_data['label'],
'camera': camera,
'start_time': event_data['start_time'],
'end_time': event_data['end_time'],
'top_score': event_data['top_score'],
'false_positive': event_data['false_positive'],
'zones': list(event_data['entered_zones'])
})
if len(self.cached_clips) > 0 and not event_data['false_positive']:
self.create_clip(camera, event_data, save_clips_config.get('pre_capture', 30))
del self.events_in_process[event_data['id']]