Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rsSide = "top"
- local cellSide = "left"
- local maxPercent = 95
- local minPercent = 20
- local cell = peripheral.wrap(cellSide)
- if not cell then
- error("No energy cell or it's side is wrong!")
- end
- local max = cell.getRFCapacity()
- local shutoff = math.floor(max - (max * (100 - maxPercent) * 0.01))
- local startup = math.floor(max * minPercent * 0.01)
- print(shutoff, startup)
- local on = true
- local last = 0
- local time = 1
- local olds = {}
- local function createTimeString(dif, c)
- local tString = ""
- local t2 = ""
- local ts
- if dif > 0 then
- tString = tString .. "shutoff: "
- ts = math.abs(math.floor((shutoff - c) / dif * time))
- elseif dif < 0 then
- tString = tString .. "startup: "
- ts = math.abs(math.floor((c - startup) / math.abs(dif) * time))
- else
- tString = "Idle"
- end
- if dif ~= 0 then
- local tm = math.floor(ts / 60)
- ts = ts - (60 * tm)
- local th = math.floor(tm / 60)
- tm = tm - (60 * th)
- tString = tString .. tostring(th) .. "h, " .. tostring(tm) .. "m, " .. tostring(ts) .. "s"
- end
- return tString
- end
- local function addToOlds(n)
- if #olds > 8 then
- table.remove(olds, 1)
- end
- table.insert(olds, n)
- end
- local function average(inp)
- local ttl = 0
- local sz = #inp
- for i = 1, sz do
- ttl = ttl + inp[i]
- end
- ttl = ttl / sz
- return ttl
- end
- while true do
- local c = cell.getRFStored()
- local dif = c - last
- last = c
- addToOlds(dif)
- if c < startup then
- on = true
- elseif c > shutoff then
- on = false
- end
- term.clear()
- term.setCursorPos(1,1)
- print(tostring(c), "/", max)
- print(tostring(startup) .. " / " .. tostring(shutoff) .. " (startup/shutoff)")
- print(on and "Generators running" or "Generators offline")
- print()
- print(dif < 0 and tostring(math.abs(dif)) .. " v RF/s" or dif == 0
- and "0 - RF/s" or tostring(dif) .. " ^ RF/s")
- print()
- print(tostring(math.floor(dif / (time * 20))) .. " RF/t")
- print()
- print("Average: " .. tostring(math.floor(average(olds) / (time * 20)))
- .. " RF/t")
- print()
- print(createTimeString(average(olds), c))
- rs.setOutput(rsSide,on)
- os.sleep(time)
- end
Add Comment
Please, Sign In to add comment