Live Counter get total count per batch 3
This commit is contained in:
1 parent
cc807d3b8b
commit
1a3f6ffb6f
2 files changed
+38
-10
No files matched your search
+24
-7
@@ -35,7 +35,7 @@ FLASK_DEBUG = os.getenv("FLASK_DEBUG", "false").lower() == "true"
|
|||||||
_http_session = requests.Session()
|
_http_session = requests.Session()
|
||||||
_http_session.timeout = 3
|
_http_session.timeout = 3
|
||||||
|
|
||||||
_FILENAME_RE = re.compile(r"batch_(\d+)_(\d{8})_\d{6}\.mp4")
|
_FILENAME_RE = re.compile(r"batch[_-](\d+)[_-](\d{8})[_-]\d{6}\.mp4", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
def _parse_filename(filename):
|
def _parse_filename(filename):
|
||||||
@@ -128,12 +128,16 @@ def api_batch_result():
|
|||||||
if batch_num is None:
|
if batch_num is None:
|
||||||
return jsonify({"success": False, "error": "Cannot parse batch number from filename"}), 200
|
return jsonify({"success": False, "error": "Cannot parse batch number from filename"}), 200
|
||||||
|
|
||||||
data = _api_get(LIVE_API_URL, f"/api/day-detail/{date_str}")
|
def _match_in_batches(batches):
|
||||||
if not data:
|
for b in batches:
|
||||||
return jsonify({"success": False, "error": "Live API unreachable"}), 200
|
if b.get("batch_number") == batch_num:
|
||||||
|
return b
|
||||||
|
return None
|
||||||
|
|
||||||
for b in data.get("batches", []):
|
data = _api_get(LIVE_API_URL, f"/api/day-detail/{date_str}")
|
||||||
if b.get("batch_number") == batch_num:
|
if data:
|
||||||
|
b = _match_in_batches(data.get("batches", []))
|
||||||
|
if b:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"batch_number": batch_num,
|
"batch_number": batch_num,
|
||||||
@@ -143,7 +147,20 @@ def api_batch_result():
|
|||||||
"end_time": b.get("end_time"),
|
"end_time": b.get("end_time"),
|
||||||
})
|
})
|
||||||
|
|
||||||
return jsonify({"success": False, "error": f"Batch #{batch_num} not found on {date_str}"}), 200
|
recent = _api_get(LIVE_API_URL, "/api/recent-batches?limit=100")
|
||||||
|
if recent:
|
||||||
|
for entry in recent if isinstance(recent, list) else recent.get("batches", []):
|
||||||
|
if isinstance(entry, dict) and entry.get("batch_number") == batch_num:
|
||||||
|
return jsonify({
|
||||||
|
"success": True,
|
||||||
|
"batch_number": batch_num,
|
||||||
|
"date": entry.get("date", date_str),
|
||||||
|
"count": entry["count"],
|
||||||
|
"start_time": entry.get("start_time"),
|
||||||
|
"end_time": entry.get("end_time"),
|
||||||
|
})
|
||||||
|
|
||||||
|
return jsonify({"success": False, "error": f"Batch #{batch_num} not found"}), 200
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/stop-recount", methods=["POST"])
|
@app.route("/api/stop-recount", methods=["POST"])
|
||||||
|
|||||||
@@ -490,15 +490,24 @@ async function loadBatchResult(filePath) {
|
|||||||
batchResultLoaded = false;
|
batchResultLoaded = false;
|
||||||
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
||||||
document.getElementById('live-label').textContent = 'Objects Counted';
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
||||||
document.getElementById('live-status').textContent = 'waiting...';
|
document.getElementById('live-count').textContent = '--';
|
||||||
|
document.getElementById('live-batch').textContent = '--';
|
||||||
|
document.getElementById('live-time').textContent = '--';
|
||||||
|
document.getElementById('live-status').textContent = 'no file selected';
|
||||||
document.getElementById('live-status').className = 'counter-status disconnected';
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
||||||
loadLiveProgress();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/batch-result?file=' + encodeURIComponent(filePath));
|
const res = await fetch('/api/batch-result?file=' + encodeURIComponent(filePath));
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
||||||
|
document.getElementById('live-count').textContent = '--';
|
||||||
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
||||||
|
document.getElementById('live-batch').textContent = '--';
|
||||||
|
document.getElementById('live-time').textContent = data.error || 'not found';
|
||||||
|
document.getElementById('live-status').textContent = 'not found';
|
||||||
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
||||||
batchResultLoaded = false;
|
batchResultLoaded = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -508,7 +517,9 @@ async function loadBatchResult(filePath) {
|
|||||||
document.getElementById('live-label').textContent = 'Batch #' + data.batch_number;
|
document.getElementById('live-label').textContent = 'Batch #' + data.batch_number;
|
||||||
document.getElementById('live-batch').textContent = data.batch_number;
|
document.getElementById('live-batch').textContent = data.batch_number;
|
||||||
document.getElementById('live-time').textContent = data.date;
|
document.getElementById('live-time').textContent = data.date;
|
||||||
document.getElementById('live-status').textContent = 'recorded \u00b7 ' + (data.start_time ? new Date(data.start_time).toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit'}) : '--') + ' \u2013 ' + (data.end_time ? new Date(data.end_time).toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit'}) : '--');
|
var startStr = data.start_time ? new Date(data.start_time).toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit'}) : '--';
|
||||||
|
var endStr = data.end_time ? new Date(data.end_time).toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit'}) : '--';
|
||||||
|
document.getElementById('live-status').textContent = 'recorded \u00b7 ' + startStr + ' \u2013 ' + endStr;
|
||||||
document.getElementById('live-status').className = 'counter-status connected';
|
document.getElementById('live-status').className = 'counter-status connected';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load batch result:', err);
|
console.error('Failed to load batch result:', err);
|
||||||
|
|||||||
Reference in new issue
Block a user