Advertisement
TrueVirusTV

induction-matrix_monitoring_OLD

Oct 11th, 2022 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.06 KB | Gaming | 0 0
  1. -- PERIPHERIE LOKALISIEREN --
  2.  
  3. local matrix = peripheral.find("inductionPort")
  4. local mon = peripheral.find("monitor")
  5.  
  6. local avgAr = {}
  7.  
  8. --DEBUG--
  9. --[[if matrix==nil then
  10.     print("Matrix is nil")
  11.     else
  12.     print("Matrix found")
  13. end
  14. ]]--
  15.  
  16. -- ALLE WICHTIGEN DATEN AUS DER MATRIX ZIEHEN (LOOP) --
  17.  
  18. while true do
  19.    
  20.     local monX, monY = mon.getSize()
  21.    
  22.     local rawEnergy = matrix.getEnergy() or error("No Matrix found")                            -- INT
  23.     local rawEnergyMax = matrix.getMaxEnergy() or error("No Matrix found")                      -- INT
  24.     local rawEnergyPercentage = matrix.getEnergyFilledPercentage() or error("No Matrix found")  -- INT
  25.     local rawFormed = matrix.isFormed()                                                         -- BOOLEAN
  26.     if rawFormed==true then
  27.         --print("formed is true") --DEBUG
  28.         rawHeight = matrix.getHeight() or error("No Matrix found")                          -- INT
  29.         rawLength = matrix.getLength() or error("No Matrix found")                          -- INT
  30.         rawWidth = matrix.getWidth() or error("No Matrix found")                                -- INT
  31.         rawCells = matrix.getInstalledCells()   or error("No Matrix found")                 -- INT
  32.         rawProviders = matrix.getInstalledProviders()   or error("No Matrix found")         -- INT
  33.         rawInput = matrix.getLastInput()    or error("No Matrix found")                     -- INT
  34.         rawOutput = matrix.getLastOutput() or error("No Matrix found")                      -- INT
  35.         else
  36.         --print("formed is false") --DEBUG
  37.         rawHeight = 0 -- INT
  38.         rawLength =0 -- INT
  39.         rawWidth = 0 -- INT
  40.         rawCells = 0 -- INT
  41.         rawProviders = 0 -- INT
  42.         rawInput = 0 -- INT
  43.         rawOutput = 0 -- INT
  44.         end
  45.  
  46. --DEBUG--
  47. --[[print(rawEnergy)
  48. print(rawEnergyMax)
  49. print(rawEnergyPercentage)
  50. print(rawFormed)
  51. print(rawHeight)
  52. print(rawLength)
  53. print(rawWidth)
  54. print(rawCells)
  55. print(rawProviders)
  56. print(rawInput)
  57. print(rawOutput)]]--
  58.  
  59. -- ENERGYWERTE UMRECHNEN --
  60.    
  61.     local energyFE = (rawEnergy / 10)*4
  62.     local energyMaxFE = (rawEnergyMax / 10)*4
  63.     local energyPercentage = rawEnergyPercentage*100
  64.     local inputFE = (rawInput / 10)*4
  65.     local outputFE = (rawOutput / 10)*4
  66.    
  67.     if table.getn(avgAr) >= 20 then
  68.     table.remove(avgAr,1)
  69.     table.insert(avgAr,outputFE)
  70.         else
  71.         table.insert(avgAr,outputFE)
  72.         end
  73.    
  74.     local avg = 0
  75.     --DEBUG--
  76.     --print("Avg=0: "..avg)
  77.     for i=1,#avgAr do
  78.         avg = avg + avgAr[i]
  79.         end
  80.     --DEBUG--
  81.     --print("Avg Neu: "..avg)
  82.    
  83.     --DEBUG--
  84.     --[[
  85.     print("Aktuelle Anzahl Werte in Array: "..table.getn(avg))
  86.     ]]--
  87.    
  88.     local secs = energyFE / ((avg*20)/20)
  89.     --DEBUG--
  90.     --print("Secs: "..secs)
  91.  
  92.     function calc(param)
  93.             if param<1000 then
  94.                 param = math.floor(param)
  95.                 result = tostring(param.." FE")
  96.                 return result
  97.                 elseif param<1000000 then
  98.                     param = param/1000
  99.                     local X = math.pow(10, 2)
  100.                     param = math.floor(param * X) / X
  101.                     result = string.format("%0.2f kFE",param)
  102.                     return result
  103.                     elseif param<1000000000 then
  104.                         param = param/1000000
  105.                         local X = math.pow(10, 2)
  106.                         param = math.floor(param * X) / X
  107.                         result = string.format("%0.2f MFE",param)
  108.                         return result
  109.                         elseif param<1000000000000 then
  110.                             param = param/1000000000
  111.                             local X = math.pow(10, 2)
  112.                             param = math.floor(param * X) / X
  113.                             result = string.format("%0.2f GFE",param)
  114.                             return result
  115.                             elseif param<1000000000000000 then
  116.                                 param = param/1000000000000
  117.                                 local X = math.pow(10, 2)
  118.                                 param = math.floor(param * X) / X
  119.                                 result = string.format("%0.2f TFE",param)
  120.                                 return result
  121.                 end
  122.             end
  123.    
  124.     function timeleft(secs)
  125.        
  126.           secs = math.floor(secs)
  127.  
  128.           -- Days
  129.           local weeks = math.floor(secs / 604800)
  130.           secs = secs - (604800 * weeks)
  131.  
  132.           -- Days
  133.           local days = math.floor(secs / 86400)
  134.           secs = secs - (86400 * days)
  135.  
  136.           -- Hours
  137.           local hours = math.floor(secs / 3600)
  138.           secs = secs - (3600 * hours)
  139.  
  140.           -- Minutes
  141.           local mins = math.floor(secs / 60)
  142.           secs = secs - (60 * mins)
  143.        
  144.           -- If we have more than 72h worth of storage, switch to week, day, hour format
  145.           if weeks > 0 then
  146.             return string.format('%dwk %dd %dh', weeks, days, hours)
  147.           elseif days >= 3 then
  148.             return string.format('%dd %dh', days, hours)
  149.           end
  150.  
  151.           -- Formatting to have trailing zeros on H:MM:SS
  152.           return string.format('%d:%02d:%02d', hours, mins, secs)
  153.        
  154.         end
  155.        
  156.    
  157. -- SCREEN INITIALISIEREN --
  158.  
  159.     mon.setBackgroundColor(colors.black)
  160.     mon.clear()
  161.     mon.setCursorPos(1,1)
  162.     mon.setTextScale(1)
  163.     mon.setBackgroundColor(colors.blue)
  164.     for i = 1,monX do
  165.         mon.write(" ")
  166.     end
  167.    
  168.     mon.setCursorPos(1,2)
  169.     mon.write(" ")
  170.     mon.setBackgroundColor(colors.black)
  171.     local title = "Induction Matrix"
  172.     local len = string.len(title)
  173.     mon.setCursorPos((monX - len+1) / 2, 2)
  174.     mon.write(title)
  175.     mon.setCursorPos(monX, 2)
  176.     mon.setBackgroundColor(colors.blue)
  177.     mon.write(" ")
  178.    
  179.     mon.setCursorPos(1,3)
  180.     for i = 1,monX do
  181.         mon.write(" ")
  182.     end
  183.  
  184.     mon.setCursorPos(1,4)
  185.     mon.write(" ")
  186.     mon.setBackgroundColor(colors.black)
  187.     mon.write("Online: ")
  188.     if rawFormed==true then
  189.         mon.setBackgroundColor(colors.lime)
  190.         mon.write(" ")
  191.         else
  192.         mon.setBackgroundColor(colors.red)
  193.         mon.write(" ")
  194.         end
  195.     mon.setCursorPos(monX, 4)
  196.     mon.setBackgroundColor(colors.blue)
  197.     mon.write(" ")
  198.    
  199.     mon.setCursorPos(1,5)
  200.     mon.write(" ")
  201.     mon.setBackgroundColor(colors.black)
  202.     mon.write("Cells: "..rawCells.." | Providers: "..rawProviders)
  203.     pertemp = string.format(" | %02.02f",energyPercentage)
  204.     mon.write(pertemp.." %")
  205.     mon.setCursorPos(monX, 5)
  206.     mon.setBackgroundColor(colors.blue)
  207.     mon.write(" ")
  208.  
  209.     mon.setCursorPos(1,6)
  210.     mon.setBackgroundColor(colors.blue)
  211.     for i = 1,monX do
  212.         mon.write(" ")
  213.     end
  214.    
  215.     mon.setCursorPos(1,7)
  216.     mon.write(" ")
  217.     mon.setBackgroundColor(colors.black)
  218.     mon.write("Current: "..calc(energyFE).." / "..calc(energyMaxFE))
  219.     mon.setBackgroundColor(colors.blue)
  220.     mon.setCursorPos(monX,7)
  221.     mon.write(" ")
  222.    
  223.    
  224.     mon.setCursorPos(1,8)
  225.     mon.write(" ")
  226.     mon.setBackgroundColor(colors.black)
  227.     mon.write("Input  : "..calc(inputFE).."/t")
  228.     mon.setBackgroundColor(colors.blue)
  229.     mon.setCursorPos(monX,8)
  230.     mon.write(" ")
  231.    
  232.     mon.setCursorPos(1,9)
  233.     mon.write(" ")
  234.     mon.setBackgroundColor(colors.black)
  235.     mon.write("Output : "..calc(outputFE).."/t")
  236.     mon.setBackgroundColor(colors.blue)
  237.     mon.setCursorPos(monX,9)
  238.     mon.write(" ")
  239.    
  240.    
  241.     mon.setCursorPos(1,10)
  242.     mon.write(" ")
  243.     mon.setBackgroundColor(colors.black)
  244.     --
  245.     mon.setCursorPos(monX, 10)
  246.     mon.setBackgroundColor(colors.blue)
  247.     mon.write(" ")
  248.    
  249.    
  250.     mon.setCursorPos(1,11)
  251.     mon.write(" ")
  252.     mon.setBackgroundColor(colors.black)
  253.     --TIME LEFT--
  254.     if inputFE >= outputFE then
  255.         mon.write("Time Left: Charging...")
  256.         elseif outputFE >= inputFE then
  257.             mon.write("Time Left: "..timeleft(secs))
  258.         else
  259.             mon.write("Idle...")
  260.         end
  261.    
  262.     mon.setCursorPos(monX, 11)
  263.     mon.setBackgroundColor(colors.blue)
  264.     mon.write(" ")
  265.    
  266.     --ABSCHLUSS--
  267.     mon.setCursorPos(1,monY)
  268.     mon.setBackgroundColor(colors.blue)
  269.     for i = 1,monX do
  270.         mon.write(" ")
  271.     end
  272.    
  273.     os.sleep(0.1)
  274. end
  275.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement