SHOW:
|
|
- or go back to the newest paste.
1 | - | --PowergraphMulti is made by Stekeblad 11/2017 |
1 | + | -- TODO: actually make graph? |
2 | ||
3 | - | ------------- Configuration part ------------------ |
3 | + | local monitor = peripheral.find "monitor" |
4 | - | |
4 | + | local storage = peripheral.find(settings.get "storage_type" or "draconic_rf_storage") |
5 | - | -- Seconds between checking stored energy |
5 | + | local capacity = (storage.getMaxEnergyStored or storage.getEnergyCapacity)() |
6 | - | -- and updating monitors (default: 5) |
6 | + | local delay = 0.1 |
7 | - | local updateInterval = 5 |
7 | + | local ticks_delay = 0.1 / 0.05 |
8 | ||
9 | - | -- Simple mode tries to scan for compatible storages and |
9 | + | local function read_energy() |
10 | - | -- wrap the first found one and the first found monitor |
10 | + | return storage.getEnergyStored() |
11 | - | -- For more advanced configuration, set this to false and |
11 | + | |
12 | - | -- and fill the dataTable below (example follows) |
12 | + | |
13 | - | -- Default: true |
13 | + | monitor.setTextScale(1) |
14 | - | local simpleMode = true |
14 | + | monitor.setBackgroundColor(colors.black) |
15 | - | |
15 | + | monitor.setTextColor(colors.white) |
16 | - | local dataTable = { |
16 | + | local data = {} |
17 | - | |
17 | + | |
18 | - | } |
18 | + | local prefixes = {"", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"} |
19 | local function SI_prefix(value, unit) | |
20 | - | -- help for how to fill dataTable: |
20 | + | local i = 1 |
21 | - | --[[ add a comma at the end of all lines except the |
21 | + | local x = value |
22 | - | last one in all tables. |
22 | + | while x > 1000 or x < -1000 do |
23 | - | "[required]" in front of a line means you need to |
23 | + | x = x / 1000 |
24 | - | have it or the program won't work, rows with |
24 | + | i = i + 1 |
25 | - | "[optional]" are optional and can be left out. |
25 | + | |
26 | - | The following information can be added: |
26 | + | return ("%.3f%s%s"):format(x, prefixes[i], unit) |
27 | end | |
28 | - | [required] monitor = the side or network name |
28 | + | |
29 | - | of a monitor connected to the computer. |
29 | + | local function display(data) |
30 | - | [required] energy = the energy storage witch |
30 | + | monitor.clear() |
31 | - | content should be displayed on the |
31 | + | local longest_label = 0 |
32 | - | monitor defined above. |
32 | + | for _, val in pairs(data) do |
33 | - | [optional] text = a word or sentence that will |
33 | + | if #val[1] > longest_label then longest_label = #val[1] end |
34 | - | be displayed at the bottom line on the |
34 | + | |
35 | - | monitor. |
35 | + | local i = 1 |
36 | - | [optional] blitColor = Will be ignored if its |
36 | + | for _, val in pairs(data) do |
37 | - | not a advanced monitor, specifies the |
37 | + | monitor.setCursorPos(1, i) |
38 | - | color of the graph, see following link |
38 | + | monitor.write(val[1] .. ":" .. (" "):rep(longest_label - #val[1] + 2) .. val[2]) |
39 | - | for help: |
39 | + | i = i + 1 |
40 | - | http://www.computercraft.info/wiki/Colors_(API)#Colors |
40 | + | |
41 | - | allowed values are 0-9 and a-f, |
41 | + | |
42 | - | defaults to 5 (green) |
42 | + | |
43 | - | [optional] textSize = Sets how large the text is and |
43 | + | local past_RF_per_tick = {} |
44 | - | how thick the graph line is. |
44 | + | local history_length = 1200 / ticks_delay |
45 | - | Needs to be between 0.5 and 5 and is in |
45 | + | local function display_stats() |
46 | - | steps of 0.5. eg 0.5, 1, 1.5 ... 4.5, 5 |
46 | + | local previous |
47 | - | Default is 1. (5 is very large text) |
47 | + | while true do |
48 | - | |
48 | + | local energy = read_energy() |
49 | - | local Example = { |
49 | + | if previous then |
50 | - | { |
50 | + | local diff = energy - previous |
51 | - | monitor = "monitor_1", <-- comma |
51 | + | local RF_per_tick = diff / ticks_delay |
52 | - | energy = "tile_blockcapacitorbank_name_0", <--comma |
52 | + | table.insert(past_RF_per_tick, RF_per_tick) |
53 | - | text = "ME Backup", <-- comma |
53 | + | if #past_RF_per_tick > history_length then table.remove(past_RF_per_tick, 1) end |
54 | - | blitColor = "5" <-- no comma, last line for this monitor-battery pair |
54 | + | local total = 0 |
55 | - | },{ <-- comma between braces, there are more monitor-battery pairs |
55 | + | for _, h in pairs(past_RF_per_tick) do total = total + h end |
56 | - | monitor = "top", <-- comma |
56 | + | local average = total / #past_RF_per_tick |
57 | - | energy = "back", <-- comma |
57 | + | |
58 | - | textSize = 0.5 <-- no comma, last line in this pair |
58 | + | display { |
59 | - | } <-- no comma, this was last pair |
59 | + | { "Time", ("%s.%03d"):format(os.date "!%X", os.epoch "utc" % 1000) }, |
60 | - | } <-- closing the example table, no comma |
60 | + | { "Stored", SI_prefix(energy, "RF") }, |
61 | { "Capacity", SI_prefix(capacity, "RF") }, | |
62 | - | ]] -- (ignore this two brackets, they indicate |
62 | + | { "% filled", ("%.4f%%"):format(energy / capacity * 100) }, |
63 | - | -- the end of this long multi-line comment) |
63 | + | { "Inst I/O", SI_prefix(RF_per_tick, "RF/t") }, |
64 | { "60s I/O" , SI_prefix(average, "RF/t") }, | |
65 | - | ------------- End of configuration part -------------------- |
65 | + | } |
66 | end | |
67 | - | -- Dont change anything below this line |
67 | + | previous = energy |
68 | - | -- if you not know what you are doing! |
68 | + | sleep(delay) |
69 | end | |
70 | - | if simpleMode then |
70 | + | |
71 | - | dataTable.auto = {} |
71 | + | |
72 | - | |
72 | + | display_stats() |