Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Documentation for this module may be created at Module:RankingEvent/doc

local p = {}
local cargo = mw.ext.cargo

local function clean(s)
    if not s then return nil end
    local res = s:gsub("^%s*(.-)%s*$", "%1")
    return res == "" and nil or res
end

local function parseLine(line)
    local data = {}
    for pair in string.gmatch(line, "[^,]+") do
        local key, val = string.match(pair, "^%s*([^=]+)%s*=%s*(.-)%s*$")
        if key and val then data[string.lower(key)] = val end
    end
    return data
end

function p.store(frame)
    local args = frame:getParent().args
    local statType = string.lower(clean(args.type) or "team")
    
    local meta = {
        tournament = clean(args.tournament),
        tier       = clean(args.tier),
        end_date   = clean(args.end_date)
    }

    local tableName = (statType == "player") and "RankingData_Player" or "RankingData_Team"
    
    for i = 1, 200 do
        local line = args[tostring(i)]
        if line and clean(line) then
            local rowData = parseLine(line)
            local storeData = {
                tournament = meta.tournament,
                tier       = meta.tier,
                end_date   = meta.end_date
            }
            
            if statType == "team" then
                storeData.team = rowData.team
                storeData.rank = tonumber(rowData.rank)
            elseif statType == "player" then
                storeData.player      = rowData.player
                storeData.team        = rowData.team
                storeData.finishes    = tonumber(rowData.finishes) or 0
                storeData.mvp_tourney = tonumber(rowData.mvp_tourney) or 0
                storeData.igl         = tonumber(rowData.igl) or 0
                storeData.survivor    = tonumber(rowData.survivor) or 0
                storeData.mvp_finals  = tonumber(rowData.mvp_finals) or 0
                storeData.emerging    = tonumber(rowData.emerging) or 0
            end
            
            if cargo and cargo.store then cargo.store(tableName, storeData) end
        end
    end
    return "<div style='display:none;'>Ranking Event Stored.</div>"
end

return p