summaryrefslogtreecommitdiff
path: root/Crossroads/nodes/(1755,27,943).lua
diff options
context:
space:
mode:
authorautocommitter <autocommitter@linux-forks.de>2024-04-22 14:52:07 +0200
committerautocommitter <autocommitter@linux-forks.de>2024-04-22 14:52:07 +0200
commitc21692e0a830e434675014dd7b54736d180ce71d (patch)
treee928ac06b872bb5fa7697736f8cb78873e1424d2 /Crossroads/nodes/(1755,27,943).lua
parentc6612d4e4b59a03d097a494eee4c714f8b88f123 (diff)
downloadluaatc_envs-c21692e0a830e434675014dd7b54736d180ce71d.tar.gz
luaatc_envs-c21692e0a830e434675014dd7b54736d180ce71d.tar.bz2
luaatc_envs-c21692e0a830e434675014dd7b54736d180ce71d.zip
State at 2020-06-24
Diffstat (limited to 'Crossroads/nodes/(1755,27,943).lua')
-rw-r--r--Crossroads/nodes/(1755,27,943).lua64
1 files changed, 22 insertions, 42 deletions
diff --git a/Crossroads/nodes/(1755,27,943).lua b/Crossroads/nodes/(1755,27,943).lua
index eeaa266..d09f055 100644
--- a/Crossroads/nodes/(1755,27,943).lua
+++ b/Crossroads/nodes/(1755,27,943).lua
@@ -1,57 +1,37 @@
-local head="TRAIN STATUS"
-local function trainpairs(t, f)
- local a = {}
- for n in pairs(t) do table.insert(a, n) end
- table.sort(a, f)
- local i = 0
- local iter = function ()
- i = i + 1
- if a[i] == nil then return nil
- else return a[i], t[a[i]]
- end
- end
- return iter
-end
+local head = { "V TRAIN LINE STATION", " " }
local length = 18
-if event.type=="digiline" then
- if event.channel=="upd_main" then
+if event.type=="digiline" or event.type=="punch" then
+ if event.channel=="upd_main" or event.type=="punch" then
local start_t = os.clock()
if not S.lagrec then S.lagrec = {} end
- local l = {}
+ local la = {}
+ local lb = {}
local i
- for i=1,length,1 do
- if i%2 == 0 then
- l[i]=""
- else
- l[i]=head
- end
- end
local counter=0
- for id,st in trainpairs(S.trains) do
- if (counter) % 7 < 3 then
- i = (counter - counter % 7) / 7 * 2 + 1
- else
- i = (counter - counter % 7) / 7 * 2 + 2
- end
- l[i] = l[i] .. "\n" .. id .. " " .. st
+ local ids = {}
+ for i in pairs(S.trains) do ids[#ids+1] = i end
+ table.sort(ids)
+ for id = 1, #ids, 1 do
+ local st = (S.trains[ids[id] or 0] or "")
+ i = (counter-counter%7)/7*2+((counter%7<3) and 1 or 2)
+ if not la[i] then la[i] = (i%2==0) and "" or head[1] end
+ if not lb[i] then lb[i] = (i%2==0) and "" or head[2] end
+ local n = "[" .. (st.t or "N/A") .. "] " .. (F.stnlist[st.s] or st.s)
+ la[i] = string.format ("%s\n%02d %06d %-7s %s", la[i], st.v, ids[id], st.l, n)
+ lb[i] = lb[i] .. "\n" .. (n:len() < 10 and " " or n:sub(10))
counter = counter + 1
end
- for i=1,length,1 do
- if l[i]=="" then
- digiline_send("d"..tostring(i),"...")
- else
- digiline_send("d"..tostring(i),l[i])
- end
+ for i=1,#la,1 do
+ digiline_send("d"..tostring(i).."a", la[i] or "")
+ digiline_send("d"..tostring(i).."b", lb[i] or "")
end
local end_t = os.clock()
- table.insert(S.lagrec,end_t - start_t)
+ S.lagrec[#S.lagrec+1] = end_t - start_t
table.sort(S.lagrec)
local lagavg = 0
- for _,v in pairs(S.lagrec) do
- lagavg = lagavg + v
- end
+ for i = 1, #S.lagrec, 1 do lagavg = lagavg + S.lagrec[i] end
lagavg = lagavg / #S.lagrec
- digiline_send("lag1", "DEBUG\nTRAINS: " .. counter .. "\nDISPS: " .. length .. "\nTS: " .. os.time())
+ digiline_send("lag1", "DEBUG\nTRAINS: " .. counter .. "\nTS: " .. os.time())
digiline_send("lag2", "CUR " .. (end_t - start_t) .. "\nMIN " .. S.lagrec[1] .. "\nMAX " .. S.lagrec[#S.lagrec] .. "\nAVG " .. lagavg)
end
end \ No newline at end of file