Modul:Ewige Gegner-Scorer gegen Kassel: Unterschied zwischen den Versionen

ChatBot (Diskussion | Beiträge)
Modul rendert große Tabelle direkt als sortable wikitable
ChatBot (Diskussion | Beiträge)
Rote Links in der Scorer-Tabelle unterdrücken
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 44: Zeile 44:
table.insert(list, value)
table.insert(list, value)
end
end
end
local function escapePattern(value)
return (value:gsub('([%(%)%.%%%+%-%*%?%[%]%^%$])', '%%%1'))
end
end


Zeile 152: Zeile 156:
end
end
return pages or {}
return pages or {}
end
local function getPageContent(pageName)
local title = mw.title.new(pageName)
if not title then
return ''
end
local ok, content = pcall(function()
return title:getContent()
end)
if not ok then
return ''
end
return content or ''
end
end


Zeile 327: Zeile 345:
if #seasons == 0 then
if #seasons == 0 then
return {}
return {}
end
local rowsByName = {}
local orderedRows = {}
local scannedPages = {}
local function ensureRow(name)
name = trim(name)
local row = rowsByName[name]
if not row then
row = {
page = name,
name = name,
games = 0,
goals = 0,
assists = 0,
points = 0,
teams = {}
}
rowsByName[name] = row
table.insert(orderedRows, row)
end
return row
end
for _, season in ipairs(seasons) do
for _, competition in ipairs(competitions) do
local seasonPattern = escapePattern(season)
local competitionPattern = escapePattern(competition)
for _, pageName in ipairs(getCategoryMembers(season .. ' ' .. competition)) do
if not scannedPages[pageName] then
scannedPages[pageName] = true
local content = getPageContent(pageName)
for category in content:gmatch('%[%[%s*[Kk]ategorie%s*:%s*([^%]]+)%]%]') do
category = trim(category)
local gpName = category:match('^' .. seasonPattern .. ' GP (.-) VS%-Kassel ' .. competitionPattern .. '$')
if gpName then
local row = ensureRow(gpName)
row.games = row.games + 1
end
local value, statKey, statName = category:match('^' .. seasonPattern .. ' (%d+) ([TAP]) (.-) VS%-Kassel ' .. competitionPattern .. '$')
if value and statKey and statName then
local row = ensureRow(statName)
value = tonumber(value) or 0
if statKey == 'T' then
row.goals = row.goals + value
elseif statKey == 'A' then
row.assists = row.assists + value
elseif statKey == 'P' then
row.points = row.points + value
end
end
local teamCode, teamName = category:match('^' .. seasonPattern .. ' Team ([A-ZÄÖÜ0-9]+) (.-) VS%-Kassel ' .. competitionPattern .. '$')
if teamCode and teamName then
addTeam(ensureRow(teamName), teamCode)
end
end
end
end
end
end
if #orderedRows > 0 then
return orderedRows
end
end


Zeile 362: Zeile 446:
end
end
return rows
return rows
end
local titleExistsCache = {}
local function titleExists(page)
page = trim(page)
if page == '' then
return false
end
if titleExistsCache[page] == nil then
local title = mw.title.new(page)
titleExistsCache[page] = title and title.exists or false
end
return titleExistsCache[page]
end
end


local function formatName(row)
local function formatName(row)
if trim(row.page) ~= '' then
local page = trim(row.page)
return string.format('[[%s|%s]]', row.page, row.name)
if page ~= '' and titleExists(page) then
return string.format('[[%s|%s]]', page, row.name)
end
end
return row.name
return row.name
Zeile 374: Zeile 473:
local out = {}
local out = {}
for _, code in ipairs(row.teams or {}) do
for _, code in ipairs(row.teams or {}) do
table.insert(out, '[[' .. code .. ']]')
if titleExists(code) then
table.insert(out, '[[' .. code .. ']]')
else
table.insert(out, code)
end
end
end
return table.concat(out, ' · ')
return table.concat(out, ' · ')