diff --git a/edc-web/app/__pycache__/models.cpython-311.pyc b/edc-web/app/__pycache__/models.cpython-311.pyc index 0a26320..6346ae4 100644 Binary files a/edc-web/app/__pycache__/models.cpython-311.pyc and b/edc-web/app/__pycache__/models.cpython-311.pyc differ diff --git a/edc-web/app/models.py b/edc-web/app/models.py index f8663df..0bec9c8 100644 --- a/edc-web/app/models.py +++ b/edc-web/app/models.py @@ -211,15 +211,22 @@ def get_all_test_data_for_export(serial: str = "", date_from: str = "", conn.close() -def get_automation_averages(dnt_id: int) -> dict: - """获取自动化测试的平均值(排除失败记录 state=3)""" +def get_automation_averages(dnt_id: int, since: str = None) -> dict: + """获取本次自动化测试的平均值 + + since: ISO 时间字符串,只统计此时间之后的测试记录 + 速度从 dm/s 转换为 m/s(÷10) + """ conn = get_conn() try: with conn.cursor() as cur: - # 只计算最近一批自动化测试的平均值 - # 取该设备 tb_state_tst 中与 tb_serialnet state=2 对应的记录 + where = "dnt_id=%s" + params = [dnt_id] + if since: + where += " AND create_time >= %s" + params.append(since) cur.execute( - "SELECT AVG(ppvalue) as avg_ppvalue, " + f"SELECT AVG(ppvalue) as avg_ppvalue, " "AVG(idle_freq) as avg_idle_freq, " "AVG(enter_freq) as avg_enter_freq, " "AVG(exit_freq) as avg_exit_freq, " @@ -227,14 +234,20 @@ def get_automation_averages(dnt_id: int) -> dict: "AVG(exit_dist) as avg_exit_dist, " "AVG(enter_speed) as avg_enter_speed, " "AVG(exit_speed) as avg_exit_speed " - "FROM tb_state_tst WHERE dnt_id=%s", - (dnt_id,), + f"FROM tb_state_tst WHERE {where}", + params, ) row = cur.fetchone() finally: conn.close() if row: - return {k: round(v, 2) if v else 0 for k, v in row.items()} + result = {k: round(v, 2) if v else 0 for k, v in row.items()} + # 速度 dm/s → m/s + if result.get("avg_enter_speed"): + result["avg_enter_speed"] = round(result["avg_enter_speed"] / 10, 2) + if result.get("avg_exit_speed"): + result["avg_exit_speed"] = round(result["avg_exit_speed"] / 10, 2) + return result return {} diff --git a/edc-web/app/routes/__pycache__/test_op.cpython-311.pyc b/edc-web/app/routes/__pycache__/test_op.cpython-311.pyc index 9d28dbe..2e8c208 100644 Binary files a/edc-web/app/routes/__pycache__/test_op.cpython-311.pyc and b/edc-web/app/routes/__pycache__/test_op.cpython-311.pyc differ diff --git a/edc-web/app/routes/test_op.py b/edc-web/app/routes/test_op.py index 9414821..09ebe68 100644 --- a/edc-web/app/routes/test_op.py +++ b/edc-web/app/routes/test_op.py @@ -112,9 +112,10 @@ def api_automation_start(): @login_required def api_automation_progress(dnt_id): """获取自动化进度""" + since = request.args.get("since", "", type=str) stats = get_serialnet_stats(dnt_id) latest = get_latest_test_state(dnt_id) - averages = get_automation_averages(dnt_id) + averages = get_automation_averages(dnt_id, since if since else None) return jsonify({ "stats": stats, "latest": latest, diff --git a/edc-web/app/static/js/test_data.js b/edc-web/app/static/js/test_data.js index 54bea94..20519bd 100644 --- a/edc-web/app/static/js/test_data.js +++ b/edc-web/app/static/js/test_data.js @@ -1,5 +1,10 @@ // 测试信息页 +function toSpeed(v) { + if (v === null || v === undefined || v === '') return '-'; + return (parseFloat(v) / 10).toFixed(1); +} + let currentPage = 1; let totalPages = 1; @@ -47,8 +52,8 @@ function renderTable(records) { ${r.exit_freq || '-'} ${r.enter_dist || '-'} ${r.exit_dist || '-'} - ${r.enter_speed || '-'} - ${r.exit_speed || '-'} + ${toSpeed(r.enter_speed)} + ${toSpeed(r.exit_speed)} ${r.create_time || '-'} `).join(""); diff --git a/edc-web/app/static/js/test_op.js b/edc-web/app/static/js/test_op.js index 6590701..ed94000 100644 --- a/edc-web/app/static/js/test_op.js +++ b/edc-web/app/static/js/test_op.js @@ -5,6 +5,7 @@ let autoTotal = 0; let autoDone = 0; let autoFailed = 0; let autoRemaining = 0; +let autoStartTime = ""; let pollInterval = null; let timeoutTimers = {}; // record_id → timer const TIMEOUT_MS = 10000; @@ -47,6 +48,7 @@ async function startAuto() { autoDone = 0; autoFailed = 0; autoRemaining = count; + autoStartTime = new Date().toISOString(); // 记录开始时间 // 清空显示 resetAverages(); @@ -101,7 +103,7 @@ async function pollProgress() { if (!autoRunning) return; try { - const resp = await fetch(`/api/automation/${DNT_ID}/progress`); + const resp = await fetch(`/api/automation/${DNT_ID}/progress?since=${encodeURIComponent(autoStartTime)}`); const data = await resp.json(); const stats = data.stats; @@ -171,6 +173,11 @@ function updateUI() { `${autoDone}/${autoTotal} (${autoFailed} 失败)`; } +function toSpeed(v) { + if (v === null || v === undefined || v === '') return '-'; + return (parseFloat(v) / 10).toFixed(1); +} + // ─── 显示最新结果 ────────────────────────────── function renderLatest(data) { @@ -183,8 +190,8 @@ function renderLatest(data) {

离开工作频率:${data.exit_freq || '-'} Hz

进入距离:${data.enter_dist || '-'} mm

离开距离:${data.exit_dist || '-'} mm

-

进入速度:${data.enter_speed || '-'} dm/s

-

离开速度:${data.exit_speed || '-'} dm/s

+

进入速度:${toSpeed(data.enter_speed)} m/s

+

离开速度:${toSpeed(data.exit_speed)} m/s

是否完成:${data.iffinish === '1' ? '是' : '否'}

故障信息:${data.fault_info || '无'}

时间:${data.create_time || '-'}

diff --git a/edc-web/app/templates/test_data.html b/edc-web/app/templates/test_data.html index 9835174..f408745 100644 --- a/edc-web/app/templates/test_data.html +++ b/edc-web/app/templates/test_data.html @@ -36,8 +36,8 @@ 离开频率(Hz) 进入距离(mm) 离开距离(mm) - 进入速度(dm/s) - 离开速度(dm/s) + 进入速度(m/s) + 离开速度(m/s) 时间 diff --git a/edc-web/app/templates/test_op.html b/edc-web/app/templates/test_op.html index bf35d22..02c0db5 100644 --- a/edc-web/app/templates/test_op.html +++ b/edc-web/app/templates/test_op.html @@ -53,8 +53,8 @@ 平均进入工作频率-Hz 平均进入距离-mm 平均离开距离-mm - 平均进入速度-dm/s - 平均离开速度-dm/s + 平均进入速度-m/s + 平均离开速度-m/s