(Створена сторінка: local p = {} --- Отримує дані гравця з конкретного сезону local function get_season_data(season_number, player_name) local season_names = { [1] = "Перший сезон", [2] = "Другий сезон", [3] = "Третій сезон", [4] = "Четвертий сезон", [5] = "П'ятий сезон", [6] = "Шостий сезон", [7] = "Сьомий...)
 
(Сторінка очищена)
Мітка: Очищення
 
(Не показані 3 проміжні версії цього користувача)
Рядок 1: Рядок 1:
local p = {}


--- Отримує дані гравця з конкретного сезону
local function get_season_data(season_number, player_name)
    local season_names = {
        [1] = "Перший сезон",
        [2] = "Другий сезон",
        [3] = "Третій сезон",
        [4] = "Четвертий сезон",
        [5] = "П'ятий сезон",
        [6] = "Шостий сезон",
        [7] = "Сьомий сезон",
        [8] = "Восьмий сезон",
        [9] = "Дев'ятий сезон"
    }
   
    local season_name = season_names[season_number]
    if not season_name then
        return nil
    end
   
    local title = mw.title.new(season_name)
    if not title or not title.exists then
        return nil
    end
   
    local content = title:getContent()
    if not content then
        return nil
    end
   
    -- Знаходимо секцію "Рейтинг"
    local rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.-)==")
    if not rating_section then
        rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.*)")
    end
   
    if not rating_section then
        return nil
    end
   
    -- Знаходимо таблицю
    local table_start = mw.ustring.find(rating_section, "{|")
    local table_end = mw.ustring.find(rating_section, "|}", table_start)
   
    if not table_start or not table_end then
        return nil
    end
   
    local table_content = mw.ustring.sub(rating_section, table_start, table_end + 1)
   
    -- Шукаємо рядок з гравцем
    local rows = {}
    for row in mw.ustring.gmatch(table_content, "|-\n(.-)\n|-") do
        table.insert(rows, row)
    end
   
    local last_row = mw.ustring.match(table_content, "|-\n(.-)%s*|}")
    if last_row then
        table.insert(rows, last_row)
    end
   
    for _, row in ipairs(rows) do
        -- Перевіряємо чи є ім'я гравця в цьому рядку
        if mw.ustring.find(row, "%[%[" .. player_name .. "%]%]") then
            local cells = {}
            row = mw.ustring.gsub(row, "^%s*|%s*", "")
           
            for cell in mw.ustring.gmatch(row, "|%s*([^\n|]+)") do
                local trimmed = mw.text.trim(cell)
                if trimmed ~= "" then
                    table.insert(cells, trimmed)
                end
            end
           
            -- cells[1] = №, cells[2] = Пан/Пані, cells[3] = Σ, cells[4] = І, cells[5] = %
            if #cells >= 5 then
                return {
                    place = mw.text.trim(cells[1]),
                    points = mw.text.trim(cells[3]),
                    games = mw.text.trim(cells[4]),
                    winrate = mw.text.trim(cells[5])
                }
            end
        end
    end
   
    return nil
end
--- Головна функція для виведення таблиці досягнень
function p.season_achievements(frame)
    local player_name = frame.args.player
   
    if not player_name or player_name == "" then
        return "<span style='color:red;'>Ім'я гравця не вказано</span>"
    end
   
    -- Створюємо HTML таблицю
    local htmlTable = mw.html.create('table')
        :addClass('wikitable sortable')
        :css('width', '100%')
        :css('font-size', '14.5px')
   
    -- Додаємо заголовки
    local headerRow = htmlTable:tag('tr')
    headerRow:tag('th'):wikitext('Сезон')
    headerRow:tag('th'):wikitext('Місце')
    headerRow:tag('th'):wikitext('Бали')
    headerRow:tag('th'):wikitext('% перемог')
    headerRow:tag('th'):wikitext('Ігор')
   
    local has_data = false
   
    -- Проходимо по всіх 9 сезонах
    for season = 1, 9 do
        local data = get_season_data(season, player_name)
       
        if data then
            has_data = true
            local row = htmlTable:tag('tr')
           
            -- Сезон
            local season_links = {
                [1] = "[[Перший сезон#Рейтинг|01 сезон]]",
                [2] = "[[Другий сезон#Рейтинг|02 сезон]]",
                [3] = "[[Третій сезон#Рейтинг|03 сезон]]",
                [4] = "[[Четвертий сезон#Рейтинг|04 сезон]]",
                [5] = "[[П'ятий сезон#Рейтинг|05 сезон]]",
                [6] = "[[Шостий сезон#Рейтинг|06 сезон]]",
                [7] = "[[Сьомий сезон#Рейтинг|07 сезон]]",
                [8] = "[[Восьмий сезон#Рейтинг|08 сезон]]",
                [9] = "[[Дев'ятий сезон#Рейтинг|09 сезон]]"
            }
           
            row:tag('td')
                :css('text-align', 'center')
                :css('padding', '8px')
                :wikitext(season_links[season])
           
            -- Місце
            row:tag('td')
                :css('text-align', 'center')
                :css('padding', '8px')
                :wikitext(data.place)
           
            -- Бали
            row:tag('td')
                :css('text-align', 'center')
                :css('padding', '8px')
                :wikitext(data.points)
           
            -- % перемог
            row:tag('td')
                :css('text-align', 'center')
                :css('padding', '8px')
                :wikitext(data.winrate)
           
            -- Ігор
            row:tag('td')
                :css('text-align', 'center')
                :css('padding', '8px')
                :wikitext(data.games)
        end
    end
   
    if not has_data then
        return "''Гравець не брав участі в жодному сезоні''"
    end
   
    return tostring(htmlTable)
end
return p

Поточна версія на 12:46, 1 грудня 2025

Документацію для цього модуля можна створити у Модуль:FetchData6/документація