Naar inhoud springen

Module:Zandbak/Hole1988

Uit Wikipedia, de vrije encyclopedie

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Zandbak/Hole1988/doc

local p = {}
bit = require( 'bit32' )
function nul(nr)
	if nr == nil then
		return 0
	else
		return nr
	end
end

function parse(time)
	if(time == nil or string.len(time) == 0) then return 0 end
	s, h = string.match(time, "(%d+),(%d+)")
	m = string.match(time, "(%d+)%.")
	m = nul(m) 
	s = nul(s)
	h = nul(h)
	return ((m*60)+s) .. "." .. h
	
end
db = {
	pos = {
		["100"] = 0,
		["500"] = 1,
		["1000"] = 2,
		["1500"] = 3,
		["3000"] = 4,
		["5000"] = 5,
		["10000"] = 6,
		["Achtervolging"] = 10,
		["Teamsprint"] = 15,
		["2X500"] = 20,
		["Sprint"] = 30,
		["Mini"] = 40,
		["Kleine"] = 50,
		["Grote"] = 60
	},
	links = {
		["100"] = "100_meter_(schaatsen)",
		["500"] = "500_meter_(schaatsen)",
		["1000"] = "1000_meter_(schaatsen)",
		["1500"] = "1500_meter_(schaatsen)",
		["3000"] = "3000_meter_(schaatsen)",
		["5000"] = "5000_meter_(schaatsen)",
		["10000"] = "10.000_meter_(schaatsen)",
		["Achtervolging"] = "Ploegenachtervolging_(schaatsen)",
		["Teamsprint"] = "Teamsprint_(schaatsen)",
		["2X500"] = nil,
		["Sprint"] = nil,
		["Mini"] = nil,
		["Kleine"] = "Kleine_vierkamp",
		["Grote"] = "Grote_vierkamp"
	},
	name = {
		["100"] = "100 m",
		["500"] = "500 m",
		["1000"] = "1000 m",
		["1500"] = "1500 m",
		["3000"] = "3000 m",
		["5000"] = "5000 m",
		["10000"] = "10.000 m",
		["Achtervolging"] = "Ploegenachtervolging",
		["2X500"] = "2x 500 m",
		["Sprint"] = "Sprint Vierkamp",
		["Mini"] = "Mini Vierkamp",
		["Kleine"] = "Kleine Vierkamp",
		["Grote"] = "Grote Vierkamp"
	},
	cat = {
		["100"] = 12,
		["500"] = 3,
		["1000"] = 3,
		["1500"] = 3,
		["3000"] = 9,
		["5000"] = 3,
		["10000"] = 6,
		["Achtervolging"] = 12,
		["Teamsprint"] = 12,
		["2X500"] = 12,
		["Sprint"] = 12,
		["Mini"] = 12,
		["Kleine"] = 12,
		["Grote"] = 12
	},
    bit = {
    	["V"] = 5,
    	["M"] = 10
    }
}
punt = {}
punt.V = 0
punt.M = 0
function creattable(t,a,g,frame)
	table.insert(t,"{| class=\"wikitable\"")
	if g == "V" then table.insert(t,"|+ vrouwen")
	elseif g == "M" then table.insert(t,"|+ mannen")
	end
	local l = ""
	if g == "V" then l = "Schaatsster"
	elseif g == "M" then l = "Schaatser"
	end
	table.insert(t,"!Afstand || "..l.." || Land || Tijd || Datum")
	local d = {}
	local c = {}
	for key,value in pairs(a)  do 
		if db.pos[key] then table.insert(d, key)
		else table.insert(c, key) end
	end
	table.sort(d,function(a,b)
		return tonumber(db.pos[b]) > tonumber(db.pos[a])
	end)
	table.sort(c)
	for i,n in ipairs(c) do table.insert(d,n) end
	local p = true
	for i,n in ipairs(d) do 
		if Show.punten and p and db.pos[n] > 9 then
			p = false
			table.insert(t,"|-\n|colspan=\"3\"| '''puntentotaal\n|colspan=\"2\"| '''"..string.format("%.3f",punt[g]))
		end
		if db.cat[n] == nil then db.cat[n] = 256 end
		if a[n].Tijd and bit.band(db.bit[g],db.cat[n],3) ~= 0 then 
			punt[g] = punt[g]+(parse(a[n].Tijd)/(n/500))
		end
		if (bit.band(db.bit[g],db.cat[n],12) ~= 0 and Show.rest) or (bit.band(db.bit[g],db.cat[n],3) ~= 0 and Show.afstanden)  then
			if Show.punten and bit.band(db.bit[g],db.cat[n],3) == 0 and db.pos[n] < 10 then 
				table.insert(t,"|- bgcolor=FF4500")
			else 
				table.insert(t,"|-")
			end
			local l = "|"
			if Show.links and db.links[n] then l = l.."[["..db.links[n].."|"..db.name[n].."]]"
			elseif db.name[n] then l = l..db.name[n]
			elseif a[n].Afstanden == nil then l = l..n
			end
			if a[n].Titel then 
				if string.len(l) > 1 then l = l.."<br/>" end
				l = l..a[n].Afstanden
			end
			l = l.." || "
			if a[n].Naam then l = l..a[n].Naam end
			l = l.." || "
			if a[n].Land then l = l..a[n].Land end
			l = l.." || "
			if a[n].Tijd then l = l..a[n].Tijd end
			l = l.." || "
			if a[n].Datum then l = l..a[n].Datum end
			table.insert(t,l)
		end
	end
	if Show.punten and p then
		table.insert(t,"|-\n|colspan=\"3\"| '''puntentotaal\n|colspan=\"2\"| '''"..string.format("%.3f",punt[g]))
	end
	table.insert(t,"|}")
	return t
end
Args = {}
Show = {
	rest = true,
	afstanden = true,
	punten = false,
	mannen = true,
	vrouwen = true,
	tabel = true
}
function p.main(frame)
	Args = frame.args
	t = {}
	local r = {}
	r.V = {}
	r.M = {}
	for key,value in pairs(Args) do 
		s = string.match(key, "show_(.*)")
		if s and value == "1"  then 
			Show[s] = true
		end
		if s and value == "0"  then 
			Show[s] = false
		end
		g,a,p = string.match(key, "([^_]*)_(.*)_([^_]*)")
		if g and a and p then
			if r[g][a] == nil then 
				r[g][a] = {} 
			end
			r[g][a][p] = value
		end
	end
	local vr = (table.getn(r.V) and Show.vrouwen)
	local ma = (table.getn(r.M) and Show.mannen)
	local ta = (Show.tabel)
	if ta then table.insert(t,"{|\n| valign=\"top\" |") end
	if vr then t = creattable(t,r.V,"V",frame) end
	if vr and ma and ta then table.insert(t,"| width=\"50px\" |\n| valign=\"top\" |") end
	if ma then t = creattable(t,r.M,"M",frame) end
	if vr and ma and ta and Show.punten then 
		table.insert(t,"|-\n|colspan=\"2\"| '''gezamenlijk puntentotaal || '''"..string.format("%.3f",punt.V+punt.M))
	end
	if ta then table.insert(t,"|}") end
	return table.concat(t,"\n")
end
return p