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 length = 18 if event.type=="digiline" then if event.channel=="upd_main" then local start_t = os.clock() if not S.lagrec then S.lagrec = {} end local l = {} 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 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 end local end_t = os.clock() table.insert(S.lagrec,end_t - start_t) table.sort(S.lagrec) local lagavg = 0 for _,v in pairs(S.lagrec) do lagavg = lagavg + v end lagavg = lagavg / #S.lagrec digiline_send("lag1", "DEBUG\nTRAINS: " .. counter .. "\nDISPS: " .. length .. "\nTIME: " .. os.date("%d %b %Y %X")) digiline_send("lag2", "CUR " .. (end_t - start_t) .. "\nMIN " .. S.lagrec[1] .. "\nMAX " .. S.lagrec[#S.lagrec] .. "\nAVG " .. lagavg) end end