Module:WikiProject assessment progression

This is an old revision of this page, as edited by Sasuke Sarutobi (talk | contribs) at 22:57, 2 December 2020 (Initial version (largely based on Module:Progression rainbow by User:Izno)). 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)

require('Module:No globals')

local p = {}

local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {
	valueFunc = function (key, value)
		value = mw.ustring.lower(value)
	end
})
local project = args.value

local function categoryCount(category)
	return mw.site.stats.pagesInCategory(
		string.format('%s %s articles', category, project),
		'pages'
	)
end

local function round(num)
	return math.floor(num * 10 + 0.5) / 10
end

local function percentComplete(sum, total)
	return tostring(round(100 * sum / total))
end

function p.main(frame)
	local classes = {
		{count = 0, class = 'List', category = 'List-Class'},
		{count = 0, class = 'Stub', category = 'Stub-Class'},
		{count = 0, class = 'Start', category = 'Start-Class'},
		{count = 0, class = 'C', category = 'C-Class'},
		{count = 0, class = 'B', category = 'B-Class'},
		{count = 0, class = 'GA', category = 'GA-Class'},
		{count = 0, class = 'A', category = 'A-Class'},
		{count = 0, class = 'FA', category = 'FA-Class'},
		{count = 0, class = 'FL', category = 'FL-Class'},
		{count = 0, class = 'Unassessed', category = 'Unassessed'},
	}
	local classCount = 0
	
	for _, class in ipairs(classes) do
		if (class.class == 'Unassessed') then 
			classCount = classCount
		else 
			classCount = classCount + categoryCount(class.category)
		end
	end
	
	local total = classCount + categoryCount('Unassessed')
	return percentComplete(classCount, total)
end

return p