debug: expand text ETA parsing and show raw eta string
This commit is contained in:
+57
-16
@@ -2170,7 +2170,13 @@ function Display.render()
|
|||||||
if #etaLine > w then etaLine = etaLine:sub(1, w) end
|
if #etaLine > w then etaLine = etaLine:sub(1, w) end
|
||||||
mon.write(etaLine)
|
mon.write(etaLine)
|
||||||
end
|
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
|
end
|
||||||
if hasUpcoming then
|
if hasUpcoming then
|
||||||
mon.setTextColor(COLORS.INFO)
|
mon.setTextColor(COLORS.INFO)
|
||||||
@@ -2348,6 +2354,53 @@ local Main = {}
|
|||||||
State.announcedApproaching = {}
|
State.announcedApproaching = {}
|
||||||
State.pendingApproaching = {}
|
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()
|
function Main.loop()
|
||||||
while true do
|
while true do
|
||||||
local now = os.epoch("utc")
|
local now = os.epoch("utc")
|
||||||
@@ -2360,6 +2413,7 @@ function Main.loop()
|
|||||||
trainStopsCount = 0,
|
trainStopsCount = 0,
|
||||||
tickRate = State.tickRate or 20,
|
tickRate = State.tickRate or 20,
|
||||||
textKey = nil,
|
textKey = nil,
|
||||||
|
textEtaRaw = nil,
|
||||||
nbtKey = nil,
|
nbtKey = nil,
|
||||||
textEta = nil,
|
textEta = nil,
|
||||||
nbtEta = nil,
|
nbtEta = nil,
|
||||||
@@ -2383,26 +2437,13 @@ function Main.loop()
|
|||||||
platform, etaStr, tName, dest = string.match(cleanLine, "^([^%s]+)%s+(.-)%s+([^%s]+)%s+(.*)$")
|
platform, etaStr, tName, dest = string.match(cleanLine, "^([^%s]+)%s+(.-)%s+([^%s]+)%s+(.*)$")
|
||||||
end
|
end
|
||||||
if tName and etaStr then
|
if tName and etaStr then
|
||||||
local etaSeconds = -1
|
local etaSeconds = parseEtaText(etaStr)
|
||||||
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
|
|
||||||
if dest then
|
if dest then
|
||||||
local textKey = tName .. "_" .. dest
|
local textKey = tName .. "_" .. dest
|
||||||
etaByText[textKey] = etaSeconds
|
etaByText[textKey] = etaSeconds
|
||||||
if not dbg.textKey then
|
if not dbg.textKey then
|
||||||
dbg.textKey = textKey
|
dbg.textKey = textKey
|
||||||
|
dbg.textEtaRaw = etaStr
|
||||||
dbg.textEta = etaSeconds
|
dbg.textEta = etaSeconds
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user