توضیحات این پودمان میتواند در پودمان:Sports table/Chess/توضیحات قرار گیرد.
-- Style for chess tables
local pp = {}
function pp.header(t,Args,p_sub,pos_label,group_col,VTE_text,full_table,results_header_txt)
-- Load relevant modules
local yesno = require('Module:Yesno')
-- Create table header
-- Pre stuff
local player_width = Args['playerwidth'] or '190'
local sort_text = ''
local sort_table_val = Args['sortable_table'] or 'no'
if yesno(sort_table_val) then sort_text = 'sortable' end
table.insert(t,'{|class="wikitable '..sort_text..'" style="text-align:center;"\n') -- Open table
-- Preprocess match data
local top_pos = tonumber(Args['highest_pos']) or 1
local N_teams = top_pos - 1 -- Default to 0 at start, but higher number needed to skip certain entries
while Args['team'..N_teams+1] ~= nil do N_teams = N_teams+1 end
for ii=1,N_teams do
local ti = Args['team' .. ii]
Args['win_'..ti] = 0
Args['draw_'..ti] = 0
Args['loss_'..ti] = 0
for jj=1,N_teams do
local tj = Args['team' .. jj]
if ii ~= jj then
local wii = mw.ustring.gsub(Args['match_' .. ti .. '_' .. tj] or '', '^([^%+]*)%+([^%+]*)$', '%1')
local bii = mw.ustring.gsub(Args['match_' .. ti .. '_' .. tj] or '', '^([^%+]*)%+([^%+]*)$', '%2')
if wii ~= (Args['match_' .. ti .. '_' .. tj] or '') then
if wii == '1' then
Args['win_'..ti] = Args['win_'..ti] + 1
elseif wii == '½' then
Args['draw_'..ti] = Args['draw_'..ti] + 1
wii = '<span class="visualhide"> </span><sup>1</sup>⁄<sub>2</sub>'
elseif wii == '0' then
Args['loss_'..ti] = Args['loss_'..ti] + 1
end
if bii == '1' then
Args['win_'..ti] = Args['win_'..ti] + 1
elseif bii == '½' then
Args['draw_'..ti] = Args['draw_'..ti] + 1
bii = '<span class="visualhide"> </span><sup>1</sup>⁄<sub>2</sub>'
elseif bii == '0' then
Args['loss_'..ti] = Args['loss_'..ti] + 1
end
Args['match_' .. ti .. '_' .. tj] =
string.format(
'<div style="width:100%%;display:table;border:1px solid black;">' ..
'<div style="display:table-row">' ..
'<div style="background:white;color:black;display:table-cell;width:50%%;padding:2px;">%s</div>' ..
'<div style="background:black;color:white;display:table-cell;width:50%%;padding:2px;">%s</div>' ..
'</div></div>', wii, bii)
end
end
end
end
-- Custom header options
local group_head_text = Args['group_header'] or '<abbr title="Group">Grp</abbr>'
local player_head_text = Args['player_header'] or 'Player'
-- Initialize
local tt = {}
tt.count = 0 -- Up by one after every call
tt.tab_text = t -- Actual text
-- Actual headers
tt = p_sub.colhead(tt,28,pos_label) -- Position col
-- Add group header
if full_table and group_col then
tt = p_sub.colhead(tt,28,group_head_text) -- Group col
end
tt = p_sub.colhead(tt,player_width,player_head_text..VTE_text) -- Player col
tt = p_sub.colhead(tt,28, '<abbr title="Played">Pld</abbr>') -- Matches played col
tt = p_sub.colhead(tt,28, '<abbr title="Points">Pts</abbr>') -- Points col
tt = p_sub.colhead(tt,28, '<abbr title="Head-to-head">H2H</abbr>')
tt = p_sub.colhead(tt,28, 'Wins')
if full_table then
tt.count = tt.count+1
table.insert(tt.tab_text,results_header_txt)
end
return tt
end
function pp.row(frame,t,Args,p_sub,notes_exist,hth_id_list,full_table,rand_val,team_list,team_code_ii,ii_start,ii_end,ii_fw,bg_col,N_teams,ii,ii_show)
-- Build the inner parts of individual rows
-- Sub-module usage
local mm = require('Module:Math')
local yesno = require('Module:Yesno')
-- Get custom/default options for in table
local win_points = tonumber(Args['winpoints']) or 1
local draw_points = tonumber(Args['drawpoints']) or 0.5
local loss_points = tonumber(Args['losspoints']) or 0
-- Get some input
local wins = tonumber(Args['win_'..team_code_ii]) or 0
local draws = tonumber(Args['draw_'..team_code_ii]) or 0
local losses = tonumber(Args['loss_'..team_code_ii]) or 0
local hth_local = Args['hth_'..team_code_ii] or '0'
-- Then calculate some values
local matches = wins + draws + losses
local points = win_points*wins + draw_points*draws + loss_points*losses
hth_local = mw.ustring.gsub(hth_local, '%s*½', '.5')
if hth_local == '' then
hth_local = '—'
else
hth_local = tonumber(hth_local) or 0
if math.floor(hth_local) ~= hth_local then
if math.floor(hth_local) > 0 then
hth_local = math.floor(hth_local) .. '<span class="visualhide"> </span><sup>1</sup>⁄<sub>2</sub>'
else
hth_local = '<span class="visualhide"> </span><sup>1</sup>⁄<sub>2</sub>'
end
else
if hth_local <= 0 then
hth_local = '—'
end
end
end
if math.floor(points) ~= points then
if math.floor(points) > 0 then
points = math.floor(points) .. '<span class="visualhide"> </span><sup>1</sup>⁄<sub>2</sub>'
else
points = '<span class="visualhide"> </span><sup>1</sup>⁄<sub>2</sub>'
end
end
-- Some local vars
local hth_string
local tt_return = p_sub.hth(frame,Args,full_table,hth_id_list,nil,notes_exist,team_list,team_code_ii,ii_start,ii_end,rand_val)
hth_string = tt_return.str
hth_id_list = tt_return.list
notes_exist = tt_return.notes_exist
-- Row building
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..matches..'\n') -- Played
table.insert(t,'| style="'..ii_fw..bg_col..'" | '..points..'\n') -- Points
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..(hth_local or '')..'\n') -- Head-to-head
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..wins..'\n') -- Won
return {t=t, notes_exist=notes_exist, hth_id_list=hth_id_list}
end
function pp.status(Args)
-- Declare status options
-- ------------------------------------------------------------
-- NOTE: If you add to status_code, also add to status_called and status_letters!!
-- Or functionality will be compromised
-- ------------------------------------------------------------
local status_code, status_called = {}
status_code = { A='Advance to a further round', C='Champion', D='Disqualified',
E='Eliminated', G='Guest', H='Host', O='Play-off winner', P='Promoted', Q='Qualified to the phase indicated',
R='Relegated', T='Qualified, but not yet to the particular phase indicated',
X='?', Y='?', Z='?'}
status_called = { A=false, C=false, D=false, E=false, G=false, H=false, O=false, P=false,
Q=false, R=false, T=false, X=false, Y=false, Z=false}
local status_letters = 'ACDEGHOPQRTXYZ'
-- Status position (before or after read and default)
local stat_pos_val = Args['status_pos'] or ''
local status_position = 'after' -- Default location
stat_pos_val = string.lower(stat_pos_val)
if stat_pos_val=='before' then
status_position = 'before'
elseif stat_pos_val=='after' then
status_position = 'after'
end
-- Read in custom status options
for l in mw.text.gsplit(status_letters, '') do
if Args['status_text_' .. l] then
status_code[l] = Args['status_text_' .. l]
end
end
return {code=status_code, called=status_called, letters=status_letters, position=status_position}
end
return pp