Module:Sports table: Difference between revisions

Content deleted Content added
Allow for different style by delegating sport/style-specific issues to sub module
Undid revision 631924403 by CRwikiCA (talk) Revert to fix issue in sandbox
Line 15:
local t = {}
local t_footer = {}
local t_return = {}
local team_list = {}
local jjj
-- Load style and sub modules
local style_def = Args['style'] or 'football'
local p_style = require('Module:Sports table/'..style_def)
local p_sub = require('Module:Sports table/sub')
-- Random value used for uniqueness
Line 53 ⟶ 47:
local results_header_txt = '! scope="col" |'..local_res_header..res_head_note_text..'\n'
-- GetDeclare status optionoptions
local status_code, status_called = {}
local t_status = p_style.status()
-- ------------------------------------------------------------
-- NOTE: If you add to status_code, also add to status_called and status_letters!!
-- Or functionality will be compromised
-- ------------------------------------------------------------
status_code = { A='Advances to a further round', C='Champion', D='Disqualified',
E='Eliminated', H='Group host', O='Play-off winner', P='Promoted', Q='Qualified to the phase indicated',
R='Relegated', T='Qualified, but not yet to the particular phase indicated'}
status_called = { A=false, C=false, D=false, E=false, H=false, O=false, P=false,
Q=false, R=false, T=false}
local status_letters = 'ACDEHOPQRT'
-- Read in number of consecutive teams (ignore entries after skipping a spot)
Line 83 ⟶ 87:
 
