diff options
-rw-r--r-- | Crossroads/nodes/(1645,6,8179).lua | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Crossroads/nodes/(1645,6,8179).lua b/Crossroads/nodes/(1645,6,8179).lua new file mode 100644 index 0000000..33d3103 --- /dev/null +++ b/Crossroads/nodes/(1645,6,8179).lua @@ -0,0 +1,86 @@ +local head = { "V TRAIN LINE TIME", "ST TRK STATION ", " " } +local length = 18 +local height = 4 +local sformat = string.format + +if event.type=="digiline" or event.type=="punch" then + if event.channel=="upd_main" or event.type=="punch" then + local ts = os.time() + local table = table + local start_t = os.clock() + if not S.lagrec then S.lagrec = {} end + local ids = {} + for i in pairs(S.trains) do ids[#ids+1] = i end + table.sort(ids, function(a, b) + local ta, tb = S.trains[a], S.trains[b] + if ta.l == tb.l then + return a < b + else + return ta.l < tb.l + end + end) + --do return end + local disp = {{}, {}, {}} + local percol = height*4-1 + for id = 1, #ids, 1 do + local st = (S.trains[ids[id] or 0] or {}) + local i = math.floor((id-1)/percol) + local j = math.floor(((id-1)%percol+1)/4)+1 + local stn = sformat("%-3s %-3s %s", st.mode or "", st.t or "N/A", F.stnlist[st.s] or st.s) + stn = stn:gsub("ä","ae"):gsub("ö","oe"):gsub("ü","ue"):gsub("ß","ss") + local dt = ts - (st.ts or -1) + local td = "" + if dt < 3600 then + td = sformat("%02dm%02ds", math.floor(dt/60), dt%60) + elseif dt < 86400 then + td = sformat("%02dh%02dm", math.floor(dt/3600), math.floor(dt/60)%60) + elseif dt < 8640000 then + td = sformat("%02dd%02dh", math.floor(dt/86400), math.floor(dt/3600)%24) + elseif st.ts then + td = "LONG" + end + local line = { + sformat("%02d %06d %-7s %s", st.v, ids[id], st.l, td), + stn, + stn:len() > 27 and stn:sub(28) or " ", + } + for df, fstr in pairs(line) do + local ft = disp[df] + local ct = ft[i] + if not ct then + ct = {{head[df]}} + ft[i] = ct + end + local rt = ct[j] + if not rt then + rt = {} + ct[j] = rt + end + table.insert(rt, fstr) + end + end + for fi, ft in pairs(disp) do + for fc, ct in pairs(ft) do + for fr, rt in pairs(ct) do + digiline_send(tostring((fi+fc*3)*10+fr), table.concat(rt or {}, "\n")) + end + end + end + local end_t = os.clock() + local t = end_t - start_t + local lagrec = S.lagrec + if t > (lagrec.max or 0) then + lagrec.max = t + end + if t < (lagrec.min or math.huge) then + lagrec.min = t + end + avg = t + if lagrec.avg then + avg = (lagrec.avg+t)/2 + end + lagrec.avg = avg + digiline_send("lag1", sformat("DEBUG\nTRAINS: %d\nTS: %d", #ids, ts)) + digiline_send("lag2", sformat("CUR %f\nMIN %f\nMAX %f\nAVG %f", t, lagrec.min, lagrec.max, avg)) + end +end
\ No newline at end of file |