Live Counter get total count per batch
This commit is contained in:
1 parent
fe220504fd
commit
e3ae89de3d
4 files changed
+82
-1
No files matched your search
@@ -5,6 +5,7 @@ lists OUTPUT_DIR MP4 files, streams via go2rtc for preview.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import requests
|
||||
from datetime import datetime
|
||||
@@ -34,6 +35,18 @@ FLASK_DEBUG = os.getenv("FLASK_DEBUG", "false").lower() == "true"
|
||||
_http_session = requests.Session()
|
||||
_http_session.timeout = 3
|
||||
|
||||
_FILENAME_RE = re.compile(r"batch_(\d+)_(\d{8})_\d{6}\.mp4")
|
||||
|
||||
|
||||
def _parse_filename(filename):
|
||||
m = _FILENAME_RE.match(filename)
|
||||
if m:
|
||||
batch_num = int(m.group(1))
|
||||
date_str = m.group(2)
|
||||
date_formatted = f"{date_str[:4]}-{date_str[4:6]}-{date_str[6:8]}"
|
||||
return batch_num, date_formatted
|
||||
return None, None
|
||||
|
||||
|
||||
def _api_get(base_url, path, default=None):
|
||||
try:
|
||||
@@ -107,6 +120,32 @@ def start_recount():
|
||||
return jsonify({"success": True, "stream_url": stream_url, "file": Path(mp4_path).name})
|
||||
|
||||
|
||||
@app.route("/api/batch-result")
|
||||
def api_batch_result():
|
||||
fpath = request.args.get("file", "")
|
||||
filename = Path(fpath).name
|
||||
batch_num, date_str = _parse_filename(filename)
|
||||
if batch_num is None:
|
||||
return jsonify({"success": False, "error": "Cannot parse batch number from filename"}), 200
|
||||
|
||||
data = _api_get(LIVE_API_URL, f"/api/day-detail/{date_str}")
|
||||
if not data:
|
||||
return jsonify({"success": False, "error": "Live API unreachable"}), 200
|
||||
|
||||
for b in data.get("batches", []):
|
||||
if b.get("batch_number") == batch_num:
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"batch_number": batch_num,
|
||||
"date": date_str,
|
||||
"count": b["count"],
|
||||
"start_time": b.get("start_time"),
|
||||
"end_time": b.get("end_time"),
|
||||
})
|
||||
|
||||
return jsonify({"success": False, "error": f"Batch #{batch_num} not found on {date_str}"}), 200
|
||||
|
||||
|
||||
@app.route("/api/stop-recount", methods=["POST"])
|
||||
def stop_recount():
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user