Module:Sports table/College: Difference between revisions

Content deleted Content added
fix ncwin_points
mNo edit summary
 
(40 intermediate revisions by 2 users not shown)
Line 9:
-- Pre stuff
local team_width = Args['teamwidth'] or '190'
local group_width = Args['groupwidth'] or '28'
local score_width = Args['scorewidth'] or '28'
local sort_text = yesno(Args['sortable_table'] or 'no') and ' sortable' or ''
local show_played = not yesno(Args['hide_played'] or 'no')
Line 19 ⟶ 21:
-- Custom header options
local played_head_text = Args['pld_header'] or '<abbr title="Played">Pld</abbr>'
local draw_head_texttie_head_text = Args['draw_headertie_header'] or '<abbr title="DrawnTie">DT</abbr>'
local group_head_text = Args['group_header'] or '<abbr title="Group">Grp</abbr>'
local team_head_text = Args['team_header'] or 'Team'
local bonus_head_text = Args['bonus_header'] or '<abbr title="Bonus points">BP</abbr>'
local loss_first = Args['loss_before_drawloss_before_tie'] or falsetrue
-- What to rank the teams by
local ranking_style = Args['ranking_style'] or 'ptsperc'
local show_points, show_perc = false
ranking_style = string.lower(ranking_style)
if ranking_style=='w' or ranking_style=='win' or ranking_style=='wins' then
-- Based on wins
elseif ranking_style=='ptsperc' or ranking_style=='pointspercentage' or ranking_style=='%' then
-- Based on percentage
show_perc = true
elseif ranking_style=='percpts' or ranking_style=='%pts' then
-- Based on percentage and points
show_perc = true
show_points = true
else
elseif ranking_style=='pts' or ranking_style=='points' then
-- Based on points
show_points = true
else
-- Based on percentage
show_perc = true
end
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local show_drawshow_tie = yesno(Args['show_drawshow_tie'] or 'no')
-- Use points instead of goals for/against
local for_against_style = Args['for_against_style'] or 'goals'
Line 78 ⟶ 80:
local do_scored = yesno(Args['use_goals_scored'] or 'no')
-- Whether to show totals instead of homeconference and awayoverall
local only_totals = yesno(Args['only_totals'] or 'no')
-- Whether to show totals instead of conference and overall
local only_conference = yesno(Args['only_conference'] or 'no')
-- Whether to show for against/totals instead of home/away for/against
Line 88 ⟶ 93:
-- Spacer style
local sps = only_totals and '' or only_conference and '' or ' style="border-width:1px 1px 1px 3px;"'
-- Initialize
Line 100 ⟶ 105:
-- Add group header
if full_table and group_col then
tt = p_sub.colhead(tt,28group_width,group_head_text) -- Group col
end
tt = p_sub.colhead(tt,team_width,team_head_text..VTE_text) -- Team col
if show_played then
tt = p_sub.colhead(tt,28score_width,played_head_text) -- Matches played col
end
if full_table then
local lbls = only_totals and {{'', 'Total '}} or only_conference and {{'', 'Conference '}} or {{'C', 'Conference '}, {'', 'Total '}}
for k,v in ipairs(lbls) do
local apre, tpre = v[1], v[2]
tt = p_sub.colhead(tt,'28'score_width..sps,'<abbr title="'..tpre..'won">'..apre..'W</abbr>') -- Win col
if loss_first then
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..'lost">'..apre..'L</abbr>') -- Loss col
if show_drawshow_tie then
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..'drawntied">'..apre..'DT</abbr>') -- Drawtie col
end
else
if show_drawshow_tie then
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..'drawntied">'..apre..'DT</abbr>') -- Drawtie col
end
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..'lost">'..apre..'L</abbr>') -- Loss col
end
if rounds_won then
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..'rounds won">'..apre..'RW</abbr>') -- Rounds won
end
if not hide_for_against and not only_fa_totals then
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..fa_word_plur..' for">'..apre..fa_letter..'F</abbr>') -- For col
tt = p_sub.colhead(tt,28score_width,'<abbr title="'..tpre..fa_word_plur..' against">'..apre..fa_letter..'A</abbr>') -- Against col
end
if show_perc then
if apre=="" then
tt = p_sub.colhead(tt,36,'<abbr title="Win percentage">'..apre..'PCT</abbr>') -- Win percentage col
else
tt = p_sub.colhead(tt,2836,'<abbr title="Games'..tpre..'win behindpercentage">GB'..apre..'PCT</abbr>')
end
end
if show_GB and tpre=="Conference " then -- Games behind header
tt = p_sub.colhead(tt,28,'<abbr title="Games behind">GB</abbr>')
end
end
Line 133 ⟶ 148:
local lsps = sps
if only_fa_totals then
tt = p_sub.colhead(tt,'28'..sps,'<abbr title="'..fa_word_plur..' for">'..fa_letter..'F</abbr>') -- For col
tt = p_sub.colhead(tt,'28','<abbr title="'..fa_word_plur..' against">'..fa_letter..'A</abbr>') -- Against col
lsps = ''
Line 149 ⟶ 164:
end
end
end
if show_GB then -- Games behind header
tt = p_sub.colhead(tt,28,'<abbr title="Games behind">GB</abbr>')
end
if show_perc then
tt = p_sub.colhead(tt,36,'<abbr title="Win percentage">PCT</abbr>') -- Win percentage col
end
if show_bonus_points then
Line 180 ⟶ 189:
local cwin_points = tonumber(Args['cwinpoints']) or tonumber(Args['winpoints']) or 3
local ncwin_points = tonumber(Args['ncwinpoints']) or tonumber(Args['winpoints']) or 3
local draw_pointstie_points = tonumber(Args['drawpointstiepoints']) or 1
local loss_points = tonumber(Args['losspoints']) or 0
local rw_points = tonumber(Args['rwpoints']) or 1
-- Order of drawsties and losses --
local loss_first = Args['loss_before_drawloss_before_tie'] or falsetrue
 
