Advertisement
sevn35

Power

May 20th, 2022 (edited)
714
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use = peripheral.wrap("energyDetector_2")
  2. create = peripheral.wrap("energyDetector_3")
  3. screen = peripheral.wrap("monitor_0")
  4. max = 6400
  5. log = {}
  6. avgLog = {}
  7.  
  8. function update()
  9.     num = 0
  10.     gen = create.getTransferRate()
  11.     spend = use.getTransferRate()
  12.     genperc = ((gen)) / (max) * 100
  13.     useperc = ((spend)) / (max) * 100
  14.  
  15.     screen.clear()
  16.     screen.setCursorPos(1,1)
  17.     screen.write("Max Power Generation: " ..(max).. " FE/t")
  18.     screen.setCursorPos(1,2)
  19.     screen.write("Current Power Generation: " .. (gen) .." FE/t")
  20.     screen.setCursorPos(1,3)
  21.     screen.write("Current Power Use: " .. (spend) .." FE/t")
  22.     screen.setCursorPos(68,2)
  23.     screen.write(math.floor((genperc)) .."%")
  24.     screen.setCursorPos(68,3)
  25.     screen.write(math.floor((useperc)) .."%")
  26.  
  27. --Adds a log. Maxes at an hour
  28.     table.insert(log,1, (spend) )
  29.     table.remove(log, 721)
  30.     for i=1,(#log) do                --Adds values of log
  31.         num = num + log[i]
  32.     end
  33.     avg = math.floor(num / #log)     --Adverages the log based on its current length
  34.     avgperc = ((avg)) / (max) * 100
  35.     screen.setCursorPos(1,4)
  36.     screen.write("Average Power Use: " ..(avg).. " FE/t")
  37.     screen.setCursorPos(68,4)
  38.     screen.write(math.floor((avgperc)) .."%")
  39. --  
  40.    
  41. --Graph based on hourly log
  42.     table.insert(avgLog,1, (avg) )
  43.     table.remove(avgLog, 72)
  44.     for a=1,(#avgLog) do
  45.         for b=1, 10 do
  46.             screen.setCursorPos(a,(20 - b))
  47.             if ((avgLog[a])/(max)) > (b/10) then
  48.                 if ((avgLog[a])/(max)) > 1 then
  49.                     screen.setTextColour(16384) --red
  50.                 elseif ((avgLog[a])/(max)) > 0.70 then
  51.                     screen.setTextColour(16) --yellow
  52.                 else
  53.                     screen.setTextColour(8192) --green
  54.                 end
  55.                 screen.write("X")
  56.             end
  57.             b = b + 1
  58.         end
  59.     end
  60.     screen.setTextColour(1) --white
  61. --
  62.    
  63.     sleep(5)
  64.     update()
  65. end
  66. --((avg)/(max)) < ((11-b)/10)
  67. update()
Advertisement
RAW Paste Data Copied
Advertisement