From dee27eb3be0b324c7f5dd99c21164c04a2961f79 Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 28 May 2026 14:54:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B9=B3=E5=9D=87=E5=80=BC=E5=8F=AA?= =?UTF-8?q?=E7=AE=97=E6=9C=AC=E6=AC=A1=E5=90=AF=E5=8A=A8=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=20+=20=E9=80=9F=E5=BA=A6=20dm/s=E2=86=92m/s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 平均值按 automation 开始时间过滤,不再包含历史数据 - 速度单位从 dm/s 转为 m/s(÷10),前端/后端同步转换 --- .../app/__pycache__/models.cpython-311.pyc | Bin 19843 -> 20566 bytes edc-web/app/models.py | 29 +++++++++++++----- .../__pycache__/test_op.cpython-311.pyc | Bin 5208 -> 5383 bytes edc-web/app/routes/test_op.py | 3 +- edc-web/app/static/js/test_data.js | 9 ++++-- edc-web/app/static/js/test_op.js | 13 ++++++-- edc-web/app/templates/test_data.html | 4 +-- edc-web/app/templates/test_op.html | 4 +-- 8 files changed, 44 insertions(+), 18 deletions(-) diff --git a/edc-web/app/__pycache__/models.cpython-311.pyc b/edc-web/app/__pycache__/models.cpython-311.pyc index 0a263209fc47c5da226da118e2d868cebe57c93e..6346ae4824eb2db5505ed6976718d151ae9d8188 100644 GIT binary patch delta 2201 zcma)-e{5679l-CN{rn@26Pq}8LV!Fc4vryCVp3Z02-J+EO39os+6^^h#^gOBSLBDz zW^FBJ32WAcpK-Xdpt1^>Di&>&vb}B4lxm~XB&unWEk&JWsahu`AxP73ry`+lf9(5x zZlJ4>wzKc^zW4og=ezGazj~g2bdi?*%xWzm(6%nQUi^oDx~z&iroFGxw&|-~^oi*Q zA-b6dX@mDk*`k=_b&6RQ6~iHeTstAY;E<)_SQe5-LJsL=Hy@|2vAPNU3r_hd&FTS< z2E_~!>mkA=Z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>Hn 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 9d28dbe67a7b5ebb9188c755c3fc054c4ee08f88..2e8c2080881a5681f3ad2e20f54ed7299583baa4 100644 GIT binary patch delta 432 zcmcbi(XPe2oR^o20SMfliD&KK$ZIdaaSOI%av7VLN(y5NQwbYL5d^GZ zUdGJ8uo{RVpq8*Va#JpVOhom)CI&)T`VR1 zFg8#fQw?(sOA6~8=4FgPRX_{@!3>&grJ_Lgi@xno`=`BVU-h(W#nYZ?FZR!Vx@*}j z*5b^(`K~FuBO@afRPw@?^mijQ*2j sgrpcFHkS)+W7OtiWdFbbBt9}TFbTBCfhglEj7A?=U=m>2A_btW0KB+lz5oCK delta 286 zcmZqIx}m|loR^o20SE+cif0vW$5a0W$JIA^||6f#E9$1FymYwu?OKS9sJLT<`KKEik*tt96A} ztHJFqzuJPbi~M?5`1Kk*?s5y=5EQ#1BymGTX7WdVxygA#a~ORla|=r`hHh39-o~iS h$;keJ0Z4pgW?&L%kpof2R~U^xu)rk1vPB9&djV3xJ>dWV 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