İçeriğe atla

Modül:İstatistikToplama

Sanarşiv, sanat ansiklopedisi

Bu modül için bir Modül:İstatistikToplama/belge belgelendirmesi oluşturabilirsiniz

local p = {}

function p.sumFields(frame)
	local parent = frame:getParent()
	local args = parent.args
	local prefix = frame.args.prefix or "maç"
	local max = tonumber(frame.args.max) or 39
	local wrap = frame.args.wrap or ""
	local paren = frame.args.paren == "true"

	local sum = 0
	local found_any = false
	local invalid_found = false

	for i = 1, max do
		local v = args[prefix .. i]
		if v then
		v = mw.text.trim(v)
		v = v:gsub("%s+", ""):gsub(",", ".")
		mw.log(tonumber(v))
			found_any = true
			if tonumber(v)==nil  then
				invalid_found = true
				break
			else
				sum = sum + tonumber(v)
			end
		
		
		end
	end

	if not found_any or invalid_found then
		return "" -- 
	end

	local out = tostring(sum)
	if paren then out = "(" .. out .. ")" end
	if wrap == "bold" then out = "'''" .. out .. "'''" end
	return out
end

return p