Info Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Sports table/WL OT/man (modifica · cronologia)
Sandbox: Modulo:Sports table/WL OT/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Sports table/WL OT/test (modifica · cronologia · esegui)

Questo modulo serve a creare delle classifiche sportive, richiamando gli appositi sotto-moduli per i singoli casi o le singole specialità.

Istruzioni

(legenda colori)

{{#invoke:Sports table|main|style=WDL OT
|update = complete/future [default: "Dati aggiornati al"]
|start_date = data di inizio (va usato solo con update = future)
|source = fonte della tabella
|sortable_table = yes/no [default: no]
|teamwidth = [default: 190px]
|ranking_style = pts/win/perc/ppg/percpts/ppgpts/none [default: pts]
|use_goal_ratio = yes/no [default: no]
|use_goal_average = yes/no [default: no]
|use_goal_percentage = yes/no [default: no]
|use_point_percentage = yes/no [default: no]
|for_against_style = goals/point/none [default: goals]
|col_codice = colore della riga (vedi istruzioni)
|text_codice = testo del risultato
|resultnum = inserire il codice del risultato
|winpoints = [default: 3]
|OTwinpoints = [default: 2]
|OTlosspoints = [default: 1]
|losspoints = [default: 0]
|goalpoints = yes/no [default: no]
|team_order = ordine di classifica
|pos_cod = sovrascrive il valore automatico
|group_cod = gruppo di appartenenza
|name_cod = nome completo della squadra (anche con template)
|win_cod = numero di vittorie
|OTwin_cod = numero di vittorie ai supplementari
|loss_cod = numero di sconfitte
|OTloss_cod = numero di sconfitte ai supplementari
|tiebr_cod = tiebreaker
|gf_cod = numero di gol fatti
|pf_cod = numero di punti fatti
|ga_cod = numero di gol subiti
|pa_cod = numero di punti subiti
|note_cod = eventuale nota sulla squadra con tag ref
|status_cod = codice lettera (es. H = Ospitante)
|startpoints_cod = numero di punti di partenza
|adjust_points_cod = numero di punti di penalità
|show_positions = yes/no [default: yes]
|show_groups = yes/no [default: no]
|hide_played = yes/no [default: no]
|show_OTwin = yes/no [default: no]
|show_OTloss = yes/no [default: no]
|show_draw = yes/no [default: no]
|show_tiebr = yes/no [default: no]
|show_GB = yes/no [default: no]
|show_bonus_points = yes/no [default: no]
|hide_results = yes/no [default: no]
|postitle = intestazione della colonna posizione [default: "<abbr title="Posizione">Pos</abbr>"]
|group_header = intestazione della colonna gruppo [default: "<abbr title="Gruppo">Gr</abbr>"]
|team_header = intestazione della colonna squadra [default: "Squadra"]
|pld_header = intestazione della colonna giocate [default: "<abbr title="Giocate">G</abbr>"]
|win_header = intestazione della colonna giocate [default: "<abbr title="Vinte">V</abbr>"]
|OTwin_header = intestazione della colonna vittoria ai supplementari [default: "<abbr title="Vinte ai supplementari">VS</abbr>"]
|OTloss_header = intestazione della colonna sconfitta ai supplementari [default: "<abbr title="Perse ai supplementari">PS</abbr>"]
|loss_header = intestazione della colonna giocate [default: "<abbr title="Perse">P</abbr>"]
|bonus_header = intestazione della colonna bonus [default: "<abbr title="Bonus">B</abbr>"]
|tiebr_header = intestazione della colonna round [default: "<abbr title="Tiebreaker">T</abbr>"]
|res_col_header = intestazione della colonna risultato [default: "Risultato"]
|note_header_res = spazio per eventuali note al titolo della colonna risultato con tag ref
|splitnum = yes/no [default: no]
|pts_first = yes/no [default: no]
|perc_first = yes/no [default: no]
|OTloss_after = yes/no [default: no]
|show_class_rules = yes/no [default: no]
|show_totals = yes/no [default: no]
|show_matches = yes/no [default: no]
|match_cod1_cod2 = risultato del match
|match_cod1_cod2_note = eventuale nota sulla partita con tag ref
}}


-- Style for win/lose+overtime tables
local pp = {}

