mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
saving events and simple endpoint
This commit is contained in:
parent
be1fcbbdf8
commit
5512bb2e06
@ -91,15 +91,18 @@ flask_db = FlaskDB(app)
|
||||
db = flask_db.database
|
||||
log = logging.getLogger('werkzeug')
|
||||
log.setLevel(logging.ERROR)
|
||||
peewee_log = logging.getLogger('peewee')
|
||||
peewee_log.addHandler(logging.StreamHandler())
|
||||
peewee_log.setLevel(logging.DEBUG)
|
||||
|
||||
class Event(flask_db.Model):
|
||||
id = CharField(null=False, primary_key=True, max_length=30)
|
||||
label = CharField(index=True, max_length=20)
|
||||
camera = CharField(index=True, max_length=20)
|
||||
start_time = DateTimeField(),
|
||||
end_time = DateTimeField(),
|
||||
top_score = FloatField(),
|
||||
false_positive = BooleanField(),
|
||||
start_time = DateTimeField()
|
||||
end_time = DateTimeField()
|
||||
top_score = FloatField()
|
||||
false_positive = BooleanField()
|
||||
zones = JSONField()
|
||||
|
||||
def init_db():
|
||||
@ -303,7 +306,7 @@ def main():
|
||||
camera_process['process'].start()
|
||||
print(f"Camera process started for {name}: {camera_process['process'].pid}")
|
||||
|
||||
event_processor = EventProcessor(CONFIG, camera_process_info, CACHE_DIR, CLIPS_DIR, event_queue, stop_event)
|
||||
event_processor = EventProcessor(CONFIG, camera_process_info, CACHE_DIR, CLIPS_DIR, event_queue, stop_event, Event)
|
||||
event_processor.start()
|
||||
|
||||
object_processor = TrackedObjectProcessor(CONFIG['cameras'], client, MQTT_TOPIC_PREFIX, tracked_objects_queue, event_queue, stop_event)
|
||||
@ -353,9 +356,7 @@ def main():
|
||||
|
||||
@app.route('/events')
|
||||
def events():
|
||||
events = Event.select().dicts()
|
||||
# if events is None:
|
||||
# return jsonify([])
|
||||
events = Event.select()
|
||||
return jsonify([model_to_dict(e) for e in events])
|
||||
|
||||
@app.route('/debug/stats')
|
||||
|
@ -7,10 +7,9 @@ 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):
|
||||
def __init__(self, config, camera_processes, cache_dir, clip_dir, event_queue, stop_event, Event):
|
||||
threading.Thread.__init__(self)
|
||||
self.config = config
|
||||
self.camera_processes = camera_processes
|
||||
@ -20,7 +19,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")
|
||||
self.Event = Event
|
||||
|
||||
def refresh_cache(self):
|
||||
cached_files = os.listdir(self.cache_dir)
|
||||
@ -178,16 +177,17 @@ 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'])
|
||||
})
|
||||
self.Event.create(
|
||||
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']]
|
||||
|
Loading…
Reference in New Issue
Block a user