![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
This module calculates the proportion of articles in a given WikiProject that have been assessed for quality ratings (i.e. any articles that are not tagged as "Unassessed"), and returns this as a simple number. It is used by {{WikiProject assessment progression}} to populate the value for a progress bar that updates automatically based on category memberships.
Usage
{{#invoke:WikiProject assessment progression|main}}
When invoked by a template that supplies a parameter called "project", it will use that parameter as a WikiProject name for class-rating categories, and return the percentage of articles in those categories that are not listed as "Unassessed". This value is a number (with one decimal place) returned as a string.
See also
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