function pp.header(t,Args,p_sub,pos_label,group_col,VTE_text,full_table,results_header_txt)
	-- Load relevant modules
	local yesno = require('Module:Yesno')

	-- Create table header
	-- Pre stuff
	local team_width = Args['teamwidth'] or '190'
	local sort_text = ''
	local sort_table_val = Args['sortable_table'] 	or 'no'
	if yesno(sort_table_val) then sort_text = 'sortable' end
	local show_played = true
	local hide_played_val = Args['hide_played'] 	or 'no'
	if yesno(hide_played_val) then show_played = false end
	table.insert(t,'{|class="wikitable '..sort_text..'" style="text-align:center;"\n')	-- Open table

	-- Custom header options
	local group_head_text = Args['group_header']		or '<abbr title="Gruppo">Gr</abbr>'
	local team_head_text = Args['team_header']			or 'Squadra'
	local startpts_head_text = Args['startpts_header']	or '<abbr title="Punti di partenza">PP</abbr>'
	local OTwin_head_text = Args['OTwin_header']		or '<abbr title="Vinte ai supplementari">VOT</abbr>'
	local OTloss_head_text = Args['OTloss_header']		or '<abbr title="Perse ai supplementari">POT</abbr>'

	-- What to rank the teams by
	local ranking_style = Args['ranking_style'] or 'pts'
	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=='perc' or ranking_style=='percentage' or ranking_style=='%' then
		-- Based on percentage
		show_perc = true
	else
		-- Based on points
		show_points = true
	end
	-- Use points instead of goals for/against
	local for_against_style = Args['for_against_style'] 	or 'goals'
	local fa_letter, fa_word_sing, fa_word_plur
	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=='g' or for_against_style=='goal' or for_against_style=='goals' then
		fa_letter = 'G'
		fa_word_sing = 'Goal'
		fa_word_plur = 'Goal'
	elseif for_against_style=='p' or for_against_style=='point' or for_against_style=='points' then
		fa_letter = 'P'
		fa_word_sing = 'Punto'
		fa_word_plur = 'Punti'
	elseif for_against_style=='no' then
		hide_for_against = true
	else
		fa_letter = 'G'
		fa_word_sing = 'Goal'
		fa_word_plur = 'Goal'
	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

	-- Show start points or not
	local show_startpts = Args['show_startpts']		or 'no'
	local do_startpts = false
	if yesno(show_startpts) then do_startpts = true end

	-- Use bonus points or not
	local show_bonuspts = Args['show_bonuspts']		or 'no'
	local do_bonuspts = false
	if yesno(show_bonuspts) then do_bonuspts = true end

	-- Initialize
	local tt = {}
	tt.count = 0 		-- Up by one after every call
	tt.tab_text = t		-- Actual text
	-- Actual headers
	tt = p_sub.colhead(tt,28,pos_label)									-- Position col
	-- Add group header
	if full_table and group_col then
		tt = p_sub.colhead(tt,28,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,28,'<abbr title="Giocate">G</abbr>')		-- Matches played col
	end
	if full_table then
		tt = p_sub.colhead(tt,28,'<abbr title="Vinte">V</abbr>')		-- Win col
		tt = p_sub.colhead(tt,28,OTwin_head_text)
		tt = p_sub.colhead(tt,28,OTloss_head_text)
		tt = p_sub.colhead(tt,28,'<abbr title="Perse">P</abbr>')		-- Loss col
		if not hide_for_against then
			tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_plur..' fatti">'..fa_letter..'F</abbr>')			-- For col
			tt = p_sub.colhead(tt,28,'<abbr title="'..fa_word_plur..' subiti">'..fa_letter..'S</abbr>')			-- Against col
			if do_ratio then
				tt = p_sub.colhead(tt,28,'<abbr title="Quoziente '..fa_word_plur..'">Q'..fa_letter..'</abbr>')	-- Ratio col
			elseif do_percentage then
				tt = p_sub.colhead(tt,28,'<abbr title="Percentuale '..fa_word_plur..'">%</abbr>')				-- Percentage col
			else
				tt = p_sub.colhead(tt,28,'<abbr title="Differenza '..fa_word_plur..'">D'..fa_letter..'</abbr>')	-- Difference col
			end
		end
		if do_startpts then
			tt = p_sub.colhead(tt,28,startpts_head_text)				-- Punti di partenza
		end
		if do_bonuspts then
			tt = p_sub.colhead(tt,28,'<abbr title="Bonus">B</abbr>')	-- Bonus
		end
	end
	if show_points then
		tt = p_sub.colhead(tt,28,'<abbr title="Punti">Pt</abbr>')						-- Points col
	elseif show_perc then
		tt = p_sub.colhead(tt,28,'<abbr title="Percentuale di vittorie">PCT</abbr>')	-- Win percentage col
	end
	if full_table then
		tt.count = tt.count+1
		table.insert(tt.tab_text,results_header_txt)
	end

	return tt
