fix: use earlier realtime tick for arrival ETA

This commit is contained in:
2026-08-02 17:14:51 +08:00
parent 426e55a7f0
commit 9060e79006
2 changed files with 15 additions and 3 deletions
+12 -3
View File
@@ -2,7 +2,7 @@
-- ============================================================================
-- 1. Configuration & Constants
-- ============================================================================
local APP_VERSION_TEXT = "v1.0.33"
local APP_VERSION_TEXT = "v1.0.34"
local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -2427,6 +2427,15 @@ local function normalizeUpcomingKey(trainName, destination)
return clean(trainName) .. "_" .. clean(destination)
end
local function pickEarlierTick(a, b)
local ta = tonumber(a)
local tb = tonumber(b)
if ta and tb then
return math.min(ta, tb)
end
return ta or tb or 0
end
function Main.loop()
while true do
local now = os.epoch("utc")
@@ -2560,8 +2569,8 @@ function Main.loop()
end
-- Calculate ETA in seconds using interpolated currentTick
local scheduledArrival = st.ScheduledArrival or 0
local realArrival = st.RealTimeArrival or 0
local scheduledArrival = pickEarlierTick(st.ScheduledArrival, st.ScheduledDeparture)
local realArrival = pickEarlierTick(st.RealTimeArrival, st.RealTimeDeparture)
local etaTicks = realArrival - currentTick
local etaSeconds = math.floor(etaTicks / (State.tickRate or 20))
if etaSeconds < 0 then etaSeconds = 0 end