Content deleted Content added
No edit summary |
No edit summary Tags: Mobile edit Mobile web edit |
||
(21 intermediate revisions by 5 users not shown) | |||
Line 2:
local pp = { }
local function args_points(Args)
local pts = {}
-- Do not change these defaults without first checking which tables use them
pts.win = tonumber(Args['winpoints']) or 2
pts.tie = tonumber(Args['tiepoints']) or 1
pts.nr = tonumber(Args['nrpoints']) or 1
pts.draw = tonumber(Args['drawpoints']) or 1
pts.bonus = tonumber(Args['bonuspoints']) or 1
pts.loss = tonumber(Args['losspoints']) or 0
return pts
end
local function abbr_header(txt, abbr, show_header_pts, pts)
if show_header_pts then
txt = txt .. ' – ' .. pts .. (pts == 1 and ' point' or ' points')
end
return '<abbr title="' .. txt .. '">' .. abbr .. '</abbr>'
end
function pp.header(t, Args, p_sub, pos_label, group_col, VTE_text, full_table, results_header_txt)
Line 12 ⟶ 33:
local team_width = Args['teamwidth'] or '180'
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
Line 22 ⟶ 42:
--Header specific options
local
local pts = args_points(Args)
local team_head_text = Args['team_header'] or 'Team'
local draw_head_text = Args['draw_header'] or abbr_header('Drawn', 'D', show_pts, pts.draw)
local tie_head_text = Args['tie_header'] or abbr_header('Tied', 'T', show_pts, pts.tie)
local nr_head_text = Args['nr_header'] or abbr_header('No result', 'NR', show_pts, pts.nr)
local bonus_head_text = Args['bonus_header'] or '<abbr title="Bonus points">BP</abbr>'
local deduct_head_text = Args['deduct_header'] or '<abbr title="Deductions">Ded</abbr>'
local nrr_head_text = Args['nrr_header'] or '<abbr title="Net run rate">[[Net run rate|NRR]]</abbr>'
--
local loss_first = yesno(Args['loss_before_tie'] or 'yes')
local
local show_tie = yesno(Args['show_tie'] or 'yes')
local show_nr = yesno(Args['show_nr'] or 'yes')
local show_deduct = yesno(Args['show_deductions'] or 'no')
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local show_nrr = yesno(Args['show_nrr'] or 'yes')
local show_nrr_fa = yesno(Args['show_nrr_fa'] or 'no') and show_nrr
-- Initialize
Line 49 ⟶ 73:
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_head_text..VTE_text) -- Team col
Line 56 ⟶ 85:
if full_table then
tt = p_sub.colhead(tt,28,abbr_header('
local loss_head_text = abbr_header('Lost', 'L', show_pts, pts.loss)
if loss_first then
tt = p_sub.colhead(tt,28,
if show_tie then
Line 69 ⟶ 99:
end
tt = p_sub.colhead(tt, 28,
end
if show_nr then
tt = p_sub.colhead(tt,28,nr_head_text) -- No result col
end
if show_bonus_points then
tt = p_sub.colhead(tt,28,bonus_head_text) -- Bonus points col
end
if show_deduct then
tt = p_sub.colhead(tt,28,deduct_head_text) -- Deduction col
end
end
Line 81 ⟶ 117:
if show_nrr then
tt = p_sub.colhead(tt,28,nrr_head_text) -- NRR col
end
if show_nrr_fa then
tt = p_sub.colhead(tt, 60, 'For')
tt = p_sub.colhead(tt, 60, 'Against')
end
tt.count = tt.count+1
Line 87 ⟶ 127:
return tt
end
local function rr_to_dec(runs, overs, balls_per_over)
if overs == 0 then
return 0
end
local balls = overs % 1
return runs / (overs - balls + balls * 10 / balls_per_over)
end
Line 96 ⟶ 145:
local mm = require('Module:Math')
local yesno = require('Module:Yesno')
-- table options, to match those in the header
local loss_first = yesno(Args['loss_before_tie'] or 'yes')
local show_tie = yesno(Args['show_tie'] or 'yes')
local show_nr = yesno(Args['show_nr'] or 'yes')
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local show_deduct = yesno(Args['show_deductions'] or 'no')
local show_nrr = yesno(Args['show_nrr'] or 'yes')
local show_nrr_fa = yesno(Args['show_nrr_fa'] or 'no') and show_nrr
-- Get some input
local wins = tonumber(Args['win_'..team_code_ii]) or 0
local ties = tonumber(Args['tie_'..team_code_ii]) or 0
local losses = tonumber(Args['loss_'..team_code_ii]) or 0
local noresults = tonumber(Args['nr_'..team_code_ii]) or 0
local bonuses = tonumber(Args['bonus_'..team_code_ii]) or 0
local deductions = tonumber(Args['ded_'..team_code_ii]) or 0
local nrr = tonumber(Args['nrr_'..team_code_ii]) or nil
local oversbowled = tonumber(Args['ob_'..team_code_ii])
local runsconceded = tonumber(Args['rc_'..team_code_ii])
local
local runsscored = tonumber(Args['rs_'..team_code_ii])
local balls_per_over = tonumber(Args['balls_per_over']) or 6
local hth_local = Args['hth_'..team_code_ii]
-- Then calculate some values
local matches = wins + losses + ties + noresults
local
local s_bps = pts.bonus*bonuses
local points = pts.win*wins + pts.loss*losses + pts.tie*ties + pts.nr*noresults + s_bps - deductions
-- Some local vars
Line 161 ⟶ 209:
end
local nrr_for = rr_to_dec(runsscored, oversfaced, balls_per_over)
local nrr_against = rr_to_dec(runsconceded, oversbowled, balls_per_over)
-- Set Net Run Rate. This is probabaly over-engineered and could just be done with a single precalculated value
if nrr ~= nil then
nrr = mm._precision_format(nrr, 3)
elseif (oversbowled == 0) or (oversfaced == 0) then -- if 0 or null then have mdash rather than 0?
nrr = '—'
else
nrr = mm._precision_format(
end
Line 173 ⟶ 225:
if full_table then
-- Use actual values if wins,
if (wins == 0 and
local function numorval(s)
return s and((s == '' and 0) or tonumber(s) or s) or 0
end
wins = numorval(Args['win_'..team_code_ii])
losses = numorval(Args['loss_'..team_code_ii])
end
Line 195 ⟶ 247:
end
if show_nr then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..
end
if show_bonus_points then
Line 203 ⟶ 255:
table.insert(t,'| style="'..bg_col..'" | '..s_bps..'\n')
end
if show_deduct then
table.insert(t,'| style="'..ii_fw..bg_col..'" | '..deductions..'\n')
end
end
if points<0 then
Line 213 ⟶ 268:
if show_nrr then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..nrr..'\n') -- Net run rate
end
if show_nrr_fa then
local nrr_for_text = oversfaced > 0 and runsscored..'/'..oversfaced or '—'
local nrr_against_text = oversbowled > 0 and runsconceded..'/'..oversbowled or '—'
table.insert(t, '| data-sort-value="'..nrr_for..'" style="'..ii_fw..bg_col..'" |'..nrr_for_text..'\n')
table.insert(t, '| data-sort-value="'..nrr_against..'" style="'..ii_fw..bg_col..'" |'..nrr_against_text..'\n')
end
end
Line 227 ⟶ 288:
local status_code, status_called = {},{}
status_code = { A='Advances to a further round', C='
E='Eliminated', G='Guest', H='Host', O='Play-off winner', P='Promoted', Q='Qualified
R='
local status_letters = (Args['status_order'] or '') .. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|