milo: stats

This commit is contained in:
kepler155c@gmail.com
2019-02-15 21:45:56 -05:00
parent cbfc5901f3
commit 0ca89a3a7f
2 changed files with 62 additions and 20 deletions

View File

@@ -87,25 +87,31 @@ local function createPage(node)
tabTitle = 'Overview', tabTitle = 'Overview',
backgroundColor = colors.black, backgroundColor = colors.black,
storageLabel = UI.Text { storageLabel = UI.Text {
x = 2, ex = -1, y = 5, x = 2, ex = -1, y = 2,
}, },
storage = UI.ProgressBar { storage = UI.ProgressBar {
x = 2, ex = -2, y = 6, height = 3, x = 2, ex = -2, y = 3, height = 3,
},
unlockedLabel = UI.Text {
x = 2, ex = -1, y = 7,
},
unlocked = UI.ProgressBar {
x = 2, ex = -2, y = 8, height = 3,
}, },
onlineLabel = UI.Text { onlineLabel = UI.Text {
x = 2, ex = -1, y = 10, x = 2, ex = -1, y = 12,
value = 'Storage Status', value = 'Storage Status',
}, },
online = UI.ProgressBar { online = UI.ProgressBar {
x = 2, ex = -2, y = 11, height = 3, x = 2, ex = -2, y = 13, height = 3,
value = 100, value = 100,
}, },
craftingLabel = UI.Text { craftingLabel = UI.Text {
x = 2, ex = -1, y = 15, x = 2, ex = -1, y = 17,
value = 'Crafting Status', value = 'Crafting Status',
}, },
crafting = UI.ProgressBar { crafting = UI.ProgressBar {
x = 2, ex = -2, y = 16, height = 3, x = 2, ex = -2, y = 18, height = 3,
value = 100, value = 100,
}, },
}, },
@@ -155,7 +161,15 @@ local function createPage(node)
local activityTab = page.tabs[5] local activityTab = page.tabs[5]
local function getStorageStats() local function getStorageStats()
local stats, totals = { }, { usedSlots = 0, totalSlots = 0, totalChests = 0 } local stats = { }
local totals = {
usedSlots = 0,
totalSlots = 0,
totalChests = 0,
unlockedSlots = 0,
usedUnlockedSlots = 0,
}
for n in context.storage:filterActive('storage') do for n in context.storage:filterActive('storage') do
if n.adapter.size and n.adapter.list then if n.adapter.size and n.adapter.list then
pcall(function() pcall(function()
@@ -163,6 +177,7 @@ local function createPage(node)
n.adapter.__size = n.adapter.size() n.adapter.__size = n.adapter.size()
n.adapter.__used = Util.size(n.adapter.list()) n.adapter.__used = Util.size(n.adapter.list())
end end
local updated = n.adapter.__lastUpdate ~= n.adapter.lastUpdate
if n.adapter.__lastUpdate ~= n.adapter.lastUpdate then if n.adapter.__lastUpdate ~= n.adapter.lastUpdate then
n.adapter.__used = Util.size(n.adapter.list()) n.adapter.__used = Util.size(n.adapter.list())
n.adapter.__lastUpdate = n.adapter.lastUpdate n.adapter.__lastUpdate = n.adapter.lastUpdate
@@ -172,10 +187,15 @@ local function createPage(node)
size = n.adapter.__size, size = n.adapter.__size,
used = n.adapter.__used, used = n.adapter.__used,
perc = math.floor(n.adapter.__used / n.adapter.__size * 100), perc = math.floor(n.adapter.__used / n.adapter.__size * 100),
updated = updated,
}) })
totals.usedSlots = totals.usedSlots + n.adapter.__used totals.usedSlots = totals.usedSlots + n.adapter.__used
totals.totalSlots = totals.totalSlots + n.adapter.__size totals.totalSlots = totals.totalSlots + n.adapter.__size
totals.totalChests = totals.totalChests + 1 totals.totalChests = totals.totalChests + 1
if not n.lock then
totals.unlockedSlots = totals.unlockedSlots + n.adapter.__size
totals.usedUnlockedSlots = totals.usedUnlockedSlots + n.adapter.__used
end
end) end)
end end
end end
@@ -230,21 +250,21 @@ local function createPage(node)
end end
function usageTab.grid:getRowTextColor(row, selected) function usageTab.grid:getRowTextColor(row, selected)
if row.lastCount and row.lastCount ~= row.count then return row.updated and colors.yellow or
return row.count > row.lastCount and colors.yellow or colors.lightGray UI.Grid:getRowTextColor(row, selected)
end
return UI.Grid:getRowTextColor(row, selected)
end end
function statsTab.textArea:draw() function statsTab.textArea:draw()
local _, stats = getStorageStats() local _, stats = getStorageStats()
local totalItems, nodeCount = 0, 0 local totalItems, nodeCount = 0, 0
local formatString = [[ local formatString = [[
Storage Usage : %d%% Storage Usage : %d%%
Slots : %d of %d used Slots : %d of %d used
Unique Items : %d Unique Items : %d
Total Items : %d Total Items : %d
Nodes : %d Nodes : %d
Unlocked Slots : %d of %d (%d%%)
]] ]]
for _,v in pairs(context.storage.nodes) do for _,v in pairs(context.storage.nodes) do
@@ -263,7 +283,10 @@ Nodes : %d
stats.totalSlots, stats.totalSlots,
Util.size(context.storage.cache), Util.size(context.storage.cache),
totalItems, totalItems,
nodeCount) nodeCount,
stats.usedUnlockedSlots,
stats.unlockedSlots,
math.floor(stats.usedUnlockedSlots / stats.unlockedSlots * 100))
UI.TextArea.draw(self) UI.TextArea.draw(self)
end end
@@ -281,7 +304,6 @@ Nodes : %d
function overviewTab:draw() function overviewTab:draw()
local _, stats = getStorageStats() local _, stats = getStorageStats()
local percent = math.floor(stats.usedSlots / stats.totalSlots * 100)
self.online.progressColor = context.storage:isOnline() and colors.green or colors.red self.online.progressColor = context.storage:isOnline() and colors.green or colors.red
@@ -290,6 +312,7 @@ Nodes : %d
self.crafting.progressColor = Milo:isCraftingPaused() and colors.yellow or colors.green self.crafting.progressColor = Milo:isCraftingPaused() and colors.yellow or colors.green
local percent = math.floor(stats.usedSlots / stats.totalSlots * 100)
local color = colors.green local color = colors.green
if percent > 90 then if percent > 90 then
color = colors.red color = colors.red
@@ -299,10 +322,23 @@ Nodes : %d
self.storage.progressColor = color self.storage.progressColor = color
self.storage.value = percent self.storage.value = percent
self.storageLabel.value = string.format('Usage: %s%% (%s of %s slots)', self.storageLabel.value = string.format('Total Usage: %s%% (%s of %s slots)',
percent, stats.usedSlots, stats.totalSlots) percent, stats.usedSlots, stats.totalSlots)
UI.Tab.draw(self) percent = math.floor(stats.usedUnlockedSlots / stats.unlockedSlots * 100)
color = colors.green
if percent > 90 then
color = colors.red
elseif percent > 75 then
color = colors.yellow
end
self.unlocked.progressColor = color
self.unlocked.value = percent
self.unlockedLabel.value = string.format('Unlocked Usage: %s%% (%s of %s slots)',
percent, stats.usedUnlockedSlots, stats.usedSlots)
UI.Tab.draw(self)
end end
function overviewTab:enable() function overviewTab:enable()

View File

@@ -6,6 +6,12 @@ local modules = _G.peripheral.wrap('back')
local os = _G.os local os = _G.os
local parallel = _G.parallel local parallel = _G.parallel
if not modules.launch or not modules.getMetaOwner then
error([[Required:
* kinetic augment is required')
* error('introspection module is required]])
end
local function run() local function run()
while true do while true do
local meta = modules.getMetaOwner() local meta = modules.getMetaOwner()