Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local charts = require("charts") --Using the Charts Library (https://oc.cil.li/topic/1359-charts-library/)
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local text = require("text")
- term.clear()
- local gpu = term.gpu()
- gpu.setResolution(96, 30) --to make the text bigger, using a 3x2 monitor
- local matrix = component.list("induction_matrix")
- for a, _ in pairs(matrix) do matrix = component.proxy(a) end
- local maxEnergy = math.floor(matrix.getMaxEnergy() / 2.5) --values are 2.5x higher than listed in the matrix gui for some reason, this fixes it
- --local transferCap = matrix.getTransferCap() --saving in case I need the value in the future
- local powerBar = charts.Container{
- x = 1,
- y = 1,
- width = 96,
- height = 5,
- payload = charts.ProgressBar {
- direction = charts.sides.RIGHT,
- value = 0,
- min = 0,
- max = maxEnergy,
- colorFunc = function(_, perc )
- if perc >= .9 then
- return 0x00db00
- end
- if perc >= .75 then
- return 0x99db00
- end
- if perc >= .5 then
- return 0xffdb00
- end
- if perc >= .25 then
- return 0xff4900
- end
- if perc >= .1 then
- return 0xff0000
- end
- end
- }
- }
- local inputHist = charts.Container {
- x = 1,
- y = 6,
- width = 96,
- height = 12,
- payload = charts.Histogram {
- max = 1,
- colorFunc = function(index, norm, value, self, container)
- return 0x0049ff
- end
- }
- }
- local outputHist = charts.Container {
- x = 1,
- y = 18,
- width = 96,
- height = 12,
- payload = charts.Histogram {
- max = 1,
- min = -1,
- level = { value = 0 , y = 12},
- colorFunc = function(index, norm, value, self, container)
- return 0xff6d40
- end
- }
- }
- function centerText(_str, y, x1, x2) --function to write text centered between two X values
- local x1 = x1 or 1 --if no values for x are given, assume full screen.
- local x2 = x2 or 96
- local start = math.floor(((x2 - x1) - #_str)/2) + x1
- gpu.set(start, y, _str)
- end
- function comma_value(amount) --format big numbers with commas.
- local formatted = tostring(amount)
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then
- break
- end
- end
- return formatted
- end
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- num = math.floor(num * mult + 0.5) / mult
- if num ~= 100 then
- return string.format("%."..numDecimalPlaces.."f", num)
- end
- return "100"
- end
- function sum(table)
- local sum = 0
- for k,v in pairs(table) do
- sum = sum + v
- end
- return sum
- end
- function getMaxValue(table) --find the maximum value in a table
- local highest = 1
- for _,v in pairs(table) do
- if math.abs(v) > highest then highest = math.abs(v) end
- end
- return highest
- end
- function setMaxValue() --Makes sure the Histograms are using the same scale
- local highest = 1
- local inMax = getMaxValue(inputHist.payload.values)
- local outMax = getMaxValue(outputHist.payload.values)
- if inMax > highest then highest = inMax end
- if outMax > highest then highest = outMax end
- inputHist.payload.max = highest
- outputHist.payload.min = -highest
- end
- local average = "Average I/O Rate: 0 RF/t"
- local draws = 0
- while true do
- --local startTime = computer.uptime()
- local energy = math.floor(matrix.getEnergy() / 2.5) --values are 2.5x higher than listed in the matrix gui for some reason, this fixes it
- local input = math.floor(matrix.getInput() / 2.5)
- local output = math.floor(matrix.getOutput() / 2.5)
- table.insert(inputHist.payload.values, input)
- table.insert(outputHist.payload.values, -output)
- powerBar.payload.value = energy
- if #inputHist.payload.values > 96 then --don't let the Histograms overflow their area and stop displaying data
- table.remove(inputHist.payload.values, 1)
- table.remove(outputHist.payload.values, 1)
- end
- setMaxValue()
- if draws % 10 == 0 then
- average = (sum(inputHist.payload.values) + sum(outputHist.payload.values))/96
- average = round(average, 0)
- average = comma_value(average)
- average = "Average I/O Rate: " .. average .. " RF/t"
- end
- if draws % 3 == 0 then
- powerBar:draw()
- centerText("Induction Matrix", 1)
- local tmp = comma_value(energy).." RF"
- centerText(tmp, 2)
- tmp = round(((energy/maxEnergy) * 100), 2) .. "%"
- centerText(tmp, 3)
- centerText(average, 4)
- elseif draws % 3 == 1 then
- inputHist:draw()
- gpu.set(1, 15, "Input Rate")
- local tmp = comma_value(input).." RF"
- gpu.set(2, 16, tmp)
- else
- outputHist:draw()
- gpu.set(1, 19, "Output Rate")
- local tmp = comma_value(output).." RF"
- gpu.set(2, 20, tmp)
- end
- draws = draws + 1
- --term.setCursor(1, 15)
- --centerText(tostring(computer.uptime()-startTime))
- local _, _, x, y = event.pull( .04, "touch")
- if x and y then goto quit end
- end
- ::quit::
Advertisement
Add Comment
Please, Sign In to add comment