Модуль:Fb overview
Көрүнүш
{{fb overview}} калыбын иштетет
local p = {}
local trackingcat = 'Категория:Спорттун жалпы калыбын белгисиз параметрлер менен колдонулган макалалар'
local labels = {
competition = 'Мелдеш',
firstmatch = 'Биринчи оюн',
lastmatch = 'Акыркы оюн',
startinground = 'Баштапкы раунд',
finalposition = 'Жыйынтык орун',
record = 'Статистика',
total = 'Жалпысы',
source = 'Булак: ',
lastupdated = 'Жаңыртылган күнү: ',
sourcedefault = '[[#Мелдештер|Мелдештер]]',
unknownparameter = 'Белгисиз параметр: ',
pld = '<abbr title="Оюндар саны">Оюн</abbr>',
w = '<abbr title="Жеңиш">Жңш</abbr>',
d = '<abbr title="Тең">Тең</abbr>',
l = '<abbr title="Жеңилүү">Жңл</abbr>',
pf = '<abbr title="Упай топтолду">УТ</abbr>',
pa = '<abbr title="Упай өткөрүлдү">УӨ</abbr>',
pd = '<abbr title="Упай айырмасы">УА</abbr>',
gf = '<abbr title="Гол киргизилген">ГК</abbr>',
ga = '<abbr title="Гол өткөрүлгөн">ГӨ</abbr>',
gd = '<abbr title="Гол айырмасы">ГА</abbr>',
wp = '<abbr title="Жеңиш пайызы">Ж %</abbr>',
winner = 'Жеңүүчү',
champion = 'Чемпион',
runnerup = 'Финалист',
runnersup = 'Финалисттер'
}
local function signnum(n)
n = tonumber(n) or 0
if n > 0 then return '+' .. tostring(n) end
return tostring(n)
end
local function percentStr(w, pld)
pld = tonumber(pld) or 0
w = tonumber(w) or 0
if pld <= 0 then return '0' end
local pct = math.floor((w / pld) * 100 + 0.5)
if pct > 0 then return tostring(pct) .. '%' end
return tostring(pct)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
local rownumbers = {}
local unknown = {}
local showdates, showrounds, showpos = false, false, false
local maxrow = -1
local rowlimit = 99
local function addrownumber(num)
if not num then return end
num = tonumber(num)
if not num or num < 1 or num > rowlimit then return end
table.insert(rownumbers, num)
if num > maxrow then maxrow = num end
end
for k, v in pairs(args) do
local key = tostring(k)
local n = tonumber(key:match('^[a-z]+(%d+)$') or '')
if key == 'u' or key == 'c' or key == 's' or key == 'pts' or key == 'tot' then
elseif key:match('^[cwdlfa]%d+$') then
addrownumber(n)
elseif key:match('[dfl]m%d+$') then
showdates = true; addrownumber(n)
elseif key:match('sr%d+$') then
showrounds = true; addrownumber(n)
elseif key:match('fp%d+$') then
showpos = true; addrownumber(n)
else
table.insert(unknown, key)
end
end
local cparam = tonumber(args.c) or 0
if cparam > 0 then
rownumbers = {}
for i = 1, cparam do table.insert(rownumbers, i) end
end
if rownumbers then
table.sort(rownumbers)
for i = #rownumbers, 2, -1 do
if rownumbers[i] == rownumbers[i-1] then table.remove(rownumbers, i) end
end
end
if not rownumbers or #rownumbers == 0 then
if #unknown > 0 then
local unknown_params = require('Module:If preview')._warning(
labels.unknownparameter .. '<code>' .. table.concat(unknown, '</code>, <code>') .. '</code>.'
) .. '[[' .. trackingcat .. '|' .. (unknown[1] or '') .. ' ]]'
return unknown_params
end
return ''
end
local out = {}
table.insert(out, '{| class="wikitable" style="text-align:center"')
local totspan = 1
table.insert(out, '|-')
local header1 = '! rowspan=2 | ' .. labels.competition
if showdates then
header1 = header1 .. '\n! rowspan=2 | ' .. labels.firstmatch
header1 = header1 .. '\n! rowspan=2 | ' .. labels.lastmatch
totspan = totspan + 2
end
if showrounds then
header1 = header1 .. '\n! rowspan=2 | ' .. labels.startinground
totspan = totspan + 1
end
if showpos then
header1 = header1 .. '\n! rowspan=2 | ' .. labels.finalposition
totspan = totspan + 1
end
header1 = header1 .. '\n! colspan=8 | ' .. labels.record
table.insert(out, header1)
table.insert(out, '|-')
for _, token in ipairs({'! ' .. labels.pld, '! ' .. labels.w, '! ' .. labels.d, '! ' .. labels.l, '! ' .. labels.gf, '! ' .. labels.ga, '! ' .. labels.gd, '! ' .. labels.wp}) do
table.insert(out, token)
end
local wtot, dtot, ltot, ftot, atot = 0, 0, 0, 0, 0
for _, r in ipairs(rownumbers) do
table.insert(out, '|-')
table.insert(out, '| ' .. (args['c' .. r] or ''))
if showdates then
if args['dm' .. r] then
table.insert(out, '| colspan=2 | ' .. args['dm' .. r])
else
table.insert(out, '| ' .. (args['fm' .. r] or ''))
table.insert(out, '| ' .. (args['lm' .. r] or ''))
end
end
if showrounds then
table.insert(out, '| ' .. (args['sr' .. r] or ''))
end
if showpos then
local fp = args['fp' .. r] or ''
local bg = nil
if fp:match('^' .. labels.winner) or fp:match('^' .. labels.champion) then bg = 'gold'
elseif fp:match('^' .. labels.runnersup) or fp:match('^' .. labels.runnerup) then bg = 'silver' end
if bg then
table.insert(out, '| style="background-color:' .. bg .. '" | ' .. fp)
else
table.insert(out, '| ' .. fp)
end
end
local w = tonumber(args['w' .. r]) or 0
local d = tonumber(args['d' .. r]) or 0
local l = tonumber(args['l' .. r]) or 0
local f = tonumber(args['f' .. r]) or 0
local a = tonumber(args['a' .. r]) or 0
local pld = w + d + l
local gd = f - a
local wp = percentStr(w, pld)
table.insert(out, '| ' .. tostring(pld))
table.insert(out, '| ' .. tostring(w))
table.insert(out, '| ' .. tostring(d))
table.insert(out, '| ' .. tostring(l))
table.insert(out, '| ' .. tostring(f))
table.insert(out, '| ' .. tostring(a))
table.insert(out, '| ' .. signnum(gd))
table.insert(out, '| ' .. wp)
wtot = wtot + w
dtot = dtot + d
ltot = ltot + l
ftot = ftot + f
atot = atot + a
end
table.insert(out, '|- style="background:#f2f2f2; font-weight:bold;"')
if totspan > 1 then
table.insert(out, '! colspan=' .. totspan .. ' | ' .. labels.total)
else
table.insert(out, '! ' .. labels.total)
end
local total_pld = wtot + dtot + ltot
table.insert(out, '| ' .. tostring(total_pld))
table.insert(out, '| ' .. tostring(wtot))
table.insert(out, '| ' .. tostring(dtot))
table.insert(out, '| ' .. tostring(ltot))
table.insert(out, '| ' .. tostring(ftot))
table.insert(out, '| ' .. tostring(atot))
table.insert(out, '| ' .. signnum(ftot - atot))
table.insert(out, '| ' .. percentStr(wtot, total_pld))
table.insert(out, '|}')
if args.u or args.s then
table.insert(out, '<div style="font-size:90%; margin-top:0.3em">')
if args.u then table.insert(out, labels.lastupdated .. args.u .. '<br>') end
table.insert(out, labels.source .. (args.s or labels.sourcedefault))
table.insert(out, '</div>')
end
if #unknown > 0 then
local unknown_params = require('Module:If preview')._warning(
labels.unknownparameter .. '<code>' .. table.concat(unknown, '</code>, <code>') .. '</code>.'
) .. '[[' .. trackingcat .. '|' .. (unknown[1] or '') .. ' ]]'
table.insert(out, unknown_params)
end
return table.concat(out, '\n')
end
return p