Module:Sports table/WDL: Difference between revisions

Content deleted Content added
add wperc
fix inconsistent use of ranking_style=='wpct' or ranking_style=='%w' which was causing strange results when either was uses
 
(10 intermediate revisions by 3 users not shown)
Line 32:
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
Line 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 104 ⟶ 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')
Line 207 ⟶ 211:
table.insert(tt.tab_text,results_header_txt)
end
 
return tt
end
Line 248 ⟶ 252:
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 264 ⟶ 278:
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 278 ⟶ 294:
end
local win_perc = ''
--Some sports use draw as well
local ppg = ''
local win_perc = mm._precision_format((2*wins + draws) / (2*matches), 3)
if tonumber(matches) == nil or matches == 0 then
local ppg = mm._precision_format(points / matches, 2)
if matches == 0 then
-- Escape for zero matches
win_perc = '—'
ppg = '—'
else
elseif losses > 0 or draws > 0 then
--Some sports use draw as well
-- Drop the leading zero (from the string)
win_perc = string.sub(win_perc,2,string.len(win_perc)pct_style == 'ratio') and
local 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
local ppg = mm._precision_format(points / matches, 2)
elseif 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 = '—'
Line 322 ⟶ 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 399 ⟶ 429:
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
Line 546 ⟶ 576:
-- ------------------------------------------------------------
local status_code, status_called = {}, {}
status_code = { A='Advance to a further round', C='ChampionChampions', D='Disqualified',
E='Eliminated', G='GuestGuests', H='HostHosts', O='Play-off winnerwinners', P='Promoted', Q='Qualified tofor the phase indicated',
R='Relegated', T='Qualified, but not yet tofor the particular phase indicated'}
local status_letters = (Args['status_order'] or '') .. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'