Module:Sports table/Badminton team: Difference between revisions

Content deleted Content added
No edit summary
m Protected "Module:Sports table/Badminton team": High-risk template or module: 270 transclusions (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite))
 
(29 intermediate revisions by 4 users not shown)
Line 8:
-- Create table header
-- Pre stuff
local team_width = Args['teamwidth'] or '190165'
local sort_text = ''
local sort_table_val = Args['sortable_table'] or 'no'
Line 32:
show_points = true
end
-- Use points instead of goals for/against
local for_against_style = Args['for_against_style'] or 'matches'
local fa_letter, fa_word_sing, fa_word_plur
local show_matches = yesno(Args['show_matches'] or 'yes')
local hide_for_against = false
-- First convert to lower case if it is a string
for_against_style = string.lower(for_against_style)
if for_against_style=='gm' or for_against_style=='match' or for_against_style=='matches' then
fa_letter = 'M'
fa_word_sing = 'Match'
fa_word_plur = 'Matches'
elseif for_against_style=='p' or for_against_style=='point' or for_against_style=='points' then
fa_letter = 'P'
fa_word_sing = 'Point'
fa_word_plur = 'Points'
elseif for_against_style=='none' then
hide_for_against = true
Line 53 ⟶ 51:
fa_word_plur = 'Matches'
end
-- Whether to use goal ratio (goal average) instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
Line 64 ⟶ 63:
-- True if exist, false otherwise
if yesno(use_percentage_val) then do_percentage = true end
 
