Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add parsing of target amount from container name #5

Open
mkmarq opened this issue Nov 29, 2020 · 1 comment
Open

Comments

@mkmarq
Copy link

mkmarq commented Nov 29, 2020

I'd like to be able to specify a target amount in the container hub name.

To be used in 2 ways:

  1. Color based on percentage of target amount
  2. Difference between current amount and target amount displayed, along with current amount and capacity
    For example, 200 units in container that holds 1000 with target of 500 might display 200/300/1000
    Another example, 600 units in container that holds 1000 with target of 500 might display 600/-100/1000
@mkmarq
Copy link
Author

mkmarq commented Dec 2, 2020

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">&nbsp;</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 .. [[">&nbsp;</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 ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant