fix: 平均值只算本次启动后的记录 + 速度 dm/s→m/s

- 平均值按 automation 开始时间过滤,不再包含历史数据
- 速度单位从 dm/s 转为 m/s(÷10),前端/后端同步转换
This commit is contained in:
wangfq
2026-05-28 14:54:21 +08:00
parent 322563dab0
commit dee27eb3be
8 changed files with 44 additions and 18 deletions

View File

@@ -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) {
<p>离开工作频率:${data.exit_freq || '-'} Hz</p>
<p>进入距离:${data.enter_dist || '-'} mm</p>
<p>离开距离:${data.exit_dist || '-'} mm</p>
<p>进入速度:${data.enter_speed || '-'} dm/s</p>
<p>离开速度:${data.exit_speed || '-'} dm/s</p>
<p>进入速度:${toSpeed(data.enter_speed)} m/s</p>
<p>离开速度:${toSpeed(data.exit_speed)} m/s</p>
<p>是否完成:${data.iffinish === '1' ? '是' : '否'}</p>
<p>故障信息:${data.fault_info || '无'}</p>
<p>时间:${data.create_time || '-'}</p>