-- Module to build results cross-tables for standings in Chess-- See documentation for details
require('strict')
local p =
-- Other functionslocal function get_short_name(s, t, n, ss) -- return short name if defined if s and s ~= then return s end -- deflag if necessary if ss and n then if ss
'nocountry' then n = mw.ustring.gsub(n, '%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%]', ) n = mw.ustring.gsub(n, '
[^<>]', ) if ssfunction p.header(tt,Args,p_sub,N_teams,team_list,legs,prefix) local ii, team_code_ii, short_name prefix = prefix or legs = tonumber(Args[prefix .. 'legs']) or 1
-- Set match column width local col_width = Args['match_col_width'] or '28'
-- Determine if default short style is position for short name local yesno = require('Module:Yesno') local pos_short = yesno(Args['use_pos_short'] or 'no')
if N_teams>2 then -- Set the column span col_width = col_width .. ' colspan=' .. legs .. ' style="border-left:2px solid #aaa;"' -- Get some default values in case it doesn't start at 1 local top_pos = tonumber(Args['highest_pos']) or 1 for ii=top_pos,N_teams do team_code_ii = team_list[ii] short_name = get_short_name(Args['short_'..team_code_ii], pos_short and ii or team_code_ii, Args['name_'..team_code_ii], Args['short_style'] or ) tt = p_sub.colhead(tt,col_width,short_name) if legs > 1 then tt.count = tt.count + legs - 1 end end else for ii=1,legs do local game_header = Args[prefix..'game'..ii..'_header'] or ii tt = p_sub.colhead(tt,col_width,game_header) end end local tb_numplayers = tonumber(Args['tb_numplayers']) or 0 if prefix
function p.row(tt,Args,N_teams,team_list,ii,ii_show,legs,prefix) -- Note ii is the row number being shown local jj, fw, bg, result, bg_col, team_code_jj prefix = prefix or legs = tonumber(Args[prefix .. 'legs']) or 1 local team_code_ii = team_list[ii]
-- Determine if backgrounds will be colored local yesno = require('Module:Yesno') local colorbg = yesno(Args['colorbg'] or 'yes')
-- Get some default values in case it doesn't start at 1 local top_pos = tonumber(Args['highest_pos']) or 1
local bgcolrow_str = Args[prefix .. 'bgcolrow_' .. team_code_ii] or if bgcolrow_str ~= then for pp=1,(top_pos-1) do bgcolrow_str = mw.ustring.gsub(bgcolrow_str, '^([^,]*),?', ) or -- Trim bgcol data prior to top_pos end end for jj=top_pos,N_teams do local bl = 'border-left:2px solid #aaa;' if ii
ii_show and 'bold' or 'normal') .. ';' bg = 'background:transparent;'
-- Background color for solid cell local solid_cell = Args['solid_cell'] or if solid_cell ~= 'gray' and solid_cell ~= 'grey' and solid_cell ~= 'lightgray' and solid_cell ~= 'lightgrey' and solid_cell ~= 'silver' then solid_cell = mw.ustring.match(solid_cell,'^#%x%x%x+') or end if solid_cell ~= then table.insert(tt,'| colspan ="'..legs..'" style="'..fw..bl..'background:'..solid_cell..';" |\n') else table.insert(tt,'| colspan ="'..legs..'" style="'..fw..bl..bg..'" | - \n') end elseif ii ~= jj then -- Content cells team_code_jj = team_list[jj] if bgcolrow_str ~= then Args[prefix .. 'bgcol_' .. team_code_ii..'_'..team_code_jj] = mw.ustring.match(bgcolrow_str, '^([^,]*),?') end local bgcol_str = Args[prefix .. 'bgcol_'..team_code_ii..'_'..team_code_jj] or for l=1,legs do -- Get match data local m = (legs
-- Set bolding and background fw = 'font-weight:' .. ((ii
ii_show) and 'bold' or 'normal') .. ';' if l > 1 or N_teams<=2 then bl = end bg = 'background:transparent;'
-- Background coloring if colorbg then local bg_col = mw.ustring.match(bgcol_str, '^([^%+]*)%+?') or bgcol_str = mw.ustring.gsub(bgcol_str, '^([^%+]*)%+?', ) or -- Remove bg_col from bgcol_str bg_col = mw.ustring.gsub(bg_col,'^%s*',) -- Trim starting whitespace bg_col = mw.ustring.gsub(bg_col,'%s*$',) -- Trim ending whitespace if bg_col
0 and 'B') or 'W' else bg_col = mw.ustring.upper(bg_col) end if bg_col
local tb_numplayers = tonumber(Args['tb_numplayers']) or 0 if prefix
2) and legs or (tb_numplayers * legs) for gg=1,numtbgames do table.insert(tt,'| style="background-color:white;border-left:white;border-top:white;border-bottom:white;border-right:white;"| \n') end end end return ttend
return p