Modulo:Sports table/totalscheck

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca
local tc = {}

function tc.check(Args, team_list, ii_start, ii_end)
	local warn = {}
	
	local wtotal, dtotal, ltotal = 0,0,0
	local hwtotal, hdtotal, hltotal = 0,0,0
	local awtotal, adtotal, altotal = 0,0,0
	local pkwtotal, pkltotal, otwtotal, otltotal = 0,0,0,0
	local gftotal, gatotal = 0,0
	
	for ii = ii_start, ii_end do
		-- First get code
		local team_code_ii = team_list[ii]
		if team_code_ii ~= 'SPORTS_TABLE_TOTAL' then
		-- Now tabulate values
			wtotal = wtotal + (tonumber(Args['win_'..team_code_ii]) or 0)
			dtotal = dtotal + (tonumber(Args['draw_'..team_code_ii]) or 0)
			ltotal = ltotal + (tonumber(Args['loss_'..team_code_ii]) or 0)
			hwtotal = hwtotal + (tonumber(Args['hwin_'..team_code_ii]) or 0)
			hdtotal = hdtotal + (tonumber(Args['hdraw_'..team_code_ii]) or 0)
			hltotal = hltotal + (tonumber(Args['hloss_'..team_code_ii]) or 0)
			awtotal = awtotal + (tonumber(Args['awin_'..team_code_ii]) or 0)
			adtotal = adtotal + (tonumber(Args['adraw_'..team_code_ii]) or 0)
			altotal = altotal + (tonumber(Args['aloss_'..team_code_ii]) or 0)
			pkwtotal = pkwtotal + (tonumber(Args['PKwin_'..team_code_ii]) or 0)
			pkltotal = pkltotal + (tonumber(Args['PKloss_'..team_code_ii]) or 0)
			otwtotal = otwtotal + (tonumber(Args['OTwin_'..team_code_ii]) or 0)
			otltotal = otltotal + (tonumber(Args['OTloss_'..team_code_ii]) or 0)
			gftotal = gftotal + (tonumber(Args['gf_'..team_code_ii]) or 0) + (tonumber(Args['pf_'..team_code_ii]) or 0)
			gatotal = gatotal + (tonumber(Args['ga_'..team_code_ii]) or 0) + (tonumber(Args['pa_'..team_code_ii]) or 0)
		end
	end
	if wtotal ~= ltotal then
		table.insert(warn, wtotal .. ' totale vittorie != ' .. ltotal .. ' totale sconfitte')
	end
	if hwtotal ~= altotal then
		table.insert(warn, hwtotal .. ' totale vittorie in casa != ' .. altotal .. ' totale sconfitte in trasferta')
	end
	if awtotal ~= hltotal then
		table.insert(warn, awtotal .. ' totale vittorie in trasferta != ' .. hltotal .. ' totale vittorie in casa')
	end
	if (2*math.floor(dtotal/2)) ~= dtotal then
		table.insert(warn, dtotal .. ' il totale dei pareggi è dispari')
	end
	if hdtotal ~= adtotal then
		table.insert(warn, hdtotal .. ' totale pareggi in casa != ' .. adtotal .. ' totale pareggi in trasferta')
	end
	if pkwtotal ~= pkltotal then
		table.insert(warn, pkwtotal .. ' totale vittorie ai rigori != ' .. pkltotal .. ' totale sconfitte ai rigori')
	end
	if otwtotal ~= otltotal then
		table.insert(warn, otwtotal .. ' totale vittorie ai supplementari != ' .. otltotal .. ' totale sconfitte ai supplementari')
	end
	if gftotal ~= gatotal then
		table.insert(warn, gftotal .. ' totale gol/punti fatti != ' .. gatotal .. ' totale gol/punti subiti')
	end
	
	return warn
end

return tc