Module:WDL/sandbox explained

require('strict')

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

local p =

local function total(won, drawn, lost) if not won and not drawn and not lost then return else return (won or 0) + (drawn or 0) + (lost or 0) endend

local function displayWinPercent(frame, winPercent, decimals) local retval = if winPercent < 10 then retval = '

00' elseif winPercent < 100 then retval = '0' end return retval .. frame:expandTemplateend

local function pct(frame, played, won, drawn, lost, decimals, winpctdraw) 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 played = (won or 0) + (drawn or 0) + (lost or 0) elseif tonumber(played) <= 0 then return '!—' end local wins = (won or 0) local draws = tonumber(drawn) or 0 local games = played if draws > 0 then if winpctdraw

'ignore'then -- treat ignored draws like the game was never played games = games - draws elseif winpctdraw

'loss' then -- don't have to do anything - this was the previous behavior else -- default to 'half' wins = wins + (draws / 2) end end return displayWinPercent(frame, 100 * wins / games, decimals)end

function p.main(frame, otherargs) local args = otherargs or getArgs(frame) local tableprefix = string.format('| style="%stext-align:%s" |', args.total and 'font-weight:bold;background:#efefef;' or , args.align or 'center') local played = total(args[2], args[3], args[4]) local retval = tableprefix .. frame:expandTemplate .. '\n' retval = retval .. tableprefix .. frame:expandTemplate .. '\n' retval = retval .. tableprefix .. frame:expandTemplate .. '\n' retval = retval .. tableprefix .. frame:expandTemplate .. '\n' if args['for'] then retval = retval .. tableprefix .. frame:expandTemplate .. '\n' end if args.against then retval = retval .. tableprefix .. frame:expandTemplate .. '\n' end if args.diff

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

!—\n' end end if args.winpctdraw then retval = retval .. tableprefix .. frame:expandTemplate .. '\n' end return retval .. tableprefix .. pct(frame, played, args[2], args[3], args[4], args.decimals, args.winpctdraw)end

return p