import os from flask import ( Flask, Blueprint, jsonify ) from peewee import SqliteDatabase from playhouse.shortcuts import model_to_dict from frigate.models import Event bp = Blueprint('frigate', __name__) def create_app(database: SqliteDatabase): app = Flask(__name__) @app.before_request def _db_connect(): database.connect() @app.teardown_request def _db_close(exc): if not database.is_closed(): database.close() app.register_blueprint(bp) return app @bp.route('/') def is_healthy(): return "Frigate is running. Alive and healthy!" @bp.route('/events') def events(): events = Event.select() return jsonify([model_to_dict(e) for e in events]) # @app.route('/debug/stats') # def stats(): # stats = {} # total_detection_fps = 0 # for name, camera_stats in camera_process_info.items(): # total_detection_fps += camera_stats['detection_fps'].value # stats[name] = { # 'camera_fps': round(camera_stats['camera_fps'].value, 2), # 'process_fps': round(camera_stats['process_fps'].value, 2), # 'skipped_fps': round(camera_stats['skipped_fps'].value, 2), # 'detection_fps': round(camera_stats['detection_fps'].value, 2), # 'pid': camera_stats['process'].pid, # 'capture_pid': camera_stats['capture_process'].pid, # 'frame_info': { # 'detect': camera_stats['detection_frame'].value, # 'process': object_processor.camera_data[name]['current_frame_time'] # } # } # stats['detectors'] = {} # for name, detector in detectors.items(): # stats['detectors'][name] = { # 'inference_speed': round(detector.avg_inference_speed.value*1000, 2), # 'detection_start': detector.detection_start.value, # 'pid': detector.detect_process.pid # } # stats['detection_fps'] = round(total_detection_fps, 2) # return jsonify(stats) # @app.route('//