5441
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 87: | Рядок 87: | ||
local cells = {} | local cells = {} | ||
for line in mw.ustring.gmatch(row, "[^\n]+") do | for line in mw.ustring.gmatch(row, "[^\n]+") do | ||
line = mw.text.trim(line) | line = mw.text.trim(line) | ||
if line ~= "|-" and line ~= "" then | if line ~= "|-" and line ~= "" then | ||
line = mw.ustring.gsub(line, "^|%s*", "") | line = mw.ustring.gsub(line, "^|%s*", "") | ||
| Рядок 815: | Рядок 812: | ||
return games and tostring(#games) or "0" | return games and tostring(#games) or "0" | ||
end | end | ||
-- ================================================ | |||
-- FETCHDATA6 (досягнення в сезонах) | |||
-- ================================================ | |||
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 content = get_page_content(season_name) | |||
if not content then return nil end | |||
local rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.-)\n==") | |||
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 current_row = {} | |||
local all_rows = {} | |||
for line in mw.ustring.gmatch(table_content .. "\n", "([^\n]*)\n") do | |||
line = mw.text.trim(line) | |||
if line == "|-" then | |||
if #current_row > 0 then | |||
table.insert(all_rows, current_row) | |||
end | |||
current_row = {} | |||
elseif mw.ustring.match(line, "^|[^-}]") then | |||
local cell_content = mw.ustring.gsub(line, "^|%s*", "") | |||
table.insert(current_row, cell_content) | |||
end | |||
end | |||
if #current_row > 0 then | |||
table.insert(all_rows, current_row) | |||
end | |||
for _, row in ipairs(all_rows) do | |||
if #row >= 5 then | |||
local player_cell = clean_wikilinks(row[2]) | |||
if player_cell == player_name then | |||
return { | |||
place = mw.text.trim(row[1]), | |||
points = mw.text.trim(row[3]), | |||
games = mw.text.trim(row[4]), | |||
winrate = mw.text.trim(row[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 | |||
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 season_links = { | |||
[1] = "[[Перший сезон#Рейтинг|01 сезон]]", | |||
[2] = "[[Другий сезон#Рейтинг|02 сезон]]", | |||
[3] = "[[Третій сезон#Рейтинг|03 сезон]]", | |||
[4] = "[[Четвертий сезон#Рейтинг|04 сезон]]", | |||
[5] = "[[П'ятий сезон#Рейтинг|05 сезон]]", | |||
[6] = "[[Шостий сезон#Рейтинг|06 сезон]]", | |||
[7] = "[[Сьомий сезон#Рейтинг|07 сезон]]", | |||
[8] = "[[Восьмий сезон#Рейтинг|08 сезон]]", | |||
[9] = "[[Дев'ятий сезон#Рейтинг|09 сезон]]" | |||
} | |||
for season = 1, 9 do | |||
local data = get_season_data(season, player_name) | |||
local row = htmlTable:tag('tr') | |||
row:tag('td'):css('text-align', 'center'):css('padding', '8px'):wikitext(season_links[season]) | |||
if data then | |||
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) | |||
else | |||
for i = 1, 4 do | |||
row:tag('td'):css('text-align', 'center'):css('padding', '8px'):css('color', '#666'):wikitext('-') | |||
end | |||
end | |||
end | |||
return tostring(htmlTable) | |||
end | |||
return p | |||