-- Optional rounds won
Line 191 ⟶ 200:
-- Get some input
local cwins = (tonumber(Args['cwin_'..team_code_ii]) or 0)
local ncwins = (tonumber(Args['ncwin_'..team_code_ii]) or 0)
local wins = cwins + ncwins
local cdrawscties = (tonumber(Args['cdraw_ctie_'..team_code_ii]) or 0)
local ncdrawsncties = (tonumber(Args['ncdraw_nctie_'..team_code_ii]) or 0)
local drawsties = cdrawscties + ncdrawsncties
local closses = (tonumber(Args['closs_'..team_code_ii]) or 0)
local nclosses = (tonumber(Args['ncloss_'..team_code_ii]) or 0)
local losses = closses + nclosses
local crw = (tonumber(Args['crw_'..team_code_ii]) or 0)
local ncrw = (tonumber(Args['ncrw_'..team_code_ii]) or 0)
local rw = crw + ncrw
Line 221 ⟶ 230:
local hth_local = Args['hth_'..team_code_ii] or nil
-- Then calculate some values
local matches = wins + drawsties + losses
if yesno(Args['only_conference'] or 'no') then
local points = cwin_points*cwins + ncwin_points*ncwins + draw_points*draws + loss_points*losses + rw_points*rw + s_pts
matches = cwins + cties + closses
end
local points = cwin_points*cwins + ncwin_points*ncwins + draw_pointstie_points*drawsties + loss_points*losses + rw_points*rw + s_pts
if Args['goalpoints'] and tonumber(gfor) then
points = points + (tonumber(Args['goalpoints']) or 1)*tonumber(gfor)
end
local show_drawshow_tie = yesno(Args['show_drawshow_tie'] or 'yesno')
if tonumber(Args['cwin_'..team_code_ii]) == nil or (show_draw and tonumber(Args['cdraw_'..team_code_ii]) == nil)
or tonumber(Args['closs_'..team_code_ii]) == nil or tonumber(Args['ncwin_'..team_code_ii]) == nil
or (show_draw and tonumber(Args['ncdraw_'..team_code_ii]) == nil) or tonumber(Args['ncloss_'..team_code_ii]) == nil then
matches = tonumber(Args['matches_'..team_code_ii]) or 0
end
local win_perc = ''
local cwin_perc = ''
local include_ties = yesno(Args['include_ties'] or 'yes')
if tonumber(matches) == nil or matches == 0 then
-- Escape for zero matches
win_perc = '&mdash;'
else
--Some sports use drawtie as well
if include_ties then
win_perc = mm._precision_format((2*wins + drawsties) / (2*matches), 3)
else
win_perc = mm._precision_format(wins / (matches - ties), 3)
end
if losses > 0 then
-- Drop the leading zero (from the string)
Line 246 ⟶ 259:
end
end
if tonumber(cwins+closses) == nil or (cwins+closses+cties) == 0 then
-- Escape for zero matches
cwin_perc = '&mdash;'
else
--Some sports use tie as well
if include_ties then
cwin_perc = mm._precision_format((2*cwins + cties) / (2*(cwins+cties+closses)), 3)
else
cwin_perc = mm._precision_format(cwins / (cwins+closses), 3)
end
if closses > 0 then
-- Drop the leading zero (from the string)
cwin_perc = string.sub(cwin_perc,2,string.len(cwin_perc))
end
end
-- Show for/against
local for_against_style = Args['for_against_style'] or 'goals'
Line 310 ⟶ 337:
-- Do nothing, it's vs this team
else
local wins_GB = (tonumber(Args['hwin_cwin_'..team_list[GB_team_no]]) or 0)
local +losses_GB = (tonumber(Args['awin_closs_'..team_list[GB_team_no]]) or 0)
local losses_GBties_GB = (tonumber(Args['hloss_'..team_list[GB_team_no]]) or 0) + (tonumber(Args['aloss_ctie_'..team_list[GB_team_no]]) or 0)
local GB_num = (wins_GB-winscwins+lossesclosses-losses_GB)/2 + (draws_GBties_GB - drawscties)
local draws_GB = (tonumber(Args['hdraw_'..team_list[GB_team_no]]) or 0) + (tonumber(Args['adraw_'..team_list[GB_team_no]]) or 0)
local GB_num = (wins_GB-wins+losses-losses_GB)/2 + (draws_GB - draws)
-- Display options
if GB_num >0 then
Line 335 ⟶ 362:
-- What to rank the teams by
local ranking_style = Args['ranking_style'] or 'ptsperc'
local rank_points, rank_perc = false
local win_fw, win_string
Line 364 ⟶ 391:
-- Whether to show totals instead of home and away
local only_totals = yesno(Args['only_totals'] or 'no')
-- Whether to show totals instead of home and away
local only_conference = yesno(Args['only_conference'] or 'no')
-- Spacer style
local sps = only_totals and '' or only_conference and '' or 'border-width:1px 1px 1px 3px;'
-- Row building
if show_played then
Line 371 ⟶ 400:
end
if full_table then
-- Use actual values if wins, drawsties, and losses are not numeric
if (cwins == 0 and ncwins == 0 and cdrawscties == 0 and ncdrawsncties == 0 and closses == 0 and nclosses == 0) then
local function numorval(s)
return s and ((s == '' and 0) or tonumber(s) or s) or 0
Line 378 ⟶ 407:
cwins = numorval(Args['cwin_'..team_code_ii])
ncwins = numorval(Args['ncwin_'..team_code_ii])
cdrawscties = numorval(Args['cdraw_ctie_'..team_code_ii])
ncdrawsncties = numorval(Args['ncdraw_nctie_'..team_code_ii])
closses = numorval(Args['closs_'..team_code_ii])
nclosses = numorval(Args['ncloss_'..team_code_ii])
end
local stats = only_totals and {{wins, ties, losses, rw, gfor, gaig}} or
only_conference and {{winscwins, cties, drawsclosses, lossescrw, rwcgfor, gforcgaig, gaigcwin_perc}} or
{{cwins, cdrawscties, closses, crw, cgfor, cgaig, cwin_perc}, {ncwinswins, ties, ncdrawslosses, nclossesrw, ncrwgfor, ncgforgaig, ncgaigwin_perc}}
local first_pass = true
for k,v in ipairs(stats) do
table.insert(t,'| style="'..sps..win_fw..bg_col..'" |'..(v[1])..win_string..'\n') -- Won
Line 391 ⟶ 421:
if loss_first then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..(v[3])..'\n') -- Lost
if show_drawshow_tie then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..(v[2])..'\n') -- Drawntied
end
else
if show_drawshow_tie then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..(v[2])..'\n') -- Drawntied
end
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..(v[3])..'\n') -- Lost
Line 407 ⟶ 437:
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..(v[6])..'\n') -- GA
end
if rank_perc then
if first_pass then
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..win_perc(v[7])..hth_string..'\n')
else
table.insert(t,'| style="'..ii_fw..bg_col..'" | '..GB_text(v[7])..'\n') -- GB
end
end
if show_GB and first_pass then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..GB_text..'\n') -- GB
end
first_pass = false
end
if not hide_for_against then
local lsps = sps
if only_fa_totals then
table.insert(t,'| style="'..sps..ii_fw..bg_col..'" |'..gfor..'\n') -- GF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaig..'\n') -- GA
lsps = ''
Line 417 ⟶ 458:
table.insert(t,'| style="'..lsps..ii_fw..bg_col..'" |'..gcomp..'\n') -- Goal comparison
end
end
if show_GB then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..GB_text..'\n') -- GB
end
if rank_perc then
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..win_perc..hth_string..'\n')
end
if show_bonus_points then
Line 451 ⟶ 485:
local status_code, status_called = {}, {}
status_code = { A='Advance to a further round', C='Champion', D='Disqualified',
E='Eliminated', G='Guest', H='Host', O='Play-off winner', 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'