end

function pp.row(frame,t,Args,p_sub,notes_exist,hth_id_list,full_table,rand_val,team_list,team_code_ii,ii_start,ii_end,ii_fw,bg_col,N_teams,ii,ii_show)
	-- Build the inner parts of individual rows
	-- Sub-module usage
	local mm = require('Module:Math')
	local yesno = require('Module:Yesno')

	-- Get custom/default options for in table
	local win_points = tonumber(Args['winpoints'])				or 3
	local OTwin_points = tonumber(Args['OTwinpoints'])			or 2
	local OTloss_points = tonumber(Args['OTlosspoints'])		or 1
	local loss_points = tonumber(Args['losspoints'])			or 0

	-- Get some input
	local wins = tonumber(Args['win_'..team_code_ii])			or 0
	local OTwins = tonumber(Args['OTwin_'..team_code_ii])		or 0
	local OTlosses = tonumber(Args['OTloss_'..team_code_ii])	or 0
	local losses = tonumber(Args['loss_'..team_code_ii])		or 0
	local gfor = tonumber(Args['gf_'..team_code_ii]) or	tonumber(Args['pf_'..team_code_ii]) or 0
	local gaig = tonumber(Args['ga_'..team_code_ii]) or	tonumber(Args['pa_'..team_code_ii]) or 0
	local s_pts = tonumber(Args['startpts_'..team_code_ii])		or 0
	local b_pts = tonumber(Args['bonuspts_'..team_code_ii])		or 0
	local p_pts = tonumber(Args['penaltypts_'..team_code_ii])	or 0
	local hth_local = Args['hth_'..team_code_ii]				or nil

	-- Then calculate some values
	local matches = wins + OTwins + OTlosses + losses
	local points = win_points*wins + OTwin_points*OTwins + OTloss_points*OTlosses + loss_points*losses + s_pts + b_pts + p_pts

	local win_perc = mm._precision_format((wins + OTwins) / matches, 3)
	if matches == 0 then
		-- Escape for zero matches
		win_perc = '&mdash;'
	elseif losses > 0 then
		-- Drop the leading zero (from the string)
		win_perc = string.sub(win_perc,2,string.len(win_perc))
	end

	-- Show games played
	local show_played = true
	local hide_played_val = Args['hide_played'] 	or 'no'
	if yesno(hide_played_val) then show_played = false end

	-- Show for/against
	local for_against_style = Args['for_against_style'] 	or 'goals'
	local hide_for_against = false
	for_against_style = string.lower(for_against_style)
	if for_against_style=='no' then
		hide_for_against = true
	end

	-- Comparison of for against
	local gcomp
	-- 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 gaig == 0 then
			gcomp = '&mdash;'
		else
			gcomp = mm._precision_format(gfor / gaig, 3)
		end
	elseif yesno(use_percentage_val) then
		-- Now it is the percentage
		if gaig == 0 then
			gcomp = '&mdash;'
		else
			gcomp = mm._precision_format(100 * gfor / gaig , 1)
		end
	else
		-- It's goal difference
		gcomp = gfor - gaig
		-- Formatting with signs
		if gcomp>0 then
			gcomp='+'..gcomp
		elseif gcomp < 0 then
			gcomp='&minus;'..-gcomp
		end
	end

	-- Some local vars
	local hth_string
	local tt_return = p_sub.hth(frame,Args,full_table,hth_id_list,hth_local,notes_exist,team_list,team_code_ii,ii_start,ii_end,rand_val)
	hth_string = tt_return.str
	hth_id_list = tt_return.list
	notes_exist = tt_return.notes_exist

	-- What to rank the teams by
	local ranking_style = Args['ranking_style'] or 'pts'
	local rank_points, rank_perc = false
	local win_fw, win_string
	ranking_style = string.lower(ranking_style)
	if ranking_style=='w' or ranking_style=='win' or ranking_style=='wins' then
		-- Based on wins
		win_fw = 'font-weight: bold;'
		win_string = hth_string
	elseif ranking_style=='perc' or ranking_style=='percentage' or ranking_style=='%' then
		-- Based on percentage
		rank_perc = true
		win_fw=ii_fw
		win_string = ''
	else
		-- Based on points
		rank_points = true
		win_fw=ii_fw
		win_string = ''
	end

	-- Show start points
	local show_startpts = Args['show_startpts']		or 'no'
	local do_startpts = false
	if show_startpts=='yes' then
		do_startpts = true
	end

	-- Show start points
	local show_bonuspts = Args['show_bonuspts']		or 'no'
	local do_bonuspts = false
	if show_bonuspts=='yes' then
		do_bonuspts = true
	end

	-- Row building
	if show_played then
		table.insert(t,'| style="'..ii_fw..bg_col..'" |'..matches..'\n') 			-- Giocate
	end
	if full_table then
		table.insert(t,'| style="'..win_fw..bg_col..'" |'..wins..win_string..'\n') 	-- Vinte
		table.insert(t,'| style="'..ii_fw..bg_col..'" |'..OTwins..'\n') 			-- Vinte ai supplementari
		table.insert(t,'| style="'..ii_fw..bg_col..'" |'..OTlosses..'\n') 			-- Perse ai supplementari
		table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') 			-- Perse
		if not hide_for_against then
			table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gfor..'\n') 			-- Gol fatti
			table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaig..'\n')			-- Gol subiti
			table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gcomp..'\n')      	-- Differenza reti
		end
		if do_startpts then
			table.insert(t,'| style="'..ii_fw..bg_col..'" |'..s_pts..'\n')			-- Punti di partenza
		end
		if do_bonuspts then
			table.insert(t,'| style="'..ii_fw..bg_col..'" |'..b_pts..'\n')			-- Bonus
		end
	end
	if rank_points then
		-- Add &minus; for negative point totals
		if points<0 then
			table.insert(t,'| style="font-weight: bold;'..bg_col..'" | &minus;'..-points..hth_string..'\n')
		else
			table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..points..hth_string..'\n')
		end
	elseif rank_perc then
		table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..win_perc..hth_string..'\n')
	end
	return {t=t, notes_exist=notes_exist, hth_id_list=hth_id_list}
