Reset Mechanism

This commit is contained in:
proitlab committed 2026-07-29 16:15:02 +07:00
1 parent e8893a3aa4
commit b63e2fa2fa
3 files changed
+11 -4

No files matched your search

+6 -3
View File
@@ -3,12 +3,16 @@ Production batch persistence for edge Jetson counter.
Mirrors frigate-counter SQLite schema + current_batch.json contract. Mirrors frigate-counter SQLite schema + current_batch.json contract.
""" """
import json import json
import os
import sqlite3 import sqlite3
import threading import threading
import time import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pathlib import Path from pathlib import Path
_SHMD = os.getenv("SHM_DIR", "/dev/shm/bytetrack-counter")
_RESET_FLAG = Path(f"{_SHMD}/.reset")
class BatchStore: class BatchStore:
def __init__( def __init__(
@@ -195,9 +199,8 @@ class BatchStore:
self.log('Ignore batch label cooldown finished') self.log('Ignore batch label cooldown finished')
def _check_reset_signal(self): def _check_reset_signal(self):
reset_file = Path(str(self.state_file) + ".reset") if _RESET_FLAG.exists():
if reset_file.exists(): _RESET_FLAG.unlink(missing_ok=True)
reset_file.unlink(missing_ok=True)
if self.current_state is not None: if self.current_state is not None:
self.log("External reset signal — clearing in-memory state") self.log("External reset signal — clearing in-memory state")
self.current_state = None self.current_state = None
+2
View File
@@ -11,6 +11,8 @@ OUTPUT_DIR=/opt/bytetrack-counter
DB_PATH=/opt/bytetrack-counter/bytetrack_counter.db DB_PATH=/opt/bytetrack-counter/bytetrack_counter.db
# JSON file persisting the current active batch state # JSON file persisting the current active batch state
STATE_FILE=/tmp/bytetrack_current_batch.json STATE_FILE=/tmp/bytetrack_current_batch.json
# Shared memory directory used for reset signal (touch .reset to clear counter state)
SHM_DIR=/dev/shm/bytetrack-counter
# --- Input source --- # --- Input source ---
# RTSP / HTTP live stream, or a local video file path # RTSP / HTTP live stream, or a local video file path
+3 -1
View File
@@ -31,6 +31,7 @@ CURRENT_BATCH_PATH = os.getenv("STATE_FILE", os.getenv("CURRENT_BATCH_PATH", f"{
CUTOFF_TIME = os.getenv("CUTOFF_TIME", os.getenv("DAILY_CUTOFF_TIME", "20:00")) CUTOFF_TIME = os.getenv("CUTOFF_TIME", os.getenv("DAILY_CUTOFF_TIME", "20:00"))
LIVE_STREAM_FRAME_PATH = os.getenv("LIVE_STREAM_FRAME_PATH", "/dev/shm/jetson-counter/live_frame.jpg") LIVE_STREAM_FRAME_PATH = os.getenv("LIVE_STREAM_FRAME_PATH", "/dev/shm/jetson-counter/live_frame.jpg")
SHM_DIR = os.getenv("SHM_DIR", "/dev/shm/bytetrack-counter")
SITE_NAME = os.getenv("SITE_NAME", "LIVE") SITE_NAME = os.getenv("SITE_NAME", "LIVE")
@@ -560,8 +561,9 @@ def api_reset():
paths.add(cb) paths.add(cb)
for p in paths: for p in paths:
Path(p).unlink(missing_ok=True) Path(p).unlink(missing_ok=True)
Path(str(p) + ".reset").touch()
Path(LIVE_STREAM_FRAME_PATH).unlink(missing_ok=True) Path(LIVE_STREAM_FRAME_PATH).unlink(missing_ok=True)
Path(SHM_DIR).mkdir(parents=True, exist_ok=True)
Path(f"{SHM_DIR}/.reset").touch()
except Exception: except Exception:
pass pass
return jsonify({"success": True, "message": "State + live frame cleared"}) return jsonify({"success": True, "message": "State + live frame cleared"})