Content deleted Content added
No edit summary |
fix inconsistent use of ranking_style=='wpct' or ranking_style=='%w' which was causing strange results when either was uses |
||
(27 intermediate revisions by 5 users not shown) | |||
Line 28:
local loss_first = Args['loss_before_draw'] or Args['loss_before_tie'] or false
-- What to rank the teams by
local ranking_style = string.lower(Args['ranking_style'] or 'pts')
local show_points, show_wperc, show_perc, show_ppg = false, false, false, false
if ranking_style=='w' or ranking_style=='win' or ranking_style=='wins' or ranking_style=='none' then
-- Based on wins
elseif ranking_style=='wperc' or ranking_style=='win percentage' or ranking_style=='wpct' or ranking_style=='%w' then
show_wperc = true
elseif ranking_style=='perc' or ranking_style=='percentage' or ranking_style=='%' then
-- Based on percentage
Line 42 ⟶ 43:
-- Based on percentage and points
show_perc = true
show_points = true
elseif ranking_style=='ppgpts' then
-- Based on ppg and points
show_ppg = true
show_points = true
else
Line 50 ⟶ 55:
local show_away_goals = yesno(Args['show_away_goals'] or 'no')
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local show_win = yesno(Args['show_win'] or 'yes')
local show_draw = yesno(Args['show_draw'] or 'yes')
local show_loss = yesno(Args['show_loss'] or 'yes')
-- Use points instead of goals for/against
local for_against_style = Args['for_against_style'] or 'goals'
Line 84 ⟶ 91:
fa_letter = 'R'
fa_word_sing = 'Run'
fa_word_plur = 'Runs'
elseif for_against_style=='l' or for_against_style=='leg' or for_against_style=='legs' then
fa_letter = 'L'
fa_word_sing = 'Leg'
fa_word_plur = 'Legs'
elseif for_against_style=='none' then
hide_for_against = true
Line 97 ⟶ 108:
-- Whether to use goal percentage instead
local do_percentage = yesno(Args['use_goal_percentage'] or Args['use_against_percentage'] or Args['use_point_percentage'] or 'no')
local do_point_for_avg = yesno(Args['use_goals_per_match'] or Args['use_points_per_match'] or 'no')
-- Whether to suppress the GR/GA/G% column entirely
Line 133 ⟶ 146:
end
if full_table then
if show_win then
tt = p_sub.colhead(tt,28,'<abbr title="Won">W</abbr>') -- Win col
end
if loss_first then
if show_loss then
tt = p_sub.colhead(tt,28,'<abbr title="Lost">L</abbr>') -- Loss col
end
if show_draw then
tt = p_sub.colhead(tt,28,draw_head_text) -- Draw col
Line 143 ⟶ 160:
tt = p_sub.colhead(tt,28,draw_head_text) -- Draw col
end
if show_loss then
tt = p_sub.colhead(tt,28,'<abbr title="Lost">L</abbr>') -- Loss col
end
end
if rounds_won then
Line 158 ⟶ 177:
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..ratio_word..'">'..fa_letter..ratio_letter..'</abbr>') -- Ratio col
elseif do_percentage then
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..' percentage">
elseif do_point_for_avg then
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_plur..' per match">'..fa_letter..'PM</abbr>') -- Points per match
elseif do_difference then
tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..' difference">'..fa_letter..'D</abbr>') -- Difference col
Line 176 ⟶ 197:
if show_perc then
tt = p_sub.colhead(tt,36,'<abbr title="Win percentage">PCT</abbr>') -- Win percentage col
elseif show_wperc then
tt = p_sub.colhead(tt,36,'<abbr title="Win percentage">WPCT</abbr>') -- Win percentage col
end
if show_ppg then
Line 188 ⟶ 211:
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
Line 198 ⟶ 241:
local mm = require('Module:Math')
local yesno = require('Module:Yesno')
-- Get custom/default options for in table
local show_win = yesno(Args['show_win'] or 'yes')
local show_draw = yesno(Args['show_draw'] or 'yes')
local show_loss = yesno(Args['show_loss'] or 'yes')
local win_points = tonumber(Args['winpoints']) or (show_draw and 3 or 2)
local draw_points = tonumber(Args['drawpoints']) or (show_draw and 1 or 0)
local loss_points = tonumber(Args['losspoints']) or (show_draw and 0 or 1)
local rw_points = tonumber(Args['rwpoints']) or 1
local digits = Args['digitpad']
local total_row_name = 'SPORTS_TABLE_TOTAL'
-- Add to tallies if enabled
if yesno(Args['show_totals'] or 'no') and (team_code_ii ~= total_row_name) then
for k,v in ipairs({'win', 'draw', 'loss', 'gf', 'ga', 'adjust_points', 'startpoints'}) do
Args[v .. '_' .. total_row_name] =
(tonumber(Args[v .. '_' .. total_row_name]) or 0)
+ (tonumber(Args[v .. '_' .. team_code_ii]) or 0)
end
end
-- Order of draws and losses --
local loss_first = Args['loss_before_draw'] or Args['loss_before_tie'] or false
Line 221 ⟶ 277:
local s_pts = (tonumber(Args['adjust_points_'..team_code_ii]) or 0) + (tonumber(Args['startpoints_'..team_code_ii]) or 0)
local hth_local = yesno(Args['show_hth'] or 'yes') and Args['hth_'..team_code_ii] or nil
local ranking_style = string.lower(Args['ranking_style'] or 'pts')
local pct_style = string.lower(Args['pct_style'] or 'ratio')
-- Then calculate some values
local matches = wins + draws + losses
Line 235 ⟶ 294:
end
local win_perc = ''
local ppg = ''
if tonumber(matches) == nil or matches == 0 then
-- Escape for zero matches
win_perc = '—'
ppg = '—'
else
--Some sports use draw as well
win_perc =
mm._precision_format((2*wins + draws + s_pts) / (2*matches), 3) or
mm._precision_format(100*(2*wins + draws + s_pts) / (2*matches), 2)
-- Allow win_perc to be altered due to point deductions/additions
ppg = mm._precision_format(points / matches, 2)
if (losses > 0 or draws > 0) and pct_style == 'ratio' then
-- Drop the leading zero (from the string)
win_perc = string.sub(win_perc,2,string.len(win_perc))
end
end
if ranking_style=='wperc' or ranking_style=='win percentage' or ranking_style=='wpct' or ranking_style=='%w' then
if matches == 0 then
win_perc = '—'
else
win_perc = mm._precision_format(100 * wins / matches, 2)
end
end
Line 272 ⟶ 345:
else
gcomp = mm._precision_format(100 * gfor / gaig , 1)
end
elseif yesno(Args['use_against_percentage'] or 'no') then
-- Now it is the percentage
if (gfor == '?') or (gaig == '?') or gfor == 0 then
gcomp = '—'
else
gcomp = mm._precision_format(100 * gaig / gfor , 1)
end
elseif yesno(Args['use_point_percentage'] or 'no') then
Line 279 ⟶ 359:
else
gcomp = mm._precision_format(100 * gfor / (gfor + gaig) , 2)
end
elseif yesno(Args['use_goals_per_match'] or Args['use_points_per_match'] or 'no') then
-- Now it is the point for average
if (gfor == '?') or matches <= 0 then
gcomp = '—'
else
gcomp = mm._precision_format(gfor / matches , 1)
end
elseif yesno(Args['use_goal_diff'] or 'yes') then
Line 288 ⟶ 375:
-- Formatting with signs
if gcomp>0 then
gcomp='+'..num_align(gcomp,digits)
elseif gcomp < 0 then
gcomp='−'..-num_align(gcomp,digits)
end
end
Line 312 ⟶ 399:
if GB_num >0 then
-- Indicates trailing GB_team
GB_text = num_align(GB_num,digits)
elseif GB_num == 0 then
-- Equal, do nothing to get dash
else
-- Ahead of GB team, should be noted by plus (instead of minus that comes from formula)
GB_text = '+'..num_align(-GB_num,digits)
end
end
Line 330 ⟶ 417:
-- What to rank the teams by
local rank_points, rank_perc, rank_wperc, rank_ppg = false, false, false, false
local win_fw, win_string
if ranking_style=='w' or ranking_style=='win' or ranking_style=='wins' then
-- Based on wins
Line 341 ⟶ 427:
-- Based on percentage
rank_perc = true
win_fw=ii_fw
win_string = ''
elseif ranking_style=='wperc' or ranking_style=='win percentage' or ranking_style=='wpct' or ranking_style=='%w' then
-- Based on percentage
rank_wperc = true
win_fw=ii_fw
win_string = ''
Line 351 ⟶ 442:
-- Based on percentage and points
rank_perc = true
rank_points = true
win_fw=ii_fw
win_string = ''
elseif ranking_style=='ppgpts' then
-- Based on ppg and points
rank_ppg = true
rank_points = true
win_fw=ii_fw
Line 366 ⟶ 463:
local show_away_goals = yesno(Args['show_away_goals'] or 'no')
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local pts_perc_first = yesno((rank_points and Args['pts_first']) or ((rank_perc or rank_wperc) and Args['perc_first']) or 'no')
-- Row building
if (tonumber(Args['adjust_points_'..team_code_ii]) and tonumber(Args['startpoints_'..team_code_ii])) then
Line 375 ⟶ 472:
-- Add − for negative point totals
if points<0 then
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | −'..num_align(-points,digits)..hth_string..'\n')
else
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..num_align(points,digits)..hth_string..'\n')
end
end
if rank_perc then
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..win_perc..hth_string..'\n')
elseif rank_wperc then
table.insert(t,'| style="font-weight: bold;text-align:right;'..bg_col..'" | '..win_perc..hth_string..'\n')
end
if rank_ppg then
Line 400 ⟶ 499:
losses = numorval(Args['loss_'..team_code_ii])
end
if show_win then
table.insert(t,'| style="'..win_fw..bg_col..'" |'..num_align(wins,digits)..win_string..'\n')
end
if loss_first then
if show_loss then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..num_align(losses,digits)..'\n') -- Lost
end
if show_draw then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..num_align(draws,digits)..'\n') -- Drawn
end
else
if show_draw then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..num_align(draws,digits)..'\n') -- Drawn
end
if show_loss then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..num_align(losses,digits)..'\n') -- Lost
end
end
if rounds_won then
Line 422 ⟶ 526:
if not hide_for_against then
if not yesno(Args['hide_for_against_columns'] or 'no') then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..num_align(gfor,digits)..'\n') -- GF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..num_align(gaig,digits)..'\n') -- GA
end
if gcomp then
Line 436 ⟶ 540:
if show_bonus_points then
if s_pts < 0 then
table.insert(t,'| style="'..bg_col..'" | −'..num_align(-s_pts,digits)..'\n')
else
table.insert(t,'| style="'..bg_col..'" | '..num_align(s_pts,digits)..'\n')
end
end
Line 445 ⟶ 549:
-- Add − for negative point totals
if points<0 then
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | −'..num_align(-points,digits)..hth_string..'\n')
else
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..num_align(points,digits)..hth_string..'\n')
end
end
if rank_perc then
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..win_perc..hth_string..'\n')
elseif rank_wperc then
table.insert(t,'| style="font-weight: bold;text-align:right;'..bg_col..'" | '..win_perc..hth_string..'\n')
end
if rank_ppg then
Line 470 ⟶ 576:
-- ------------------------------------------------------------
local status_code, status_called = {}, {}
status_code = { A='Advance to a further round', C='
E='Eliminated', G='
R='Relegated', T='Qualified, but not yet
local status_letters = (Args['status_order'] or '') .. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|