Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local string = require("string")
- local term = require("term")
- local os = require("os")
- local gpu = component.gpu
- local interface = {}
- interface = component.proxy(component.me_interface.address)
- --Prints all keys in a table.
- function printTableKeys(table, prop)
- for k,v in pairs(table) do
- print("--->", k)
- end
- end
- --Combines two tables. Returns a new table with the contents of the originals
- function combineTables(tables)
- local out = {}
- for k,t in pairs(tables) do
- for j,item in pairs(t) do
- table.insert(out, item)
- end
- end
- return out
- end
- --Checks to see if item is a value in the table
- function isIn(table, item)
- for k,v in pairs(table) do
- if(v == item) then return true end
- end
- return false
- end
- function plotLine(x0, y0, x1, y1, color)
- if(math.abs(y1 - y0) < abs(x1 - x0)) then
- if x0 > x1 then
- plotLineLow(x1, y1, x0, y0, color)
- else
- plotLineLow(x0, y0, x1, y1, color)
- end
- else
- if y0 > y1 then
- plotLineHigh(x1, y1, x0, y0, color)
- else
- plotLineHigh(x0, y0, x1, y1, color)
- end
- end
- end
- function plotLineLow(x0, y0, x1, y1, color)
- local dx = x1 - x0
- local dy = y1 - y0
- local yi = 1
- if(dy < 0) then
- yi = -1
- dy = -dy
- end
- local D = 2*dy - dx
- local y = y0
- for x=x0,x1 do
- plot(x, y, color)
- if D > 0 then
- y = y + yi
- D = D - 2*dx
- end
- D = D + 2*dy
- end
- end
- function plotLineHigh(x0, y0, x1, y1, color)
- local dx = x1 - x0
- local dy = y1 - y0
- local xi = 1
- if(dx < 0) then
- yx = -1
- dx = -dx
- end
- local D = 2*dx - dy
- local x = x0
- for y=y0,y1 do
- plot(x, y, color)
- if D > 0 then
- x = x + xi
- D = D - 2*dy
- end
- D = D + 2*dx
- end
- end
- function plot(x, y, color)
- gpu.fill(x, y, 1, 1, color)
- end
- --Items to track. Split up into multiple lists for readability, combined later on
- local metals = {"Copper Ingot", "Iron Ingot", "Tin Ingot", "Gold Ingot", "Zinc Ingot", "Silver Ingot", "Nickel Ingot"}
- local dusts = {"Redstone Dust", "Glowstone Dust", "Sulfur"}
- local other = {"Ender Pearl", "Nether Quartz", "Certeus Quartz", "Charcoal", "Coal", "Diamond", "Rubber Wood", "Sugarcane"}
- local all = {}
- local totals = {}
- local rates = {}
- local accelerations = {}
- --Initialize all items that we will be analyzing
- for _,item in pairs(combineTables({metals, dusts, other})) do
- all[item] = 0
- rates[item] = 0
- end
- --+ is a blue color, - is a red color. vt100 color codes
- colors = {["+"] = "\27[34m", ["-"] = "\27[31m"}
- --Prints all items that we will be tracking. Wait for a keypress
- printTableKeys(all, "")
- io.read()
- --Make the window smaller, increasing text size.
- gpu.setResolution(80, 25)
- --Get the cutoff (# items below which a name will turn red), and timeout (seconds per refresh)
- term.clear()
- print("Cutoff: ")
- local cutoff = tonumber(io.read())
- print("Timeout: (seconds)")
- local timeout = tonumber(io.read())
- --Main program loop. Manages refreshes, coloring, and table generation
- while true do
- term.clear()
- gpu.setForeground(0xFFFFFF)
- --Table header
- io.write(string.format("%-20s\tCount\titem/%ss\titem/%ss^2\n", "Item",timeout, timeout))
- items = {}
- --
- for i,item in pairs(interface.getItemsInNetwork()) do
- if(type(item) == "table") then
- if(all[item.label] ~= nil) then
- local rate = item.size - all[item.label]
- local dRate = rate - rates[item.label]
- all[item.label] = item.size
- rates[item.label] = rate
- accelerations[item.label] = dRate
- items[#items + 1] = {["size"]=item.size, ["rate"]=rate, ["dRate"]=dRate, ["label"]=item.label}
- end
- end
- end
- table.sort(items, function(a, b)
- return a.size > b.size
- end)
- for k,item in pairs(items) do
- local coloredName = ""
- if(item.size < cutoff) then
- coloredName = colors["-"] .. tostring(item.label)
- else
- coloredName = colors["+"] .. tostring(item.label)
- end
- local coloredRate = ""
- if(item.rate < 0) then
- coloredRate = colors["-"] .. "(" .. tostring(item.rate) .. ")"
- else
- coloredRate = colors["+"] .. "(+" .. tostring(item.rate) .. ")"
- end
- local coloredDRate = ""
- if(item.dRate < 0) then
- coloredDRate = colors["-"] .. "(-" .. tostring(item.dRate) .. ")"
- else
- coloredDRate = colors["+"] .. "(++" .. tostring(item.dRate) .. ")"
- end
- io.write(string.format("%-20s", coloredName) .. "\t\t" .. tostring(item.size) .. "\t" .. coloredRate .. "\t" .. coloredDRate .. "\n")
- end
- os.sleep(timeout)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement