Module:Sports table/Water polo
Appearance
| This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome. |
This style for Lua-based Module:Sports table is meant to build group and league tables only for water polo competitions with a win-PSW-PSL-loss format and with the Tournament Performance Index instead of total points.
Usage
[edit]{{#invoke:Sports table/Water polo}}
Code example
[edit]|win_USA=2|psw_USA=3|psl_USA=4|loss_USA=5|gf_USA=6|ga_USA=7|tpi_USA=88.8
-- Style for water polo tables with TPI
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
local sort_text = yesno(Args['sortable_table'] or 'no') and ' sortable' or ''
table.insert(t,'{| class="wikitable'..sort_text..'" style="text-align:center;"\n') -- Open table
-- Table title
if Args['title'] or Args['table_header'] then
table.insert(t,'|+ ' .. (Args['title'] or Args['table_header']) .. '\n')
end
-- Pre stuff
local team_width = Args['teamwidth'] or '190'
-- Custom header options
local group_head_text = Args['group_header'] or '<abbr title="Group">Grp</abbr>'
local team_head_text = Args['team_header'] or 'Team'
-- Initialize
local tt = {}
tt.count = 0 -- Up by one after every call
tt.tab_text = t -- Actual text
-- Actual headers
if pos_label ~= nil then
tt = p_sub.colhead(tt,32,pos_label) -- Position col
end
-- Add group header
if full_table and group_col then
tt = p_sub.colhead(tt,32,group_head_text) -- Group col
end
tt = p_sub.colhead(tt,team_width,team_head_text..VTE_text) -- Mandatory cols
tt = p_sub.colhead(tt,32,'<abbr title="Played">Pld</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Wins">W</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Penalty shootouts wins">PSW</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Penalty shootouts losses">PSL</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Losses">L</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Goals for">GF</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Goals against">GA</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Goal difference">GD</abbr>')
tt = p_sub.colhead(tt,32,'<abbr title="Tournament Performance Index">TPI</abbr>')
table.insert(tt.tab_text,results_header_txt)
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 yesno = require('Module:Yesno')
-- Get some input
local defaultvalue = (Args['defaultvalue_'..team_code_ii])
local win = tonumber(Args['win_'..team_code_ii]) or 0
local psw = tonumber(Args['psw_'..team_code_ii]) or 0
local psl = tonumber(Args['psl_'..team_code_ii]) or 0
local loss = tonumber(Args['loss_'..team_code_ii]) or 0
local gf = tonumber(Args['gf_'..team_code_ii]) or 0
local ga = tonumber(Args['ga_'..team_code_ii]) or 0
local tpi = tonumber(Args['tpi_'..team_code_ii]) or 0
local hth_local = yesno(Args['show_hth'] or 'yes') and Args['hth_'..team_code_ii] or nil
if (win == 0 and psw == 0 and psl == 0 and loss == 0 and gf == 0 and ga == 0 and tpi == 0) then
local dv = (defaultvalue == '' or defaultvalue == nil) and 0 or defaultvalue
win, psw, psl, loss, gf, ga, tpi = dv, dv, dv, dv, dv, dv, dv
end
-- Then calculate some values
local matches = (defaultvalue and defaultvalue ~= '') and defaultvalue or (win + psw + psl + loss)
local gd = (defaultvalue and defaultvalue ~= '') and defaultvalue or (gf - ga)
if tonumber(gd) and tonumber(gd) < 0 then
gd = '−' .. -(tonumber(gd))
end
-- Some local vars
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)
notes_exist = tt_return.notes_exist
-- Row building
table.insert(t,'| style="'..bg_col..'" |'..matches..'\n')
table.insert(t,'| style="'..bg_col..'" |'..win..'\n')
table.insert(t,'| style="'..bg_col..'" |'..psw..'\n')
table.insert(t,'| style="'..bg_col..'" |'..psl..'\n')
table.insert(t,'| style="'..bg_col..'" |'..loss..'\n')
table.insert(t,'| style="'..bg_col..'" |'..gf..'\n')
table.insert(t,'| style="'..bg_col..'" |'..ga..'\n')
table.insert(t,'| style="'..bg_col..'" |'..gd..'\n')
table.insert(t,'| style="font-weight: bold;'..bg_col..'" |'..tpi..'\n')
return {t=t, notes_exist=notes_exist}
end
function pp.status(Args)
-- Declare status options
local status_code, status_called = {}, {}
status_code = { A='Advance to a further round', C='Champion', D='Disqualified',
E='Eliminated', G='Guest', H='Hosts', O='Play-off winner', P='Promoted', Q='Qualified to the phase indicated',
R='Relegated', T='Qualified, but not yet to the particular phase indicated'}
local status_letters = (Args['status_order'] or '') .. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-- Status position (before or after read and default)
local stat_pos_val = string.lower(Args['status_pos'] or '')
local status_position = 'after' -- Default location
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
status_called[l] = false
status_code[l] = status_code[l] or '?'
status_letters = mw.ustring.gsub(status_letters, '(' .. l ..'.-)' .. l, '%1')
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