Documentation for this module may be created at Module:USRD Leaderboard/doc

-- This module's function lookup table, used by the calling context
local p = {}
local formatnum = require("Module:Formatnum")
local format = mw.ustring.format

local projectList = {
	["IH"] = {"Interstate Highway System", "Interstates", "silver"},
	["US"] = {"U.S. Highway system", "U.S. Highways", "silver"},
	["AT"] = {"U.S. auto trail", "Auto trails", "silver"},
	["AL"] = {"Alabama road transport", "Alabama"},
	["AK"] = {"Alaska road transport", "Alaska"},
	["AS"] = {"American Samoa road transport", "American Samoa", "silver"},
	["AZ"] = {"Arizona road transport", "Arizona"},
	["AR"] = {"Arkansas road transport", "Arkansas"},
	["CA"] = {"California road transport", "California"},
	["CO"] = {"Colorado road transport", "Colorado"},
	["CT"] = {"Connecticut road transport", "Connecticut"},
	["DE"] = {"Delaware road transport", "Delaware"},
	["DC"] = {"District of Columbia road transport", "D.C.", "silver"},
	["FL"] = {"Florida road transport", "Florida"},
	["GA"] = {"Georgia (U.S. state) road transport", "Georgia"},
	["GU"] = {"Guam road transport", "Guam", "silver"},
	["HI"] = {"Hawaii road transport", "Hawaii"},
	["ID"] = {"Idaho road transport", "Idaho"},
	["IL"] = {"Illinois road transport", "Illinois"},
	["IN"] = {"Indiana road transport", "Indiana"},
	["IA"] = {"Iowa road transport", "Iowa"},
	["KS"] = {"Kansas road transport", "Kansas"},
	["KY"] = {"Kentucky road transport", "Kentucky"},
	["LA"] = {"Louisiana road transport", "Louisiana"},
	["ME"] = {"Maine road transport", "Maine"},
	["MD"] = {"Maryland road transport", "Maryland"},
	["MA"] = {"Massachusetts road transport", "Massachusetts"},
	["MI"] = {"Michigan road transport", "Michigan"},
	["MN"] = {"Minnesota road transport", "Minnesota"},
	["MS"] = {"Mississippi road transport", "Mississippi"},
	["MO"] = {"Missouri road transport", "Missouri"},
	["MT"] = {"Montana road transport", "Montana"},
	["NE"] = {"Nebraska road transport", "Nebraska"},
	["NV"] = {"Nevada road transport", "Nevada"},
	["NH"] = {"New Hampshire road transport", "New Hampshire"},
	["NJ"] = {"New Jersey road transport", "New Jersey"},
	["NM"] = {"New Mexico road transport", "New Mexico"},
	["NY"] = {"New York road transport", "New York"},
	["NC"] = {"North Carolina road transport", "North Carolina"},
	["ND"] = {"North Dakota road transport", "North Dakota"},
	["OH"] = {"Ohio road transport", "Ohio"},
	["OK"] = {"Oklahoma road transport", "Oklahoma"},
	["OR"] = {"Oregon road transport", "Oregon"},
	["PA"] = {"Pennsylvania road transport", "Pennsylvania"},
	["PR"] = {"Puerto Rico road transport", "Puerto Rico", "silver"},
	["RI"] = {"Rhode Island road transport", "Rhode Island"},
	["SC"] = {"South Carolina road transport", "South Carolina"},
	["SD"] = {"South Dakota road transport", "South Dakota"},
	["TN"] = {"Tennessee road transport", "Tennessee"},
	["TX"] = {"Texas road transport", "Texas"},
	["VI"] = {"U.S. Virgin Islands road transport", "U.S. Virgin Islands", "silver"},
	["UT"] = {"Utah road transport", "Utah"},
	["VT"] = {"Vermont road transport", "Vermont"},
	["VA"] = {"Virginia road transport", "Virginia"},
	["WA"] = {"Washington road transport", "Washington"},
	["WV"] = {"West Virginia road transport", "West Virginia"},
	["WI"] = {"Wisconsin road transport", "Wisconsin"},
	["WY"] = {"Wyoming road transport", "Wyoming"},
	["RD"] = {"U.S. road transport", "USRD Project", "#ddffdd"},
	["CR"] = {"U.S. county road", "County roads", "silver"},
	["JCT"] = {"U.S. road junction", "Junctions", "silver"},
	["66"] = {"U.S. Route 66", "Route 66", "silver"},
	["AB"] = {"Alberta road transport", "Alberta"},
	["BC"] = {"British Columbia road transport", "British Columbia"},
	["MB"] = {"Manitoba road transport", "Manitoba"},
	["NB"] = {"New Brunswick road transport", "New Brunswick"},
	["NL"] = {"Newfoundland and Labrador road transport", "Newfoundland and Labrador"},
	["NS"] = {"Nova Scotia road transport", "Nova Scotia"},
	["ON"] = {"Ontario road transport", "Ontario"},
	["PE"] = {"Prince Edward Island road transport", "Prince Edward Island"},
	["QC"] = {"Quebec road transport", "Québec"},
	["SK"] = {"Saskatchewan road transport", "Saskatchewan"},
	["NT"] = {"Northwest Territories road transport", "Northwest Territories"},
	["NU"] = {"Nunavut road transport", "Nunavut"},
	["YT"] = {"Yukon road transport", "Yukon"},
	["TCH"] = {"Trans-Canada Highway", "TCH", "silver"},
	["CARD"] = {"Canada road transport", "Canada", "silver"},
	["AFR"] = {"Africa road transport", "Africa", "silver"},
	["ASIA"] = {"Asia road transport", "Asia", "silver"},
	["AUS"] = {"Australia road transport", "Australia"},
	["CAN"] = {"Canada road transport", "Canada"},
	["EUR"] = {"Europe road transport", "Europe", "silver"},
	["HKG"] = {"Hong Kong road transport", "Hong Kong"},
	["IND"] = {"India road transport", "India"},
	["LAT"] = {"Latin America road transport", "Latin America", "silver"},
	["OCN"] = {"Oceania road transport", "Oceania", "silver"},
	["UK"] = {"UK road transport", "United Kingdom", "silver"},
	["USA"] = {"U.S. road transport", "United States"},
	["HWY"] = {"Highways", "Highways", "#99ccff"},
	["ALL"] = {"Road transport", "All Roads", "#ffcc99"},
}

