请输入您要查询的百科知识:

 

词条 Module:WDL/sandbox
释义

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs

local roundAndPad = require('Module:Math')._precision_format

local p = {}

local function total(frame, played, won, drawn, lost, category)

if played == '-' or played == '—' then

return '—'

elseif not played then

if not won and not drawn and not lost then

return

end

return frame:expandTemplate{title = 'Number table sorting', args = { (won or 0) + (drawn or 0) + (lost or 0) }}

elseif tonumber(played) ~= (won or 0) + (drawn or 0) + (lost or 0) then

return 'error' .. (category or ) .. ''

else

return frame:expandTemplate{title = 'Number table sorting', args = { played }}

end

end

local function displayWinPercent(frame, winPercent, decimals)

local retval =

if winPercent < 10 then

retval = '0'

end

retval = retval .. frame:expandTemplate{title = 'Number table sorting', args = { roundAndPad(winPercent, decimals or 2) }}

if winPercent >= 100 then -- XXX: Should >= be ==? This should never be over 100, but that's what the original template had

return retval .. '0'

else

return retval

end

end

local function pct(frame, played, won, drawn, lost, decimals)

if played == '-' or played == '—' then

return '—'

elseif not played then

if not won and not drawn and not lost then

return

elseif (won or 0) + (drawn or 0) + (lost or 0) <= 0 then

return '!—'

end

return displayWinPercent(frame, 100 * (won or 1) / ((won or 1) + (drawn or 0) + (lost or 0)), decimals) -- XXX: Why is 1 used in the numerator instead of 0 if won isn't set? It's not like that in the case where played is set. It makes sense in the denominator to avoid a divide by zero

elseif tonumber(played) <= 0 then

return '!—'

else

return displayWinPercent(frame, 100 * (won or 0) / played, decimals)

end

end

function p.main(frame)

local args = getArgs(frame)

local tableprefix = string.format('| style="%stext-align:%s" |', args.total and 'font-weight:bold;background:#efefef;' or , args.align or 'center')

local retval = tableprefix .. total(frame, args[1], args[2], args[3], args[4], args.demospace and or ) .. '\'

retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args[2] }} .. '\'

retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args[3] }} .. '\'

retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args[4] }} .. '\'

if args['for'] then

retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args['for'] }} .. '\'

end

if args.against then

retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args.against }} .. '\'

end

if args.diff == 'yes' then

if tonumber(args['for']) and tonumber(args.against) then

retval = retval .. tableprefix .. string.format('%s%d\', args['for'] < args.against and '−' or '+', math.abs(args['for'] - args.against))

else

retval = retval .. tableprefix .. '!—\'

end

end

return retval .. tableprefix .. pct(frame, args[1], args[2], args[3], args[4], args.decimals)

end

return p

1 : WDL error

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/21 13:54:26