Naar inhoud springen

Module:Zandbak/Hole1988

Uit Wikipedia, de vrije encyclopedie
Dit is een oude versie van deze pagina, bewerkt door Hole1988 (overleg | bijdragen) op 2 nov 2016 om 04:15.
Deze versie kan sterk verschillen van de huidige versie van deze pagina.

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

local p = {}

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 = {["500"] = 1,
		["1000"] = 2,
		["1500"] = 3,
		["3000"] = 4,
		["5000"] = 5,
		["10000"] = 6,
		["Achtervolging"] = 10,
		["2X500"] = 20,
		["Sprint"] = 30,
		["Mini"] = 40,
		["Kleine"] = 50,
		["Grote"] = 60
	},
	links = {["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)",
		["2X500"] = nil,
		["Sprint"] = nil,
		["Mini"] = nil,
		["Kleine"] = "Kleine_vierkamp",
		["Grote"] = "Grote_vierkamp"
	},
	name = {["500"] = "500 m",
		["1000"] = "1000 m",
		["1500"] = "1500 m",
		["3000"] = "3000 m",
		["5000"] = "5000 m",
		["10000"] = "10.000 m",
		["Achtervolging"] = "Ploegenachtervolging",
		["2X500"] = nil,
		["Sprint"] = nil,
		["Mini"] = nil,
		["Kleine"] = "Kleine Vierkamp",
		["Grote"] = "Grote Vierkamp"
	},
	cat = {["500"] = 0,
		["1000"] = 0,
		["1500"] = 0,
		["3000"] = 0,
		["5000"] = 0,
		["10000"] = 0,
		["Achtervolging"] = 1,
		["2X500"] = 2,
		["Sprint"] = 2,
		["Mini"] = 2,
		["Kleine"] = 2,
		["Grote"] = 2
	}
}
punt = {}
punt.V = 0
punt.M = 0
function creattable(t,a,g,frame)
	table.insert(t,"{| class=\"wikitable\"\n")
	if g == "V" then table.insert(t,"|+ vrouwen\n")
	elseif g == "M" then table.insert(t,"|+ mannen\n")
	end
	table.insert(t,"!Afstand || Schaatser || Land || Tijd || Datum\n")
	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
	for i,n in ipairs(d) do 
	if (db.cat[n] == nil and Show.rest) or (db.cat[n] == 0 and Show.afstanden) or (db.cat[n] == 1 and Show.team) or (db.cat[n] == 2 and Show.meerkamp) then
		if Show.punten and ((g == "V" and n == "10000") or (g == "M" and n == "3000")) then 
			table.insert(t,"|- bgcolor=FF4500\n")
		else 
			table.insert(t,"|-\n")
			if a[n].Tijd and tonumber(n) and n%500 == 0 then 
				punt[g] = punt[g]+(parse(a[n].Tijd)/(n/500))
			end
		end
		if Show.links and db.links[n] then table.insert(t,"| [["..db.links[n].."|"..db.name[n].."]] || ")
		elseif db.name[n] then table.insert(t,"| "..db.name[n].." || ")
		else table.insert(t,"| "..n.." || ")
		end
		if a[n].Naam then table.insert(t,a[n].Naam) end
		table.insert(t," || ")
		if a[n].Land then table.insert(t,frame:preprocess("{{"..a[n].Land.."}}")) end
		table.insert(t," || ")
		if a[n].Tijd then table.insert(t,a[n].Tijd) end
		table.insert(t," || ")
		if a[n].Datum then table.insert(t,a[n].Datum) end
		table.insert(t,"\n")
	end
	end
	if Show.punten then table.insert(t,"|-\n|colspan=\"3\"| '''puntentotaal\n|colspan=\"2\"| '''"..string.format("%.3f",punt[g]).."\n") end
	table.insert(t,"|}\n")
	return t
end
Args = {}
Show = {
	rest = true,
	afstanden = true,
	team = false,
	meerkamp = false,
	punten = false
}
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] = {} 
				--table.insert(v,a)
			end
			r[g][a][p] = value
		end
	end
	table.insert(t,"{|\n|\n")
	if table.getn(r.V) then t = creattable(t,r.V,"V",frame) end
	if table.getn(r.V) and table.getn(r.M) then table.insert(t,"| width=\"50px\" |\n|\n") end
	if table.getn(r.M) then t = creattable(t,r.M,"M",frame) end
	if table.getn(r.V) and table.getn(r.M) and Show.punten then 
		table.insert(t,"|-\n|colspan=\"2\"| '''gezamenlijk puntentotaal || '''"..string.format("%.3f",punt.V+punt.M).."\n")
	end
	return table.concat(t).."|}"
end
return p