function p.wikiwork(frame)

-- Determine the WikiProject for which to grab stats.
	local topic = frame.args[1]
	
	local list = projectList[topic]

	-- WP 1.0 category names follow the pattern "<class>-Class <topic> articles".
	local cSuffix = "-Class " .. list[1] .. " articles"

	-- Get the article counts for each handled class.
	local qFA = mw.site.stats.pagesInCategory("FA"		.. cSuffix, "pages")
	local qA = mw.site.stats.pagesInCategory("A"		 .. cSuffix, "pages")
	local qGA = mw.site.stats.pagesInCategory("GA"		.. cSuffix, "pages")
	local qB = mw.site.stats.pagesInCategory("B"		 .. cSuffix, "pages")
	local qC = mw.site.stats.pagesInCategory("C"		 .. cSuffix, "pages")
	local qStart = mw.site.stats.pagesInCategory("Start" .. cSuffix, "pages")
	local qStub	= mw.site.stats.pagesInCategory("Stub"	.. cSuffix, "pages")

	-- Sum of all class article counts; i.e. all articles in scope of the WikiProject.
	local total = qFA + qA + qGA + qB + qC + qStart + qStub
	
	-- Total WikiWork; weighted average based on class of all articles.
	local totWW = ((qFA * 0) + qA + (qGA * 2) + (qB * 3) + (qC * 4) + (qStart * 5) + (qStub * 6))
	
	local totalWW = formatnum.formatNum(totWW, 'en')
	
	-- Relative WikiWork; Total WikiWork ÷ total number of articles
	local relWW = (totWW / total)
	
	local relativeWW = formatnum.formatNum(relWW, 'en', 3)
	
	local link = tostring("[[Wikipedia:Version 1.0 Editorial Team/".. list[1] .. " articles by quality statistics|" .. list[2] .. "]]")
	
	-- Formatted numbers for the table
	local fFA = formatnum.formatNum(qFA, 'en')
	local fA = formatnum.formatNum(qA, 'en')
	local fGA = formatnum.formatNum(qGA, 'en')
	local fB = formatnum.formatNum(qB, 'en')
	local fC = formatnum.formatNum(qC, 'en')
	local fStart = formatnum.formatNum(qStart, 'en')
	local fStub	= formatnum.formatNum(qStub, 'en')
	local fTotal = formatnum.formatNum(total, 'en')

	--Create the wikitext output and return it to the calling template.
	if list[3] then
		local format = [=[background-color: %s !important -- '''%s''' -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s]=]
		return mw.ustring.format(format, list[3], link, fFA, fA, fGA, fB, fC, fStart, fStub, fTotal, totalWW, relativeWW)
	else
		local format = [=[-- '''%s''' -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s]=]
		return mw.ustring.format(format, link, fFA, fA, fGA, fB, fC, fStart, fStub, fTotal, totalWW, relativeWW)
	end

end

return p