Open mkmarq opened 3 years ago
Just got this working on my local board.
I'm using the description, if it's present and a valid number, as my target.
Code snippets: changed material_readout_cell
function material_readout_cell(name)
local x = {}
local html = ""
--system.print("NAME: "..hasValue(name))
if name == nil then
html = [[<div class="row"><div class="name"></div><div class="percentage"></div><div class="progressbar" style="width:0%; background-color:pink"> </div></div>]]
else
--system.print(name)
x = getMaterial(name)
--system.print("ENTRA 1")
if next(x) == nil then
--system.print("array vazio")
html = [[<div class="rowinfo">PLEASE CONNECT<br>]] .. name .. [[</div>]]
else
local percentage = getFromArray(x, 9)
local targetpercentage = nil
local rawdescription = getFromArray(x, 6)
local description = ""
local quantity = getFromArray(x, 8)
local totalcontainerqtdinlitre = getFromArray(x, 10)
if rawdescription == "empty" then
description = ""
elseif tonumber(rawdescription) ~= nil then
description = getValueWithUnits(tonumber(rawdescription))
if tonumber(rawdescription) > 0 then
targetpercentage = quantity * 100 / tonumber(rawdescription)
end
else
description = rawdescription
end
local color = nil
if targetpercentage ~= nil then
color = progresscolor(targetpercentage)
else
color = progresscolor(percentage)
end
--print_r(x)
--system.print("MATERIAL: "..name.." | %: "..percentage)
html = [[<div class="row"><div class="name">]] .. _G[name][1] .. [[</div><div class="percentage">]] .. percentage .. [[%</div><div class="progressbar" style="width:]] .. percentage .. [[%; background-color:]] .. color .. [["> </div>
<div class="desc">]]
.. description .. [[</div><div class="info">]] .. litreParse(quantity, totalcontainerqtdinlitre, tonumber(rawdescription)) .. [[</div></div>]]
--system.print(progresscolor(percentage))
end
end
return html
end
changed litreParse (uses code snippet included in #6 comments as base)
function litreParse(litre, total, target)
local parsed = getValueWithUnits(litre) .. "/"
if target ~= nil and tonumber(target) ~= nil then
parsed = parsed .. getValueWithUnits(target-litre) .. "/"
end
return parsed .. getValueWithUnits(total)
end
function getValueWithUnits(value)
local size = ""
if value < 1000 and value > -1000 then
size = "L"
elseif value < 1000000 and value > -1000000 then
value = value / 1000
size = "kL"
else
value = value / 1000000
size = "kt"
end
return string.format("%.1f",value)..size
end
Feel free to incorporate into the project.
If you do, then I'll be able to keep using updates as they come ^_^
I'd like to be able to specify a target amount in the container hub name.
To be used in 2 ways: