SHOW:
|
|
- or go back to the newest paste.
1 | - | local component = require("component") |
1 | + | local component = require("component") |
2 | - | local sides = require("sides") |
2 | + | local sides = require("sides") |
3 | - | local term = require("term") |
3 | + | local term = require("term") |
4 | - | local os = require("os") |
4 | + | local os = require("os") |
5 | - | |
5 | + | |
6 | - | local old_stacks = {} |
6 | + | local old_stacks = {} |
7 | - | |
7 | + | |
8 | - | function display_chest_content(side) |
8 | + | function display_chest_content(side) |
9 | - | local items = component.inventory_controller.getAllStacks(side) |
9 | + | local items = component.inventory_controller.getAllStacks(side) |
10 | - | if not items then |
10 | + | if not items then |
11 | - | return false |
11 | + | return false |
12 | - | end |
12 | + | end |
13 | - | |
13 | + | |
14 | - | print("Listing inventory on side " .. side) |
14 | + | print("Listing inventory on side " .. side) |
15 | - | |
15 | + | |
16 | - | local size = math.floor(component.inventory_controller.getInventorySize(side)) |
16 | + | local size = math.floor(component.inventory_controller.getInventorySize(side)) |
17 | - | |
17 | + | |
18 | - | local stacks = {} |
18 | + | local stacks = {} |
19 | - | for k, v in ipairs(items) do |
19 | + | for k, v in ipairs(items) do |
20 | - | if v.size > 1 then |
20 | + | if v.size > 1 then |
21 | - | stacks[#stacks + 1] = v |
21 | + | stacks[#stacks + 1] = v |
22 | - | end |
22 | + | end |
23 | - | end |
23 | + | end |
24 | - | |
24 | + | |
25 | - | print(#stacks .. "/" .. size .. " stacks in inventory") |
25 | + | print(#stacks .. "/" .. size .. " stacks in inventory") |
26 | - | |
26 | + | |
27 | - | table.sort(stacks, function(a, b) return a.size > b.size end) |
27 | + | table.sort(stacks, function(a, b) return a.size > b.size end) |
28 | - | |
28 | + | |
29 | - | for n, stack in ipairs(stacks) do |
29 | + | for n, stack in ipairs(stacks) do |
30 | - | local diff = "" |
30 | + | local diff = "" |
31 | - | if old_stacks[stack.label] then |
31 | + | if old_stacks[stack.label] then |
32 | - | diff = math.floor(stack.size - old_stacks[stack.label].size) |
32 | + | diff = math.floor(stack.size - old_stacks[stack.label].size) |
33 | - | if diff > 0 then |
33 | + | if diff > 0 then |
34 | - | diff = "+" .. tostring(diff) |
34 | + | diff = "+" .. tostring(diff) |
35 | - | elseif diff <= 0 then |
35 | + | elseif diff <= 0 then |
36 | - | diff = "" |
36 | + | diff = "" |
37 | - | end |
37 | + | end |
38 | - | end |
38 | + | end |
39 | - | |
39 | + | |
40 | - | local mean = "" |
40 | + | local mean = "" |
41 | - | if old_stacks[stack.label] then |
41 | + | if old_stacks[stack.label] then |
42 | - | old_stacks[stack.label] = { |
42 | + | old_stacks[stack.label] = { |
43 | - | size=stack.size, |
43 | + | size=stack.size, |
44 | - | total=(tonumber(diff) or 0) + old_stacks[stack.label].total, |
44 | + | total=(tonumber(diff) or 0) + old_stacks[stack.label].total, |
45 | - | count=1 + old_stacks[stack.label].count |
45 | + | count=1 + old_stacks[stack.label].count |
46 | - | } |
46 | + | } |
47 | - | |
47 | + | |
48 | - | mean = old_stacks[stack.label].total / old_stacks[stack.label].count |
48 | + | mean = old_stacks[stack.label].total / old_stacks[stack.label].count |
49 | - | if mean > 0 then |
49 | + | if mean > 0 then |
50 | - | mean = "+" .. string.format("%2.1f", mean) |
50 | + | mean = "+" .. string.format("%2.1f", mean) |
51 | - | elseif mean <= 0 then |
51 | + | elseif mean <= 0 then |
52 | - | mean = "" |
52 | + | mean = "" |
53 | - | end |
53 | + | end |
54 | - | else |
54 | + | else |
55 | - | old_stacks[stack.label] = { |
55 | + | old_stacks[stack.label] = { |
56 | - | size=stack.size, |
56 | + | size=stack.size, |
57 | - | total=0, |
57 | + | total=0, |
58 | - | count=0 |
58 | + | count=0 |
59 | - | } |
59 | + | } |
60 | - | end |
60 | + | end |
61 | - | |
61 | + | |
62 | - | print(stack.label .. string.rep("\t", 3 - math.floor(#stack.label / 8)) .. "| " .. math.floor(stack.size) .. "\t| " .. diff .. "\t| " .. mean) |
62 | + | print(stack.label .. string.rep("\t", 3 - math.floor(#stack.label / 8)) .. "| " .. math.floor(stack.size) .. "\t| " .. diff .. "\t| " .. mean) |
63 | - | end |
63 | + | end |
64 | end | |
65 | - | |
65 | + | |
66 | - | local refresh = 0 |
66 | + | local refresh = 0 |
67 | - | while true do |
67 | + | while true do |
68 | - | term.clear() |
68 | + | term.clear() |
69 | - | print("Refreshed " .. refresh .. " times") |
69 | + | print("Refreshed " .. refresh .. " times") |
70 | - | for i = 0, 5 do |
70 | + | for i = 0, 5 do |
71 | - | display_chest_content(i) |
71 | + | display_chest_content(i) |
72 | - | end |
72 | + | end |
73 | - | os.sleep(60) |
73 | + | os.sleep(60) |
74 | - | refresh = refresh + 1 |
74 | + | refresh = refresh + 1 |
75 | end |