Jump to content

Module:Wikipedia:WikiProject U.S. Roads/Assessment/States/Live

From Wikipedia, the free encyclopedia
local p = {}

local classes = {'FA', 'A', 'GA', 'B', 'C', 'Start', 'Stub'}

do
	local _pagesInCat = mw.site.stats.pagesInCategory
	function pagesInCat(name)
		return _pagesInCat(name, 'pages')
	end
end

local function pageCounts(project)
	local counts = {}
	for _,class in pairs(classes) do
		local category = string.format("%s-Class %s articles", class, project)
		counts[class] = pagesInCat(category)
	end
	return counts
end

local function totalPageCount(counts)
	return counts.FA + counts.A + counts.GA + counts.B + counts.C + counts.Start + counts.Stub
end

local function totalWikiwork(counts)
	return counts.A + 2*counts.GA + 3*counts.B + 4*counts.C + 5*counts.Start + 6*counts.Stub
end

function p._row(args)
	local insert = table.insert
	local format = string.format
	local cells = {}
	local rowHeader
	if args.gray then
		rowHeader = "|- bgcolor='silver'"
	else
		rowHeader = "|-"
	end
	insert(cells, rowHeader)

	local state = args.state
	local project = state and format("%s road transport", state) or args.project
	local abbr = args.abbr or state

	insert(cells, format("|'''[[Wikipedia:Version 1.0 Editorial Team/%s articles by quality statistics|%s]]'''", project, abbr))

	local counts = pageCounts(project)
	for _,class in ipairs(classes) do
		insert(cells, format("|align='center'|[[:Category:%s-Class %s articles|%s]]", class, project, counts[class]))
	end

	local totalCount = totalPageCount(counts)
	insert(cells, format("|align='center'|%s", totalCount))

	local totalWW = totalWikiwork(counts)
	insert(cells, format("|align='right'|%s", totalWW))

	local roundedWW
	if totalCount > 0 then
		local relativeWW = totalWW / totalCount
		local math = require "Module:Math"
		local round = math._precision_format
		roundedWW = round(tostring(relativeWW), "3")
	else
		roundedWW = '0.000'
	end
	insert(cells, format("|align='right'|%s", roundedWW))

	return table.concat(cells, '\n')
end

function p.row(frame)
	local argsModule = require('Module:Arguments')
	local args = argsModule.getArgs(frame)
	return p._row(args)
end

return p