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))
 
(38 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 15:
-- Custom header options
local draw_head_text = Args['draw_header'] or '<abbr title="Drawn">D</abbr>'
local group_head_text = Args['group_header'] or '<abbr title="Group">Grp</abbr>'
local team_head_text = Args['team_header'] or 'Team'
Line 31 ⟶ 32:
show_points = true
end
-- Use points instead of goals for/against
local for_against_style = Args['for_against_style'] or 'goalsmatches'
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=='goalmatch' or for_against_style=='goalsmatches' then
fa_letter = 'GM'
fa_word_sing = 'GoalMatch'
fa_word_plur = 'GoalsMatches'
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
else
fa_letter = 'GM'
fa_word_sing = 'GoalMatch'
fa_word_plur = 'GoalsMatches'
end
-- Whether to use goal ratio (goal average) instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
Line 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 69 ⟶ 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
tt = p_sub.colhead(tt,28,draw_head_text) -- Draw col
else
tt = p_sub.colhead(tt,2820,draw_head_text'<abbr title="Lost">L</abbr>') -- DrawLoss col
tt = p_sub.colhead(tt,28,'<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 118 ⟶ 200:
-- Get custom/default options for in table
local win_points = tonumber(Args['winpoints']) or 31
local draw_points = tonumber(Args['drawpoints']) or 1
local loss_points = tonumber(Args['losspoints']) or 0
Line 127 ⟶ 208:
-- 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 gformfor = tonumber(Args['gf_mf_'..team_code_ii]) or tonumber(Args['pf_mf_'..team_code_ii]) or 0
local gaigmaig = tonumber(Args['ga_ma_'..team_code_ii]) or tonumber(Args['pa_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
-- Then calculate some values
local matches = wins + draws + losses
local points = win_points*wins + draw_points*draws + loss_points*losses + s_pts
local win_perc = ''
--Some sports use draw as well
local win_perc = mm._precision_format((2*wins + draws) / (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 156 ⟶ 244:
-- Comparison of for against
local gcompmcomp
-- 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 maig == 0 then
mcomp = '&mdash;'
else
mcomp = mm._precision_format(gfor / gaig, 3)
end
elseif yesno(use_percentage_val) then
-- Now it is the percentage
if maig == 0 then
mcomp = '&mdash;'
else
mcomp = mm._precision_format(100 * gfor / gaig , 1)
end
else
-- It's match difference
mcomp = mfor - maig
-- Formatting with signs
if mcomp>0 then
mcomp='+'..mcomp
elseif mcomp < 0 then
mcomp='&minus;'..-mcomp
end
end
local gcomp
-- Whether to use goal ratio (goal average) or goal percentage instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
Line 176 ⟶ 294:
end
else
-- It's goalmatch difference
gcomp = gfor - gaig
-- Formatting with signs
Line 186 ⟶ 304:
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 221 ⟶ 368:
if loss_first then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') -- Lost
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..draws..'\n') -- Drawn
else
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..draws..'\n') -- Drawn
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..'" |'..gfor..'\n') -- GF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaigmfor..'\n') -- GAMF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gcompmaig..'\n') -- Goal 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