Jump to content

Module:Sports table/Chess

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 13:45, 17 March 2018 (created by copying Module:Sports table/WDL and then modifying for Chess per Module talk:Sports table ... will require some work to make the final product). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)


Cite error: There are <ref group=lower-alpha> tags or {{efn}} templates on this page, but the references will not show without a {{reflist|group=lower-alpha}} template or {{notelist}} template (see the help page).

-- 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
	
	-- 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 .. ' colspan=2',pos_label)										-- Position col
	-- Add group header
	if full_table and group_col then
		tt = p_sub.colhead(tt,28 .. ' colspan=2',group_head_text)			-- Group col
	end
	tt = p_sub.colhead(tt,player_width .. ' colspan=2',player_head_text..VTE_text)				-- Player col
	tt = p_sub.colhead(tt,28 .. ' colspan=2','<abbr title="Played">Pld</abbr>')				-- Matches played col
	tt = p_sub.colhead(tt,28 .. ' colspan=2','<abbr title="Points">Pts</abbr>\n! scope=col rowspan=2 | Tie breaks')					-- 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 nil
	-- Then calculate some values
	local matches = wins + draws + losses
	local points = win_points*wins + draw_points*draws + loss_points*losses
	
	if math.floor(points) ~= points then
		points = math.floor(points) .. '<span class="visualhide">&nbsp;</span><sup>1</sup>&frasl;<sub>2</sub>'
	end
	
	-- Some local vars	
	local hth_string
	local tt_return = p_sub.hth(frame,Args,full_table,hth_id_list,hth_local,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="font-weight: bold;'..bg_col..'" | '..points..hth_string..'\n') -- Points

	table.insert(t,'| style="'..win_fw..bg_col..'" |'..(hth_local or '')..'\n')	-- Head-to-head
	table.insert(t,'| style="'..win_fw..bg_col..'" |'..wins..win_string..'\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