From eb018dbae91dc6bac36272d636f1cee3f4baca6d Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Mon, 3 Aug 2026 11:14:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(client):=20=E4=BF=AE=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=90=8C=E5=90=8D=E5=90=8C=E7=9B=AE=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E7=9A=84=E5=88=97=E8=BD=A6=E4=BA=92=E7=9B=B8=E6=B8=85=E9=99=A4?= =?UTF-8?q?=20pending=20=E7=8A=B6=E6=80=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当存在多个列车(如无名列车 ??? 开往同一目的地)时: - 第二个 ETA 较远的列车会因为 `etaSeconds > 45` 走进 `else` 分支 - 原逻辑在 `else` 分支会直接清空该 key 的 pending 状态 - 导致排在前面的列车永远无法积累 5 秒的稳定期 修改: 1. 移除 `else` 分支,统一交由末尾的清理循环处理 2. 使用 `if not seenApproachKeys[announceKey]` 确保同一个 tick 只有 ETA 最近(排最前)的列车更新状态 --- station_broadcast.lua | 114 +++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index af9a283..eae687e 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.50" +local APP_VERSION_TEXT = "v1.0.51" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -2704,38 +2704,38 @@ function Main.loop() end if etaSeconds >= 0 and etaSeconds <= 45 then - seenApproachKeys[announceKey] = true - local pending = State.pendingApproaching[announceKey] - if not pending then - State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } - else - if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 15 then - pending.since = now + if not seenApproachKeys[announceKey] then + seenApproachKeys[announceKey] = true + local pending = State.pendingApproaching[announceKey] + if not pending then + State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } + else + if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 15 then + pending.since = now + end + pending.lastEta = etaSeconds end - pending.lastEta = etaSeconds - end - local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 - local currentPending = State.pendingApproaching[announceKey] - if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then - State.announcedApproaching[announceKey] = now - Utils.log("INFO", string.format("Train Approaching: %s (ETA: %.1fs, Delay: %dm)", trainName, etaSeconds, delayMinutes)) - Network.send({ - type = "train_approaching", - stationName = State.stationName, - stationCode = State.stationCode, - stationPlatform = platform, - trainId = trainName, - destination = destination, - eta = string.format("%.1fs", etaSeconds), - etaSeconds = etaSeconds, - delay = displayDelayMinutes, - cancelled = cancelled, - reason = reason - }) + local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 + local currentPending = State.pendingApproaching[announceKey] + if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then + State.announcedApproaching[announceKey] = now + Utils.log("INFO", string.format("Train Approaching: %s (ETA: %.1fs, Delay: %dm)", trainName, etaSeconds, delayMinutes)) + Network.send({ + type = "train_approaching", + stationName = State.stationName, + stationCode = State.stationCode, + stationPlatform = platform, + trainId = trainName, + destination = destination, + eta = string.format("%.1fs", etaSeconds), + etaSeconds = etaSeconds, + delay = displayDelayMinutes, + cancelled = cancelled, + reason = reason + }) + end end - else - State.pendingApproaching[announceKey] = nil end end end @@ -2838,36 +2838,36 @@ function Main.loop() end if etaSeconds >= 0 and etaSeconds <= 45 then - seenApproachKeys[announceKey] = true - local pending = State.pendingApproaching[announceKey] - if not pending then - State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } - else - if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 3 then - pending.since = now + if not seenApproachKeys[announceKey] then + seenApproachKeys[announceKey] = true + local pending = State.pendingApproaching[announceKey] + if not pending then + State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } + else + if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 15 then + pending.since = now + end + pending.lastEta = etaSeconds end - pending.lastEta = etaSeconds - end - local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 - local currentPending = State.pendingApproaching[announceKey] - if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then - State.announcedApproaching[announceKey] = now - Utils.log("INFO", string.format("Train Approaching: %s (ETA: %ds, Delay: %dm)", tName, etaSeconds, delay)) - Network.send({ - type = "train_approaching", - stationName = State.stationName, - stationCode = State.stationCode, - stationPlatform = platform or State.stationPlatform or "1", - trainId = tName, - destination = dest, - eta = etaStr, - etaSeconds = etaSeconds, - delay = delay - }) + local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 + local currentPending = State.pendingApproaching[announceKey] + if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then + State.announcedApproaching[announceKey] = now + Utils.log("INFO", string.format("Train Approaching: %s (ETA: %ds, Delay: %dm)", tName, etaSeconds, delay)) + Network.send({ + type = "train_approaching", + stationName = State.stationName, + stationCode = State.stationCode, + stationPlatform = platform or State.stationPlatform or "1", + trainId = tName, + destination = dest, + eta = etaStr, + etaSeconds = etaSeconds, + delay = delay + }) + end end - else - State.pendingApproaching[announceKey] = nil end end end