fix(client): 修复多个同名同目的地的列车互相清除 pending 状态的问题
当存在多个列车(如无名列车 ??? 开往同一目的地)时: - 第二个 ETA 较远的列车会因为 `etaSeconds > 45` 走进 `else` 分支 - 原逻辑在 `else` 分支会直接清空该 key 的 pending 状态 - 导致排在前面的列车永远无法积累 5 秒的稳定期 修改: 1. 移除 `else` 分支,统一交由末尾的清理循环处理 2. 使用 `if not seenApproachKeys[announceKey]` 确保同一个 tick 只有 ETA 最近(排最前)的列车更新状态
This commit is contained in:
+57
-57
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user