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

Questo modulo include le diverse funzioni richiamate dai template risultati di Formula 1.

Il modulo è provvisto di due sottopagine:

  • Stagioni: tabella contenente i dati relativi a ciascuna stagione
  • GP: tabella contenente i dati relativi ai Gran Premi

local p = {}
local getArgs = require('Modulo:Arguments').getArgs
local tabella = mw.loadData('Modulo:RisF1/Stagioni')
local tabgp = mw.loadData('Modulo:RisF1/GP')

local tavolozza = {
["1"] = "FFFFBF",
["2"] = "DFDFDF",
["3"] = "FFDF9F",
punti = "DFFFDF",
nopunti = "CFCFFF",
NC = "CFCFFF",
Rit = "EFCFFF",
SQ = "000000; color:white; font-size:81%",
NP = "FFFFFF",
NQ = "EFCFCF",
NPQ = "FFCFCF",
SP = "F1F8FF",
TP = "F1F8FF",
["0"] = ""
}

function p.colori(frame)
	local args = getArgs(frame)
	local zonapunti = tonumber(args[1])
	local ris = args[2]
	local format

	if ris == nil then
		ris = 0
	end

	local ris2 = string.gsub(ris,"'","")

	if tonumber(ris2) ~= nil and tonumber(ris2) > 3 then
   		if tonumber(ris2) <= zonapunti then
   			ris2 = "punti"
   		else ris2 = "nopunti"
   		end
	end

	local colore = tavolozza[ris2]

	if colore == nil then
		colore = ""
	end

	return "style=\"padding-left:0px;padding-right:0px;background-color:#" .. colore .. "\""
end

function p.ppgv(frame)
	local args = getArgs(frame)
	local ris = args[1]
	local apici = args[2]

	local switch = {["PG"]="'''''",["PP"]="'''",["GV"]="''"}

	if ris ~= nil then
		if switch[apici] ~= nil then
			ris = switch[apici] .. ris .. switch[apici]
		end
	end

	return ris

end

function p.sequenza(frame)

	local anno = tonumber(frame.args[1])

	if anno == nil then
		anno = "default"
	end

	local stagione = tabella[anno]

	if stagione == nil then
		stagione = tabella["default"]
	end

	local seq = stagione["gp"]
	local gareanno = stagione["gare"]
	local str = 'width=3%|' .. p.band({seq[1],anno})

	for i = 2,gareanno do
		str = str .. '||width=3%|' .. p.band({seq[i],anno})
	end

	return str

end

function p.vuote(frame)

	local anno = tonumber(frame.args[1])
	local ritiro = {tonumber(frame.args[2])}

	if anno == nil then
		anno = "default"
	end

	local stagione = tabella[anno]

	if stagione == nil then
		stagione = tabella["default"]
	end

	local max = p.max(ritiro)
	local str = ""

	if max-stagione["gare"] ~= 0 then
		for i=1,(max-stagione["gare"]) do
			str = str .. "||width=3%|&#32;"
		end
	end

	return str

end

function p.celle(frame)
	local argstmp = frame:getParent().args
	local args = getArgs(frame)
	local str = ""
	local anno = tonumber(argstmp["Anno"])

	if anno == nil then
		anno = "default"
	end

	local stagione = tabella[anno]

	if stagione == nil then
		stagione = tabella["default"]
	end

	local zonapunti = stagione["punti"]
	local lettera = args[1]
	local width1 = 'width=3% '
	local widthn = '||width=3% '
	local gare = stagione["gare"]

	local t = {}

	if lettera == nil or lettera == "" then
		for i=1,gare do
			param = i .. "R"
			t[i*3-2] = argstmp[param]
			param2 = "G" .. i
			t[i*3-1] = argstmp[param2]
			param3 = "N" .. i
			t[i*3] = argstmp[param3]
		end
	else
		for i=1,gare do
			param = lettera .. i
			t[i*3-2] = argstmp[param]
			t[i*3-1] = ""
			t[i*3] = ""
		end
	end

	for i=1,(gare*3-2),3 do
		local j=i+1
		local k=i+2
		local note = t[k]
		local col = p.colori({zonapunti,t[i]})
		local res = p.ppgv({t[i],t[j]})
		if res == nil then
			res = ""
		end
		if note == nil then
			note = ""
		end
		if i==1 then
			str = str .. width1
		else str = str .. widthn
		end
		str = str .. col .. "|&#32;" .. res .. note
	end

	return str

end

function p.max(frame)
	local args = getArgs(frame)
	local ritiro = tonumber(args[1])
	local max = 7
	local ultima = 1950

	while tabella[ultima] ~= nil do
		ultima = ultima + 1
	end
	ultima = ultima - 1

	if ritiro == nil or ritiro > ultima then
		ritiro = ultima
	end

	for i = 1951,ritiro do
		local stagione = tabella[i]
		local gare = stagione["gare"]
		if gare > max then
			max = gare
		end
	end

	return max

end

function p.band(frame)
	local args = getArgs(frame)
	local gp = args[1]
	local anno = tostring(args[2])
	local dati = tabgp[gp]
	local str = ""

	if dati == nil then
		dati = tabgp["NC"]
	end

	if anno == "nil" then
		anno = ""
	else anno = " " .. anno
	end

	str = str .. '[[File:' .. dati["file"] .. '|18px|border|link=' .. dati["nome"] .. anno .. ']]'

	return str

end

function p.gareanno(frame)
	local argstmp = frame:getParent().args
	local anno = tonumber(argstmp["Anno_di_gara"])
	local stagione = tabella[anno]
	local gareanno = 0
	if stagione ~= nil then
		gareanno = stagione["gare"]
	else
		gareanno = p.max(stagione)
	end
	return gareanno
end

return p