Jump to content

Module:User:Happy5214/WikiWork

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 09:05, 4 May 2014 (Initial version). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}
local getArgs = require('Module:Arguments').getArgs
local math = require "Module:Math"
local round = math._precision_format

local stats, total
local top, high, mid, low
local fa, a, ga, b, c, start, stub

local function pad(number)
	return round(tostring(number), '3')
end

local function getCount(type)
	return stats[type] or 0
end

local function setup()
	top = getCount('topFA') + getCount('topA') + getCount('topGA') + getCount('topB') + getCount('topC') + getCount('topStart') + getCount('topStub')
	high = getCount('highFA') + getCount('highA') + getCount('highGA') + getCount('highB') + getCount('highC') + getCount('highStart') + getCount('highStub')
	mid = getCount('midFA') + getCount('midA') + getCount('midGA') + getCount('midB') + getCount('midC') + getCount('midStart') + getCount('midStub')
	low = getCount('lowFA') + getCount('lowA') + getCount('lowGA') + getCount('lowB') + getCount('lowC') + getCount('lowStart') + getCount('lowStub')
	fa = getCount('topFA') + getCount('highFA') + getCount('midFA') + getCount('lowFA')
	a = getCount('topA') + getCount('highA') + getCount('midA') + getCount('lowA')
	ga = getCount('topGA') + getCount('highGA') + getCount('midGA') + getCount('lowGA')
	b = getCount('topB') + getCount('highB') + getCount('midB') + getCount('lowB')
	c = getCount('topC') + getCount('highC') + getCount('midC') + getCount('lowC')
	start = getCount('topStart') + getCount('highStart') + getCount('midStart') + getCount('lowStart')
	stub = getCount('topStub') + getCount('highStub') + getCount('midStub') + getCount('lowStub')
	total = top + high + mid + low
end

local function original()
	return (a + 2*ga + 3*b + 4*c + 5*start + 6*stub) / total
end

function p._wikiwork()
	local insert = table.insert
	setup()
	local cells = {}
	local omega = original()
	insert(cells, pad(omega))
	return '|| ' .. table.concat(cells, ' || ')
end

function p.wikiwork(frame)
	stats = getArgs(frame)
	return p._wikiwork()
end

return p