fix: trigger delay alerts from displayed CRN delay
This commit is contained in:
+14
-7
@@ -2,7 +2,7 @@
|
||||
-- ============================================================================
|
||||
-- 1. Configuration & Constants
|
||||
-- ============================================================================
|
||||
local APP_VERSION_TEXT = "v1.0.38"
|
||||
local APP_VERSION_TEXT = "v1.0.39"
|
||||
|
||||
local CONFIG = {
|
||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||
@@ -2415,6 +2415,7 @@ function Main.loop()
|
||||
local now = os.epoch("utc")
|
||||
local newUpcoming = {}
|
||||
local etaTextByKey = {}
|
||||
local delayTextByKey = {}
|
||||
|
||||
-- Read CRN text ETA only for display wording.
|
||||
-- Timing decisions and numeric ETA still come from NBT.
|
||||
@@ -2423,6 +2424,8 @@ function Main.loop()
|
||||
if okLines and type(lines) == "table" then
|
||||
for _, lineText in pairs(lines) do
|
||||
if lineText and lineText ~= "" and lineText:match("[%w%?%[]") then
|
||||
local delayMatch = string.match(lineText, "%+%s*(%d+)")
|
||||
local textDelay = tonumber(delayMatch) or 0
|
||||
local cleanLine = string.gsub(lineText, "%s*%(?%+%s*%d+.-%)?", "")
|
||||
local etaValue, etaUnit, tName, dest
|
||||
etaValue, etaUnit, tName, dest = string.match(cleanLine, "^(%S+)%s+(.-)%s+(%[.-%][^%s]*)%s+(.*)$")
|
||||
@@ -2437,6 +2440,9 @@ function Main.loop()
|
||||
unit = etaUnit,
|
||||
raw = tostring(etaValue or "") .. ((etaUnit and etaUnit ~= "") and (" " .. tostring(etaUnit)) or "")
|
||||
}
|
||||
if textDelay > 0 then
|
||||
delayTextByKey[textKey] = textDelay
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2518,6 +2524,7 @@ function Main.loop()
|
||||
local delayTicks = realArrival - scheduledArrival
|
||||
local delayMinutes = math.floor(delayTicks / ((State.tickRate or 20) * 60))
|
||||
if delayMinutes < 0 then delayMinutes = 0 end
|
||||
local displayDelayMinutes = math.max(delayMinutes, tonumber(delayTextByKey[announceKey]) or 0)
|
||||
|
||||
table.insert(newUpcoming, {
|
||||
trainName = trainName,
|
||||
@@ -2525,16 +2532,16 @@ function Main.loop()
|
||||
platform = platform,
|
||||
eta = etaSeconds,
|
||||
etaLabel = etaLabel,
|
||||
delay = delayMinutes,
|
||||
delay = displayDelayMinutes,
|
||||
cancelled = cancelled,
|
||||
reason = reason
|
||||
})
|
||||
|
||||
local alertKey = announceKey .. "::delay=" .. tostring(delayMinutes) .. "::reason=" .. tostring(reason or "") .. "::cancel=" .. tostring(cancelled)
|
||||
if cancelled or delayMinutes > 0 then
|
||||
local alertKey = announceKey .. "::delay=" .. tostring(displayDelayMinutes) .. "::reason=" .. tostring(reason or "") .. "::cancel=" .. tostring(cancelled)
|
||||
if cancelled or displayDelayMinutes > 0 then
|
||||
if not State.announcedAlerts[alertKey] then
|
||||
State.announcedAlerts[alertKey] = now
|
||||
Utils.log("INFO", string.format("Train Alert: %s (ETA: %ds, Delay: %dm, Cancelled: %s, Reason: %s)", trainName, etaSeconds, delayMinutes, tostring(cancelled), tostring(reason or "")))
|
||||
Utils.log("INFO", string.format("Train Alert: %s (ETA: %ds, Delay: %dm, Cancelled: %s, Reason: %s)", trainName, etaSeconds, displayDelayMinutes, tostring(cancelled), tostring(reason or "")))
|
||||
Network.send({
|
||||
type = "train_approaching",
|
||||
stationName = State.stationName,
|
||||
@@ -2544,7 +2551,7 @@ function Main.loop()
|
||||
destination = destination,
|
||||
eta = tostring(etaSeconds) .. "s",
|
||||
etaSeconds = etaSeconds,
|
||||
delay = delayMinutes,
|
||||
delay = displayDelayMinutes,
|
||||
cancelled = cancelled,
|
||||
reason = reason
|
||||
})
|
||||
@@ -2564,7 +2571,7 @@ function Main.loop()
|
||||
destination = destination,
|
||||
eta = tostring(etaSeconds) .. "s",
|
||||
etaSeconds = etaSeconds,
|
||||
delay = delayMinutes,
|
||||
delay = displayDelayMinutes,
|
||||
cancelled = cancelled,
|
||||
reason = reason
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user