Module:Classements en fin de saison
Apparence
La documentation de ce module est générée par le modèle {{Documentation module}}.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}
local genreTab = {
W = 'WTA', F = 'WTA', D = 'WTA',
A = 'APT', M = 'APT', H = 'APT'
}
local increase = '<span data-sort-value="">[[Fichier:Increase2.svg|9px|en augmentation|link=]]</span>'
local decrease = '<span data-sort-value="">[[Fichier:Decrease2.svg|9px|en diminution|link=]]</span>'
local steady = '<span data-sort-value="">[[Fichier:Steady.svg|9px|en stagnation|link=]]</span>'
local norank = 10000
local function init()
local html = mw.html.create('table')
html:addClass('wikitable')
:addClass('classements-fin-saison')
:tag('caption')
:wikitext("Classements à l'issue de chaque saison")
return html
end
local function yearLine(list, genre)
local g = "l'ATP"
if genre == 'WTA' then
g = "la WTA"
end
local line = mw.html.create('tr')
line:tag('th')
:attr('scope', 'row')
:wikitext("Année")
for _, y in ipairs(list) do
line:tag('td')
:wikitext("'''[[Saison " .. y .. " de " .. g .. "|" .. y .."]]'''")
end
return line
end
local function rankLine(list, comp)
local line = mw.html.create('tr')
line:tag('th')
:attr('scope', 'row')
:wikitext("Rang en " .. comp)
local best, bestY = norank
for i, r in ipairs(list) do
if r < best then
best = r
bestY = i
end
end
for i, r in ipairs(list) do
local td = line:tag('td')
if i > 1 and r < norank and list[i-1] ~= norank then
if r < list[i-1] then
td:node(increase)
elseif r > list[i-1] then
td:node(decrease)
else
td:node(steady)
end
end
if i == bestY then
td:tag('b')
:wikitext(r)
elseif r == norank then
td:wikitext('–')
else
td:wikitext(r)
end
end
return line
end
local function split(text)
if type(text) ~= 'string' then
return {}
end
text = mw.text.trim(text):gsub("'", '')
local list = mw.text.split( text, '[%s,;:]+' )
for i=1, #list do
list[i] = tonumber(list[i]) or norank
end
return list
end
function p.rankTable(frame)
local args = frame.getParent and frame:getParent().args or frame
local genre = args.genre and mw.ustring.upper(args.genre)
genre = genreTab[mw.ustring.sub(genre, 1, 1)]
local years = split(args['année'])
local single = args.simple and split(args.simple)
local double = args.double and split(args.double)
local html = init()
:node(yearLine(years, genre))
if single then
html:node(rankLine(single, 'simple'))
end
if double then
html:node(rankLine(double, 'double'))
end
return tostring(html)
end
return p