summaryrefslogtreecommitdiff
path: root/Crossroads/nodes/(1755,27,943).lua
blob: d09f055a67cebe6536e7805896e5dea2ecba0058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local head = { "V  TRAIN  LINE    STATION", " " }
local length = 18
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 la = {}
    local lb = {}
    local i
    local counter=0
    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,#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()
    S.lagrec[#S.lagrec+1] = end_t - start_t
    table.sort(S.lagrec)
    local lagavg = 0
    for i = 1, #S.lagrec, 1 do lagavg = lagavg + S.lagrec[i] end
    lagavg = lagavg / #S.lagrec
    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