mrWhiskasss

tps opencomputers checker

Oct 18th, 2021
660
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os = require("os")
  2. event = require("event")
  3. term = require("term")
  4. keyboard = require("keyboard")
  5. com = require("component")
  6. fs = require("filesystem")
  7.  
  8. w,h = com.gpu.getResolution()
  9.  
  10. prog = true
  11. clearMon = false
  12. crop = 0.4
  13. tSlot = 1
  14. timeConstant = 2
  15. TPS = {}
  16. avgTPS = 0
  17. joke = 0
  18. logTps = 1
  19. logRow = 1
  20. ww = w*crop
  21. hh = h*crop
  22.  
  23. com.gpu.setResolution(ww, hh)
  24.  
  25. for tSlot=1,10 do
  26.     TPS[tSlot]=0
  27. end;
  28.  
  29. function minusTime(tc)
  30.     if tc <= 1 then
  31.         return tc
  32.     else
  33.         return tc - 1
  34.     end;
  35. end;
  36.  
  37. function plusTime(tc)
  38.     if tc >= 20 then
  39.         return tc
  40.     else
  41.         return tc + 1
  42.     end;
  43. end;
  44.  
  45. btn = {
  46.     {
  47.         x = ww-2,
  48.         y = 1,
  49.         action = function()
  50.             event.ignore("touch", touch)
  51.             prog = false
  52.             clearMon = true
  53.         end;
  54.     },
  55.     {
  56.         x = 13,
  57.         y = 3,
  58.         action = function()
  59.             timeConstant = minusTime(timeConstant)
  60.         end;
  61.     },
  62.     {
  63.         x = 21,
  64.         y = 3,
  65.         action = function()
  66.             timeConstant = plusTime(timeConstant)
  67.         end;
  68.     }
  69. }
  70.  
  71. function touch(_,_, x, y)
  72.     for i = 1, #btn do
  73.         if x == btn[i].x and y == btn[i].y or x >= btn[i].x + 1 and x < btn[i].x + 3 and y == btn[i].y then
  74.             btn[i].action()
  75.             break
  76.         end;
  77.     end;
  78. end;
  79.  
  80. function twenty(flt)
  81.     if flt > 20 then
  82.         return 20
  83.     else
  84.         return flt
  85.     end;
  86. end;
  87.  
  88. function time()
  89.     local f = io.open("/tmp/timeFile","w")
  90.     f:write("test")
  91.     f:close()
  92.     return(fs.lastModified("/tmp/timeFile"))
  93. end;
  94.  
  95. while prog == true do
  96.  
  97.     realTimeOld = time()
  98.     os.sleep(timeConstant/10)
  99.     realTimeNew = time()
  100.    
  101.     realTimeDiff = realTimeNew-realTimeOld
  102.  
  103.     TPS[tSlot] = twenty(20000*(timeConstant/10)/realTimeDiff)
  104.     avgTPS = (TPS[1]+TPS[2]+TPS[3]+TPS[4]+TPS[5]+TPS[6]+TPS[7]+TPS[8]+TPS[9]+TPS[10])/10
  105.    
  106.     event.listen("touch", touch)
  107.    
  108.     com.gpu.setForeground(0x222222)
  109.     com.gpu.fill(1, 1, ww, hh-2, '█')
  110.    
  111.     com.gpu.setForeground(0x000080)
  112.     com.gpu.fill(1, 1, ww, 1, '█')
  113.    
  114.     term.setCursor(1,1)
  115.     com.gpu.setBackground(0x000080)
  116.     com.gpu.setForeground(0xFFFFFF)
  117.     print("roga122 tps checker")
  118.    
  119.     com.gpu.setForeground(0xff0000)
  120.     com.gpu.fill(ww-2, 1, 3, 1, '█')
  121.    
  122.     term.setCursor(ww-1,1)
  123.     com.gpu.setBackground(0xff0000)
  124.     com.gpu.setForeground(0xffffff)
  125.     print("X")
  126.    
  127.    
  128.     term.setCursor(1,3)
  129.     com.gpu.setForeground(0xffffff)
  130.     com.gpu.setBackground(0x222222)
  131.     print("Частота:", timeConstant/10)
  132.    
  133.     term.setCursor(1,4)
  134.     com.gpu.setForeground(0xffffff)
  135.     com.gpu.setBackground(0x222222)
  136.     print("TPS сейчас:", string.format("%.2f",TPS[tSlot]))
  137.    
  138.     term.setCursor(1,5)
  139.     com.gpu.setBackground(0x222222)
  140.     print("TPS средний:", string.format("%.2f",avgTPS))
  141.    
  142.     term.setCursor(1,7)
  143.     print("Плавность работы визуально:")
  144.    
  145.     term.setCursor(1,17)
  146.     print("История тпс:")
  147.    
  148.     com.gpu.setForeground(0xcccccc)
  149.     com.gpu.fill(13, 3, 3, 1, '█')
  150.    
  151.     com.gpu.setBackground(0xcccccc)
  152.     com.gpu.setForeground(0xffffff)
  153.     term.setCursor(14,3)
  154.     print("-")
  155.        
  156.     com.gpu.setForeground(0xcccccc)
  157.     com.gpu.fill(21, 3, 3, 1, '█')
  158.    
  159.     com.gpu.setBackground(0xcccccc)
  160.     com.gpu.setForeground(0xffffff)
  161.     term.setCursor(22,3)
  162.     print("+")
  163.    
  164.    
  165.     if joke < ww then
  166.         if (avgTPS > 18) then
  167.             com.gpu.setForeground(0x00FF00)
  168.         elseif (avgTPS < 18 and avgTPS > 13) then
  169.             com.gpu.setForeground(0xFFFF00)
  170.         elseif (avgTPS < 13 and avgTPS > 8) then
  171.             com.gpu.setForeground(0xFF9900)
  172.         else
  173.             com.gpu.setForeground(0xFF0000)
  174.         end;
  175.         com.gpu.fill(1, 9, joke, 7, '█')
  176.         joke = joke + 1
  177.     else
  178.         if (avgTPS > 18) then
  179.             com.gpu.setForeground(0x00FF00)
  180.         elseif (avgTPS < 18 and avgTPS > 13) then
  181.             com.gpu.setForeground(0xFFFF00)
  182.         elseif (avgTPS < 13 and avgTPS > 8) then
  183.             com.gpu.setForeground(0xFF9900)
  184.         else
  185.             com.gpu.setForeground(0xFF0000)
  186.         end;
  187.         com.gpu.fill(1, 9, ww, 7, '█')
  188.         joke = 0
  189.     end;
  190.    
  191.     if logTps < 11 then
  192.         term.setCursor(logRow+3, hh-1)
  193.         com.gpu.setForeground(0xffffff)
  194.         com.gpu.setBackground(0x222222)
  195.         print(string.format("%.1f",TPS[logTps]))
  196.        
  197.         term.setCursor(1, hh-2)
  198.         com.gpu.setForeground(0x222222)
  199.         com.gpu.fill(1, hh-2, ww, 1, '█')
  200.        
  201.         term.setCursor(logRow+2, hh-2)
  202.        
  203.         com.gpu.setForeground(0x000000)
  204.         if (TPS[tSlot] > 18) then
  205.             com.gpu.setBackground(0x00FF00)
  206.         elseif (TPS[tSlot] < 18 and TPS[tSlot] > 13) then
  207.             com.gpu.setBackground(0xFFFF00)
  208.         elseif (TPS[tSlot] < 13 and TPS[tSlot] > 8) then
  209.             com.gpu.setBackground(0xFF9900)
  210.         else
  211.             com.gpu.setBackground(0xFF0000)
  212.         end;
  213.         print("Сейчас")
  214.        
  215.         com.gpu.setForeground(0xffffff)
  216.         com.gpu.setBackground(0x222222)
  217.        
  218.         logTps = logTps + 1
  219.         logRow = logRow + 6
  220.     end;
  221.    
  222.     if logTps == 11 then
  223.         logTps = 1
  224.         logRow = 1
  225.     end;
  226.    
  227.     if tSlot == 10 then
  228.         tSlot = 0
  229.     end;
  230.    
  231.     tSlot = tSlot + 1
  232.  
  233.     if clearMon == true then
  234.         term.setCursor(1, 1)
  235.         term.clear()
  236.         com.gpu.setBackground(0x000000)
  237.         com.gpu.setForeground(0x000000)
  238.         com.gpu.setResolution(w, h)
  239.         com.gpu.fill(1, 1, w, h, '█')
  240.         com.gpu.setForeground(0xFFFFFF)
  241.         com.gpu.setBackground(0x000000)
  242.         print("Выход...")
  243.     end;
  244. end;
RAW Paste Data