Jump to content

Module:SuccessScoreandRanking

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Qwyzikal (talk | contribs) at 14:47, 23 February 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

function p.rankTable(frame)
    local args = frame:getParent().args
    local rows = {}

    -- Collect data from template parameters
    for i = 1, tonumber(args["count"] or 0) 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

        -- Calculate success score
        local success_score = (cmc_wins * cmc_weighting) + (dtl_wins * dtl_weighting) + (dmc_wins * dmc_weighting)

        -- Store row data
        table.insert(rows, {
            club = args["club" .. i] or "Unknown",
            confederation = args["confederation" .. i] or "Unknown",
            country = args["country" .. i] or "Unknown",
            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 0,
            success_score = success_score
        })
    end

    -- Sort rows by success score (highest first)
    table.sort(rows, function(a, b)
        return a.success_score > b.success_score
    end)

    -- Build table output
    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! " .. i .. "\n| " 
            .. 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