Module:Sports table/Rugby
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This style for Lua-based Module:Sports table is meant to build group and league tables for rugby competitions with the following optional columns
- Played / Wins / Draws / Losses
- Match points for / Match points against / Match points difference
- Tries for / Tries against
- Try bonus competition points
- Loss bonus competition points
- Total competition points
The input syntax for this module is similar to the WDL module, but specialized for Rugby competitions.
Usage
Basic usage
In its simplest form only several parameters need to be used to build a table
What you type | {{#invoke:sports table|main|style=Rugby
<!-- Add team codes and names here -->
| team1 = AAA | name_AAA = Team AAA
| team2 = BBB | name_BBB = Team BBB
| team3 = CCC | name_CCC = Team CCC
| team4 = DDD | name_DDD = Team DDD
| team5 = EEE | name_EEE = Team EEE
| team6 = FFF | name_FFF = Team FFF
| team7 = GGG | name_GGG = Team GGG
| team8 = HHH | name_HHH = Team HHH
<!-- Update results here and then (if needed) positions below. Don't forget to update the date below (update parameter) -->
| win_AAA=0 | draw_AAA=0 | loss_AAA=0 | pf_AAA=0 | pa_AAA=0 | tf_AAA=0 | ta_AAA=0 | tb_AAA=0 | lb_AAA=0 | status_AAA=CQ
| win_BBB=0 | draw_BBB=0 | loss_BBB=0 | pf_BBB=0 | pa_BBB=0 | tf_BBB=0 | ta_BBB=0 | tb_BBB=0 | lb_BBB=0 | status_BBB=Q
| win_CCC=0 | draw_CCC=0 | loss_CCC=0 | pf_CCC=0 | pa_CCC=0 | tf_CCC=0 | ta_CCC=0 | tb_CCC=0 | lb_CCC=0 | status_CCC=A
| win_DDD=0 | draw_DDD=0 | loss_DDD=0 | pf_DDD=0 | pa_DDD=0 | tf_DDD=0 | ta_DDD=0 | tb_DDD=0 | lb_DDD=0 | status_DDD=T
| win_EEE=0 | draw_EEE=0 | loss_EEE=0 | pf_EEE=0 | pa_EEE=0 | tf_EEE=0 | ta_EEE=0 | tb_EEE=0 | lb_EEE=0 | status_EEE=
| win_FFF=0 | draw_FFF=0 | loss_FFF=0 | pf_FFF=0 | pa_FFF=0 | tf_FFF=0 | ta_FFF=0 | tb_FFF=0 | lb_FFF=0 | status_FFF=
| win_GGG=0 | draw_GGG=0 | loss_GGG=0 | pf_GGG=0 | pa_GGG=0 | tf_GGG=0 | ta_GGG=0 | tb_GGG=0 | lb_GGG=0 | status_GGG=R
| win_HHH=0 | draw_HHH=0 | loss_HHH=0 | pf_HHH=0 | pa_HHH=0 | tf_HHH=0 | ta_HHH=0 | tb_HHH=0 | lb_HHH=0 | status_HHH=R
<!-- Update team positions here -->
| team_order = AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
<!--Update team qualifications here (defined below)-->
| result1=C | result2=C | result3=C | result4=C | result7=R | result8=R
<!-- Add promotion, qualification and/or relegation row colours and column definitions. Use green for top tournament, then blue followed by yellow; red is elimination. Different levels of same competitions should have different shades in color like green1, green2 and so on. -->
| res_col_header = QR <!-- All of these may not be needed, Promotion (P), Qualification (Q) and Relegation (R) -->
| col_C = green2 | text_C = Continental Championship
| col_R = red2 | text_R = Division 2
| start_date = Unknown <!-- Add start date. When tournament starts, remove start_date -->
| update = future <!-- When tournament starts, update the with date of latest update -->
| source = Unknown <!-- Add source for table here with single bracket, e.g. [URL info] -->
| class_rules = 1) competition points; 2) match points difference; 3) match points for <!-- Add classification rules here -->
}}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
What it looks like |
First match(es) will be played: Unknown. Source: example.com
Rules for classification: 1) competition points; 2) match points difference; 3) match points for (A) Advances to a further round; (C) Champion; (Q) Qualified for the phase indicated; (R) Relegated; (T) Qualified, but not yet for the particular phase indicated |
Additional parameters
- To merge the "bonus competition points" columns into one, use
|bonus_total=
with any additional bonus points specified using|b_XYZ=
- To hide the "bonus competition points" columns, use
|show_bonus=no
- To hide the "draws" column, use
|show_draw=no
- To hide the "tries for" column, use
|show_tries_for=no
- To hide the "tries against" column, use
|show_tries_against=no
- To show the "tries difference" column, use
|show_tries_difference=yes
- To hide the "points for" column, use
|show_points_for=no
- To hide the "points against" column, use
|show_points_against=no
- To hide the "points difference" column, use
|show_points_difference=no
- To add "competition points carried forward" to the next round, use
|show_cf=yes
- To add "grand slam points" column, use
|show_grand_slam=yes
, with grand slam points specified using|gs_XYZ=
- To override the default number of "win points", use
|winpoints=
- To override the default number of "draw points", use
|drawpoints=
- To override the default number of "loss points", use
|losspoints=
-- Style for rugby union 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 team_width = Args['teamwidth'] or '170'
local sort_text = yesno(Args['sortable_table'] or 'no') and 'sortable' or ''
local show_played = yesno(Args['hide_played'] or 'no') and false or true
local show_draw = yesno(Args['show_draw'] or 'yes')
local show_tries = yesno(Args['show_tries'] or 'yes')
local show_bonus = yesno(Args['show_bonus'] or 'yes')
local ranking_style = string.lower(Args['ranking_style'] or 'pts')
local show_points = true
if ranking_style=='w' or ranking_style=='win' or ranking_style=='wins' or ranking_style=='none' then
show_points = false
end
-- Custom header
local group_head_text = Args['group_header'] or '<abbr title="Group">Grp</abbr>'
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
-- 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,28,pos_label) -- Position col
end
-- 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,team_width,'Team'..VTE_text) -- Team col
if show_played then
tt = p_sub.colhead(tt,28,'<abbr title="Played">Pld</abbr>') -- Matches played col
end
if full_table then
tt = p_sub.colhead(tt,28,'<abbr title="Won">W</abbr>') -- Win col
if show_draw then
tt = p_sub.colhead(tt,28,'<abbr title="Drawn">D</abbr>') -- Draw col
end
tt = p_sub.colhead(tt,28,'<abbr title="Lost">L</abbr>') -- Loss col
tt = p_sub.colhead(tt,28,'<abbr title="Points for">PF</abbr>') -- For col
tt = p_sub.colhead(tt,28,'<abbr title="Points against">PA</abbr>') -- Against col
tt = p_sub.colhead(tt,28,'<abbr title="Points difference">PD</abbr>') -- Difference col
if show_tries then
tt = p_sub.colhead(tt,28,'<abbr title="Tries for">TF</abbr>') -- Tries for col
tt = p_sub.colhead(tt,28,'<abbr title="Tries against">TA</abbr>') -- Tries against col
end
if show_bonus then
tt = p_sub.colhead(tt,28,'<abbr title="Try bonus points">TBP</abbr>') -- Try bonus col
tt = p_sub.colhead(tt,28,'<abbr title="Losing bonus points">LBP</abbr>') -- Losing bonus col
end
if show_points then
tt = p_sub.colhead(tt,32,'<abbr title="Total points">Pts</abbr>') -- Points col
end
tt.count = tt.count+1
table.insert(tt.tab_text,results_header_txt)
end
return tt
end
-- Numeric alignment
local function num_align(num, digits)
if tonumber(digits) and tonumber(num) then
local n = tonumber(num)
digits = tonumber(digits)
if digits == 1 then
if n >= 0 and n < 10 then
return '<span style="visibility:hidden;color:transparent;">0</span>' .. num
end
elseif digits == 2 then
if n >= 0 and n < 10 then
return '<span style="visibility:hidden;color:transparent;">00</span>' .. num
elseif n >= 10 and n < 100 then
return '<span style="visibility:hidden;color:transparent;">0</span>' .. num
end
end
end
return num
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 some input
local show_played = yesno(Args['hide_played'] or 'no') and false or true
local show_played = yesno(Args['hide_played'] or 'no') and false or true
local show_draw = yesno(Args['show_draw'] or 'yes')
local show_tries = yesno(Args['show_tries'] or 'yes')
local show_bonus = yesno(Args['show_bonus'] or 'yes')
local win_points = tonumber(Args['winpoints']) or (show_draw and 4 or 3)
local draw_points = tonumber(Args['drawpoints']) or (show_draw and 2 or 0)
local loss_points = tonumber(Args['losspoints']) or (show_draw and 0 or 0)
local ranking_style = string.lower(Args['ranking_style'] or 'pts')
local show_points = true
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 pfor = tonumber(Args['pf_'..team_code_ii]) or 0
local paig = tonumber(Args['pa_'..team_code_ii]) or 0
local tf = tonumber(Args['tf_'..team_code_ii]) or 0
local ta = tonumber(Args['ta_'..team_code_ii]) or 0
local tbp = tonumber(Args['tbp_'..team_code_ii]) or 0
local lbp = tonumber(Args['lbp_'..team_code_ii]) or 0
local s_pts = (tonumber(Args['adjust_points_'..team_code_ii]) or 0) + (tonumber(Args['startpoints_'..team_code_ii]) or 0)
local hth_local = Args['hth_'..team_code_ii] or nil
local digits = Args['digitpad']
-- Then calculate some values
local matches = wins + draws + losses
local points = win_points*wins + draw_points*draws + loss_points*losses + tbp + lbp + s_pts
local pcomp = 0
if (pfor == '?') or (paig == '?') then
pcomp = '—'
else
pcomp = pfor - paig
-- Formatting with signs
if pcomp>0 then
pcomp='+'..num_align(pcomp,digits)
elseif pcomp < 0 then
pcomp='−'..-num_align(pcomp,digits)
end
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
-- What to rank the teams by
local win_fw, win_string, pts_fw, pts_string
if ranking_style=='w' or ranking_style=='win' or ranking_style=='wins' then
-- Based on wins
win_fw = 'font-weight: bold;'
win_string = hth_string
pts_fw=ii_fw
pts_string = ''
show_points = false
elseif ranking_style=='none' then
win_fw=ii_fw
win_string = ''
pts_fw=ii_fw
pts_string = ''
show_points = false
else
win_fw=ii_fw
win_string = ''
pts_fw= 'font-weight:bold;'
pts_string = ''
show_points = true
end
-- Now that we are done calculating, show actual input values
if tonumber(Args['win_'..team_code_ii] or 0) == nil then
wins = '—'
end
if tonumber(Args['loss_'..team_code_ii] or 0) == nil then
losses = '—'
end
local function numorval(s)
return s and ((s == '' and 0) or tonumber(s) or s) or 0
end
-- Row building
if show_played then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..matches..'\n') -- Played
end
if full_table then
table.insert(t,'| style="'..win_fw..bg_col..'" |'..wins..win_string..'\n') -- Won
if show_draw then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..draws..'\n') -- Drawn
end
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') -- Lost
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..pfor..'\n') -- PF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..paig..'\n') -- PA
if show_points then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..pcomp..'\n') -- PD
else
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..pcomp..hth_string..'\n') -- PD
end
if show_tries then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..tf..'\n') -- TF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..ta..'\n') -- TA
end
if show_bonus then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..tbp..'\n') -- TB
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..lbp..'\n') -- LB
end
if show_points then
-- Add − for negative point totals
if points<0 then
table.insert(t,'| style="'..pts_fw..bg_col..'" | −'..num_align(-points,digits)..hth_string..'\n')
else
table.insert(t,'| style="'..pts_fw..bg_col..'" | '..num_align(points,digits)..hth_string..'\n')
end
end
end
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='Advances to a further round', C='Champion', D='Disqualified',
E='Eliminated', H='Host', O='Play-off winner', P='Promoted', Q='Qualified for the phase indicated',
R='Relegated', T='Qualified, but not yet for 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