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:06, 23 February 2025 (Module for automatically updating rankings in table). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
local p = {}

function p.rankTable(frame)
    local args = frame:getParent().args
    local rows = {}
    
    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
        
        local success_score = (cmc_wins * cmc_weighting) + (dtl_wins * dtl_weighting) + (dmc_wins * dmc_weighting)
        
        table.insert(rows, {
            rank = i,
            club = args["club" .. i],
            confederation = args["confederation" .. i],
            country = args["country" .. i],
            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],
            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! 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