Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chest = peripheral.find("chest")
- me = peripheral.find("aemultipart")
- mon = peripheral.find("monitor")
- dataMax = 300
- readsPerSecond = 2
- items = {}
- function linReg(data)
- if #data == 0 then return 0,0 end
- local i
- local x,y,x2,y2,xy = 0,0,0,0,0
- for i=1,#data do
- x = x + i
- y = y + data[i]
- x2 = x2 + i*i
- y2 = y2 + data[i]*data[i]
- xy = xy + i*data[i]
- end
- local a,b = (x*x2-x*xy)/(#data*x2-x*x),(#data*xy-x*y)/(#data*x2-x*x)
- if a ~= a then a = 0 end
- if b ~= b then b = 0 end
- return a,b
- end
- function buildItemList()
- chest = peripheral.find("chest")
- me = peripheral.find("aemultipart")
- if not chest or not me then
- return
- end
- local list = {}
- local stacks = chest.getAllStacks()
- for k,v in pairs(stacks) do
- local a = v.all()
- local data = {
- current = -1,
- slope = 0,
- name = a.display_name,
- id = a.id,
- dmg = a.dmg,
- count = {}
- }
- if items and items[a.dmg.."~"..a.id] then
- data.count = items[a.dmg.."~"..a.id].count
- end
- if #data.count >= dataMax then table.remove(data.count,1) end
- local value = nil
- local ok = pcall(function() value = me.getItemDetail(a) end)
- if ok then
- data.current = value.basic().qty
- end
- table.insert(data.count,data.current)
- local b,m = linReg(data.count)
- data.slope = m
- list[a.dmg.."~"..a.id] = data
- end
- items = list
- end
- function round(x)
- if x%2 ~= 0.5 then
- return math.floor(x+0.5)
- end
- return x-0.5
- end
- function getScaledSlope(slope)
- return round(slope*readsPerSecond*getScale()*100)/100
- end
- function getScale()
- return 60
- end
- function getScaledUnits()
- return "min"
- end
- function showStats()
- term.redirect(mon)
- local r=1
- local w,h = term.getSize()
- for k,v in pairs(items) do
- term.setCursorPos(1,r)
- if #v.count < dataMax/3 then
- term.setTextColor(colors.gray)
- elseif #v.count < dataMax*2/3 then
- term.setTextColor(colors.lightGray)
- else
- term.setTextColor(colors.white)
- end
- term.clearLine()
- term.write(#v.count.." ")
- term.setCursorPos(5,r)
- term.setTextColor(colors.white)
- term.write(v.name..": ")
- term.write(v.current.." ")
- term.write("("..getScaledSlope(v.slope).." / "..getScaledUnits()..")")
- r = r + 1
- end
- while r <= h do
- term.setCursorPos(1,r)
- term.clearLine()
- r = r + 1
- end
- end
- while true do
- buildItemList()
- showStats()
- sleep(1/readsPerSecond)
- end
Add Comment
Please, Sign In to add comment