-- Use points instead of point for/against
local game_for_against_style = Args['game_for_against_style'] or 'games'
local gfa_letter, gfa_word_sing, gfa_word_plur
local hide_game_for_against = false
-- First convert to lower case if it is a string
for_against_style = string.lower(for_against_style)
if game_for_against_style=='g' or game_for_against_style=='game' or game_for_against_style=='games' then
gfa_letter = 'G'
gfa_word_sing = 'Game'
gfa_word_plur = 'Games'
elseif game_for_against_style=='none' then
hide_game_for_against = true
else
gfa_letter = 'G'
gfa_word_sing = 'Game'
gfa_word_plur = 'Games'
end
-- Whether to use goal ratio (goal average) instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
local do_ratio = false
-- True if exist, false otherwise
if yesno(use_ratio_val) then do_ratio = true end
-- Whether to use goal percentage instead
local use_percentage_val = Args['use_goal_percentage'] or 'no'
local do_percentage = false
-- True if exist, false otherwise
if yesno(use_percentage_val) then do_percentage = true end
-- Use points instead of point for/against
local point_for_against_style = Args['point_for_against_style'] or 'points'
local pfa_letter, pfa_word_sing, pfa_word_plur
local hide_point_for_against = false
-- First convert to lower case if it is a string
for_against_style = string.lower(for_against_style)
if point_for_against_style=='p' or point_for_against_style=='match' or point_for_against_style=='points' then
pfa_letter = 'P'
pfa_word_sing = 'Point'
pfa_word_plur = 'Points'
elseif point_for_against_style=='none' then
hide_point_for_against = true
else
pfa_letter = 'P'
pfa_word_sing = 'Point'
pfa_word_plur = 'Points'
end
-- Whether to use goal ratio (goal average) instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
local do_ratio = false
-- True if exist, false otherwise
if yesno(use_ratio_val) then do_ratio = true end
-- Whether to use goal percentage instead
local use_percentage_val = Args['use_goal_percentage'] or 'no'
local do_percentage = false
-- True if exist, false otherwise
if yesno(use_percentage_val) then do_percentage = true end
-- Initialize
Line 70 ⟶ 128:
tt.tab_text = t -- Actual text
-- Actual headers
tt = p_sub.colhead(tt,2820,pos_label) -- Position col
-- Add group header
if full_table and group_col then
tt = p_sub.colhead(tt,2820,group_head_text) -- Group col
end
tt = p_sub.colhead(tt,team_width,team_head_text..VTE_text) -- Team col
tt = p_sub.colhead(tt,2820,'<abbr title="Played">Pld</abbr>') -- Matches played col
if full_table then
tt = p_sub.colhead(tt,2820,'<abbr title="Won">W</abbr>') -- Win col
if loss_first then
tt = p_sub.colhead(tt,2820,'<abbr title="Lost">L</abbr>') -- Loss col
else
tt = p_sub.colhead(tt,20,'<abbr title="Lost">L</abbr>') -- Loss col
end
if not hide_for_against then
if show_matches then
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_plur..' for">'..fa_letter..'F</abbr>') -- For col
tt = p_sub.colhead(tt,2820,'<abbr title="'..fa_word_plur..' againstfor">'..fa_letter..'AF</abbr>') -- AgainstFor col
tt = p_sub.colhead(tt,20,'<abbr title="'..fa_word_plur..' against">'..fa_letter..'A</abbr>') -- Against col
if do_ratio then
if do_ratio then
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..' ratio">'..fa_letter..'R</abbr>') -- Ratio col
tt = p_sub.colhead(tt,20,'<abbr title="'..fa_word_sing..' ratio">'..fa_letter..'R</abbr>') -- Ratio col
elseif do_percentage then
elseif do_percentage then
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..' percentage">%</abbr>') -- Percentage col
tt = p_sub.colhead(tt,20,'<abbr title="'..fa_word_sing..' percentage">%</abbr>') -- Percentage col
else
else
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..' difference">'..fa_letter..'D</abbr>') -- Difference col
tt = p_sub.colhead(tt,20,'<abbr title="'..fa_word_sing..' difference">'..fa_letter..'D</abbr>') -- Difference col
end
end
if not hide_game_for_against then
tt = p_sub.colhead(tt,20,'<abbr title="'..gfa_word_plur..' for">'..gfa_letter..'F</abbr>') -- For col
tt = p_sub.colhead(tt,20,'<abbr title="'..gfa_word_plur..' against">'..gfa_letter..'A</abbr>') -- Against col
if do_ratio then
tt = p_sub.colhead(tt,20,'<abbr title="'..gfa_word_sing..' ratio">'..gfa_letter..'R</abbr>') -- Ratio col
elseif do_percentage then
tt = p_sub.colhead(tt,20,'<abbr title="'..gfa_word_sing..' percentage">%</abbr>') -- Percentage col
else
tt = p_sub.colhead(tt,20,'<abbr title="'..gfa_word_sing..' difference">'..gfa_letter..'D</abbr>') -- Difference col
end
if not hide_point_for_against then
tt = p_sub.colhead(tt,20,'<abbr title="'..pfa_word_plur..' for">'..pfa_letter..'F</abbr>') -- For col
tt = p_sub.colhead(tt,20,'<abbr title="'..pfa_word_plur..' against">'..pfa_letter..'A</abbr>') -- Against col
if do_ratio then
tt = p_sub.colhead(tt,20,'<abbr title="'..pfa_word_sing..' ratio">'..pfa_letter..'R</abbr>') -- Ratio col
elseif do_percentage then
tt = p_sub.colhead(tt,20,'<abbr title="'..pfa_word_sing..' percentage">%</abbr>') -- Percentage col
else
tt = p_sub.colhead(tt,20,'<abbr title="'..pfa_word_sing..' difference">'..pfa_letter..'D</abbr>') -- Difference col
end
end
end
end
end
if show_points then
tt = p_sub.colhead(tt,2820,'<abbr title="Points">Pts</abbr>') -- Points col
elseif show_perc then
tt = p_sub.colhead(tt,36,'<abbr title="Win percentage">PCT</abbr>') -- Win percentage col
Line 126 ⟶ 211:
local mfor = tonumber(Args['mf_'..team_code_ii]) or tonumber(Args['mf_'..team_code_ii]) or 0
local maig = tonumber(Args['ma_'..team_code_ii]) or tonumber(Args['ma_'..team_code_ii]) or 0
local gfor = tonumber(Args['gf_'..team_code_ii]) or tonumber(Args['gf_'..team_code_ii]) or 0
local gaig = tonumber(Args['ga_'..team_code_ii]) or tonumber(Args['ga_'..team_code_ii]) or 0
local pfor = tonumber(Args['pf_'..team_code_ii]) or tonumber(Args['pf_'..team_code_ii]) or 0
local paig = tonumber(Args['pa_'..team_code_ii]) or tonumber(Args['pa_'..team_code_ii]) or 0
local s_pts = tonumber(Args['adjust_points_'..team_code_ii]) or tonumber(Args['startpoints_'..team_code_ii]) or 0
local hth_local = Args['hth_'..team_code_ii] or nil
Line 132 ⟶ 221:
local points = win_points*wins + loss_points*losses + s_pts
local win_perc = ''
--Some sports use draw as well
local win_perc = mm._precision_format((2*wins) / (2*matches), 3)
if matches == 0 then
-- Escape for zero matches
win_perc = '&mdash;'
else
elseif losses > 0 then
--Some sports use draw as well
-- Drop the leading zero (from the string)
win_perc = stringmm.sub_precision_format((win_perc,2,string.len*wins) / (win_perc2*matches), 3)
if losses > 0 then
-- Drop the leading zero (from the string)
win_perc = string.sub(win_perc,2,string.len(win_perc))
end
end
-- Show for/against
local for_against_style = Args['for_against_style'] or 'goals'
local show_matches = yesno(Args['show_matches'] or 'yes')
local hide_for_against = false
for_against_style = string.lower(for_against_style)
Line 181 ⟶ 274:
end
local gcomp
-- Whether to use goal ratio (goal average) or goal percentage instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
local use_percentage_val = Args['use_goal_percentage'] or 'no'
local skip_sign
if yesno(use_ratio_val) then
-- Now it is the goal ratio/goal average
if gaig == 0 then
gcomp = '&mdash;'
else
gcomp = mm._precision_format(gfor / gaig, 3)
end
elseif yesno(use_percentage_val) then
-- Now it is the percentage
if gaig == 0 then
gcomp = '&mdash;'
else
gcomp = mm._precision_format(100 * gfor / gaig , 1)
end
else
-- It's match difference
gcomp = gfor - gaig
-- Formatting with signs
if gcomp>0 then
gcomp='+'..gcomp
elseif gcomp < 0 then
gcomp='&minus;'..-gcomp
end
end
local pcomp
-- Whether to use goal ratio (goal average) or goal percentage instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
local use_percentage_val = Args['use_goal_percentage'] or 'no'
local skip_sign
if yesno(use_ratio_val) then
-- Now it is the goal ratio/goal average
if paig == 0 then
pcomp = '&mdash;'
else
pcomp = mm._precision_format(gfor / gaig, 3)
end
elseif yesno(use_percentage_val) then
-- Now it is the percentage
if paig == 0 then
pcomp = '&mdash;'
else
pcomp = mm._precision_format(100 * gfor / gaig , 1)
end
else
-- It's match difference
pcomp = pfor - paig
-- Formatting with signs
if pcomp>0 then
pcomp='+'..pcomp
elseif pcomp < 0 then
pcomp='&minus;'..-pcomp
end
end
-- Some local vars
local hth_string
Line 215 ⟶ 367:
if loss_first then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') -- Lost
else
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') -- Lost
end
if not hide_for_against then
if show_matches then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..mfor..'\n') -- MF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..maigmfor..'\n') -- MAMF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..mcompmaig..'\n') -- Match comparisonMA
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..mcomp..'\n') -- Match comparison
end
if Args['game_for_against_style'] ~= 'none' then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gfor..'\n') -- GF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaig..'\n') -- GA
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gcomp..'\n') -- Game comparison
if Args['point_for_against_style'] ~= 'none' then -- game param hides games and points in header
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..pfor..'\n') -- PF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..paig..'\n') -- PA
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..pcomp..'\n') -- Point comparison
end
end
end