debug: expand text ETA parsing and show raw eta string

This commit is contained in:
2026-08-02 17:03:43 +08:00
parent 9f2dc5bb3d
commit 96222ebf06
+57 -16
View File
@@ -2170,7 +2170,13 @@ function Display.render()
if #etaLine > w then etaLine = etaLine:sub(1, w) end
mon.write(etaLine)
end
logsStartY = upcomingStartY + 4
if upcomingStartY + 4 <= h then
mon.setCursorPos(1, upcomingStartY + 4)
local rawLine = "ETASTR:" .. tostring(dbg.textEtaRaw or "-")
if #rawLine > w then rawLine = rawLine:sub(1, w) end
mon.write(rawLine)
end
logsStartY = upcomingStartY + 5
end
if hasUpcoming then
mon.setTextColor(COLORS.INFO)
@@ -2348,6 +2354,53 @@ local Main = {}
State.announcedApproaching = {}
State.pendingApproaching = {}
local function parseEtaText(etaStr)
etaStr = tostring(etaStr or "")
if etaStr == "" then return -1 end
if string.find(etaStr, "现在", 1, true)
or string.find(etaStr, "到达", 1, true)
or string.find(etaStr, "^0+$")
then
return 0
end
local mm, ss = string.match(etaStr, "(%d+)%s*:%s*(%d+)")
if mm and ss then
return tonumber(mm) * 60 + tonumber(ss)
end
local min, sec = string.match(etaStr, "(%d+)%s*分.-(%d+)%s*秒")
if min and sec then
return tonumber(min) * 60 + tonumber(sec)
end
local secOnly = string.match(etaStr, "(%d+)%s*秒")
if secOnly then
return tonumber(secOnly)
end
local minOnly = string.match(etaStr, "(%d+)%s*分")
if minOnly then
return tonumber(minOnly) * 60
end
local num, unit = string.match(etaStr, "(%d+)%s*(.*)")
if num then
num = tonumber(num)
unit = tostring(unit or ""):lower()
if unit == "" then
return num
end
if string.find(unit, "秒", 1, true) or string.find(unit, "s", 1, true) or string.find(unit, "sec", 1, true) or (unit == "??" and num > 10) then
return num
end
return num * 60
end
return -1
end
function Main.loop()
while true do
local now = os.epoch("utc")
@@ -2360,6 +2413,7 @@ function Main.loop()
trainStopsCount = 0,
tickRate = State.tickRate or 20,
textKey = nil,
textEtaRaw = nil,
nbtKey = nil,
textEta = nil,
nbtEta = nil,
@@ -2383,26 +2437,13 @@ function Main.loop()
platform, etaStr, tName, dest = string.match(cleanLine, "^([^%s]+)%s+(.-)%s+([^%s]+)%s+(.*)$")
end
if tName and etaStr then
local etaSeconds = -1
local isNow = string.find(etaStr, "现在") or string.find(etaStr, "0")
if isNow then
etaSeconds = 0
else
local num, unit = string.match(etaStr, "(%d+)%s*(.*)")
if num then
num = tonumber(num)
if string.find(unit, "秒") or string.find(unit, "s") or string.find(unit, "sec") or (unit == "??" and num > 10) then
etaSeconds = num
else
etaSeconds = num * 60
end
end
end
local etaSeconds = parseEtaText(etaStr)
if dest then
local textKey = tName .. "_" .. dest
etaByText[textKey] = etaSeconds
if not dbg.textKey then
dbg.textKey = textKey
dbg.textEtaRaw = etaStr
dbg.textEta = etaSeconds
end
end