end

function pp.status(Args)
	-- Declare status options
	-- ------------------------------------------------------------
	-- NOTE: If you add to status_code, also add to status_called and status_letters!!
	-- Or functionality will be compromised
	-- ------------------------------------------------------------
	local status_code, status_called = {}
	status_code = { A='Qualificata al turno successivo', C='Campione', S='Squalificata',
					E='Eliminata', G='Invitata', H='Ospitante', O='Vincitrice dei play-off', P='Promossa', Q='Qualificata alla fase indicata',
					R='Retrocessa', T='Qualificata, ma ancora a nessuna specifica fase indicata',
					X='?', Y='?', Z='?'}
	status_called = { A=false, C=false, E=false, G=false, H=false, O=false, P=false,
		Q=false, R=false, S=false, T=false, X=false, Y=false, Z=false}
	local status_letters = 'ACEGHOPQRSTXYZ'

	-- Status position (before or after read and default)
	local stat_pos_val = Args['status_pos'] or ''
	local status_position = 'after' 	-- Default ___location
	stat_pos_val = string.lower(stat_pos_val)
	if stat_pos_val=='before' then
		status_position = 'before'
	elseif stat_pos_val=='after' then
		status_position = 'after'
	end

	-- Read in custom status options
	if Args['status_text_X'] then status_code.X = Args['status_text_X'] end
	if Args['status_text_Y'] then status_code.Y = Args['status_text_Y'] end
	if Args['status_text_Z'] then status_code.Z = Args['status_text_Z'] end

	return {code=status_code, called=status_called, letters=status_letters, position=status_position}
end

return pp