-- Write column headers
local team_width = Args['teamwidth'] or '190'
t_return = p_style.header(t,Args,p_sub,pos_label,VTE_text,full_table,results_header_txt)
table.insert(t,'{|class="wikitable" style="text-align:center;"\n') -- Open table
t = t_return.tab_text
table.insert(t,'! scope="col" width=28|'..pos_label..'\n') -- Position col
local N_cols = t_return.count
table.insert(t,'! scope="col" width='..team_width..'|Team'..VTE_text..'\n') -- Team col
table.insert(t,'! scope="col" width=28|<abbr title="Played">Pld</abbr>\n') -- Matches played col
if full_table then
table.insert(t,'! scope="col" width=28|<abbr title="Won">W</abbr>\n') -- Win col
table.insert(t,'! scope="col" width=28|<abbr title="Drawn">D</abbr>\n') -- Draw col
table.insert(t,'! scope="col" width=28|<abbr title="Lost">L</abbr>\n') -- Loss col
table.insert(t,'! scope="col" width=28|<abbr title="Goals for">GF</abbr>\n') -- Goal for col
table.insert(t,'! scope="col" width=28|<abbr title="Goals against">GA</abbr>\n') -- Goal against col
table.insert(t,'! scope="col" width=28|<abbr title="Goal difference">GD</abbr>\n') -- Goal difference col
end
table.insert(t,'! scope="col" width=28|<abbr title="Points">Pts</abbr>\n') -- Points col
if full_table then
table.insert(t,results_header_txt) -- Result col
end
-- Determine what entries go into table
Line 119 ⟶ 137:
end
-- Get custom options for in table
local win_points = tonumber(Args['winpoints']) or 3
local draw_points = tonumber(Args['drawpoints']) or 1
local loss_points = tonumber(Args['losspoints']) or 0
-- For results column
local new_res_ii = ii_start
Line 124 ⟶ 147:
for ii = ii_start, ii_end do
if Args['result'..ii] then results_defined = true end
end
-- Remove results header if it is unused
if full_table and not results_defined then
-- First get it as one string, then use string replace to replace that header by empty string
local t_str = tostring(table.concat(t))
t_str = mw.ustring.gsub( t_str, results_header_txt, '' )
N_cols = N_cols-1 -- There is actually one column less
t = {}
table.insert(t, t_str)
end
-- Write rows
local team_name, team_code_ii, pos_num, note_local
local note_string, note_local, note_local_num, note_id
local hth_string, hth_local, hth_local_num, hth_id
local note_id_list = {}
local hth_id_list = {}
Line 144 ⟶ 159:
team_code_ii = team_list[ii]
-- Now read values
local pos_num = Args['pos_'..team_code_ii] or ii
local team_name = Args['name_'..team_code_ii] or team_code_ii
note_locallocal wins = tonumber(Args['note_win_'..team_code_ii] ) or nil0
local draws = tonumber(Args['draw_'..team_code_ii]) or 0
local losses = tonumber(Args['loss_'..team_code_ii]) or 0
local gfor = tonumber(Args['gf_'..team_code_ii]) or 0
local gaig = tonumber(Args['ga_'..team_code_ii]) or 0
local s_pts = tonumber(Args['startpoints_'..team_code_ii]) or 0
local note_local = Args['note_'..team_code_ii] or nil
local hth_local = Args['hth_'..team_code_ii] or nil
-- Then calculate some values
local matches = wins + draws + losses
local gdiff = gfor - gaig
local points = win_points*wins + draw_points*draws + loss_points*losses + s_pts
-- Does it need a promotion/qualification/relegation tag
Line 200 ⟶ 226:
else
note_string = '';
end
-- Check whether there is a head-to-head note or not, if so get text ready for it the same way as for the notes
if hth_local and full_table then
-- Set global check for notes to true
notes_exist = true
if not Args['hth_'..hth_local] then
-- Option 1
-- Now define the identifier for this
hth_id = '"table_hth_'..team_code_ii..rand_val..'"' -- Add random end for unique ID if more tables are present on article (which might otherwise share an ID)
hth_id_list[team_code_ii] = hth_id
-- Call refn template
hth_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=hth_id, hth_local} }
else
-- Option 2
hth_local_num = team_list[hth_local]
if hth_id_list[hth_local] or ((hth_local_num >= ii_start) and (hth_local_num <= ii_end)) then
-- Option 2a
hth_id = '"table_hth_'..hth_local..rand_val..'"'
hth_string = frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = hth_id} }
else
-- Option 2b
hth_id = '"table_hth_'..hth_local..rand_val..'"' -- Add random end for unique ID
hth_id_list[hth_local] = hth_id
-- Call refn template
hth_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=hth_id, Args['hth_'..hth_local]} }
end
end
else
hth_string = '';
end
Line 213 ⟶ 269:
curr_letter = mw.ustring.upper(mw.ustring.sub(status_local,jjj,jjj))
-- See whether it exist
if t_status.codestatus_code[curr_letter] then
-- Depending on whether it is the first letter of not
if status_let_first then
status_string = curr_letter
t_status.calledstatus_called[curr_letter] = true
status_let_first = false
else
status_string = status_string..', '..curr_letter
t_status.calledstatus_called[curr_letter] = true
end
end
Line 233 ⟶ 289:
table.insert(t,'! scope="row" style="text-align: center;'..ii_fw..bg_col..'"| '..pos_num..'\n') -- Position number
table.insert(t,'| style="text-align: left; white-space:nowrap;'..ii_fw..bg_col..'"| '..team_name..note_string..status_string..'\n')-- Team (with possible note)
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..matches..'\n') -- Played
-- Call to subfunction
if full_table then
t_return = p_style.row(t,Args,p_sub,notes_exist,hth_id_list,full_table,rand_val,team_code_ii,ii_fw,bg_col)
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..wins..'\n') -- Won
t = t_return.t
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..draws..'\n') -- Drawn
notes_exist = t_return.notes_exist
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') -- Lost
hth_id_list = t_return.hth_id_list
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gfor..'\n') -- GF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaig..'\n') -- GA
-- For goal difference insert + or &minus; as needed
table.insert(t,'| style="'..ii_fw..bg_col..'" |')
if gdiff>0 then
table.insert(t,'+'..gdiff)
elseif gdiff == 0 then
table.insert(t,0)
else
table.insert(t,'&minus;'..-gdiff)
end
table.insert(t,'\n')
end
-- Add &minus; for negative point totals
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | ')
if points<0 then
table.insert(t,'&minus;'..-points..hth_string)
else
table.insert(t,points..hth_string)
end
table.insert(t,'\n')
-- Now check what needs to be added inside the results column
Line 304 ⟶ 381:
-- Now, if needed, insert a split (solid line to indicate split in standings, but only when it is not at the last shown position)
if Args['split'..ii] and (ii<ii_end) then
if full_table then
-- Base size on N_cols (it needs 2*N_cols |)
table.insert(t,'|- style="background-color:'..result_col['black1']..'; line-height:3pt;"\n')
if results_defined then
table.insert(t,string.rep('|',2*N_cols)..'\n')
-- With results column
table.insert(t,'||||||||||||||||||||||\n')
else
-- No results column
table.insert(t,'||||||||||||||||||||\n')
end
else
table.insert(t,'|- style="background-color:'..result_col['black1']..'; line-height:3pt;"\n')
table.insert(t,'||||||||\n')
end
end
end
-- Remove results header if it is unused
if full_table and not results_defined then
-- First get it as one string, then use string replace to replace that header by empty string
local t_str = tostring(table.concat(t))
t_str = mw.ustring.gsub( t_str, results_header_txt, '' )
t = {}
table.insert(t, t_str)
end
Line 340 ⟶ 436:
local status_string = ''
local curr_letter
for jjj = 1,mw.ustring.len(t_status.lettersstatus_letters) do
curr_letter = mw.ustring.upper(mw.ustring.sub(t_status.lettersstatus_letters,jjj,jjj))
if t_status.calledstatus_called[curr_letter] then
status_string = status_string..'<span style="font-weight:bold">('..curr_letter..')</span> '..t_status.codestatus_code[curr_letter]..'; '
status_exist = true
end