Jump to content

Module:SuccessScoreandRanking

From Wikipedia, the free encyclopedia
local p = {}

function p.rankTable(frame)
    local args = frame:getParent().args
    local rows = {}
    local count = tonumber(args["count"]) or 0

    for i = 1, count do
        local cmc_wins = tonumber(args["cmc" .. i]) or 0
        local cmc_weighting = tonumber(args["cmc_weighting" .. i]) or 0
        local dtl_wins = tonumber(args["dtl" .. i]) or 0
        local dtl_weighting = tonumber(args["dtl_weighting" .. i]) or 0
        local dmc_wins = tonumber(args["dmc" .. i]) or 0
        local dmc_weighting = tonumber(args["dmc_weighting" .. i]) or 0
        local success_score = (cmc_wins * cmc_weighting) + (dtl_wins * dtl_weighting) + (dmc_wins * dmc_weighting)

        table.insert(rows, {
            club = args["club" .. i] or "",
            confederation = args["confederation" .. i] or "",
            country = args["country" .. i] or "",
            cmc = cmc_wins,
            cmc_weighting = cmc_weighting,
            cmc_score = cmc_wins * cmc_weighting,
            dtl = dtl_wins,
            dtl_weighting = dtl_weighting,
            dtl_score = dtl_wins * dtl_weighting,
            dmc = dmc_wins,
            dmc_weighting = dmc_weighting,
            dmc_score = dmc_wins * dmc_weighting,
            trophies = args["trophies" .. i] or "",
            success_score = success_score
        })
    end

    table.sort(rows, function(a, b)
        return a.success_score > b.success_score
    end)

    local result = "{| class='wikitable sortable' style='text-align:center;'\n"
    result = result .. "! Rank !! Club !! Confederation !! Country !! Continental Main Cups !! CMC Weighting !! CMC Score !! Domestic Top Leagues !! DTL Weighting !! DTL Score !! Domestic Main Cups !! DMC Weighting !! DMC Score !! Trophies Won !! Success Score\n"

    for i, row in ipairs(rows) do
        result = result .. "|-\n"
        result = result .. "! " .. i .. "\n"
        result = result .. "| " .. row.club .. " || " .. row.confederation .. " || " .. row.country .. " || " .. row.cmc .. " || " .. row.cmc_weighting .. " || " .. row.cmc_score .. " || " .. row.dtl .. " || " .. row.dtl_weighting .. " || " .. row.dtl_score .. " || " .. row.dmc .. " || " .. row.dmc_weighting .. " || " .. row.dmc_score .. " || " .. row.trophies .. " || " .. row.success_score .. "\n"
    end

    result = result .. "|}"
    return result
end

return p