Module:NUMBEROF/rank

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Module documentation
-- Return a table of statistics to be accessed once per page using mw.loadData.
-- For each sister project, the table ranks each site by its number of articles.

local projects = {
	'wikipedia',
}

local function getData(statistics)
	local s, r
	for i, v in ipairs(statistics.schema.fields) do
		if v.name == 'site' then -- site, e.g. 'en'
			s = i
		elseif v.name == 'articles' then -- rank by number of articles, e.g. 1
			r = i
		end
	end
	local S, R = {}, {}
	for _, d in ipairs(statistics.data) do
		local s, r = d[s], d[r]
		S[r], R[s] = s, r
	end
	return {
		rankByIndex = S, -- S[1] == 'en'
		rankBySite = R, -- R['en'] == 1
	}
end

function makeData()
	-- For example, data to rank each language for sister project wikipedia is at
	-- https://commons.wikimedia.org/wiki/Data:Wikipedia_statistics/rank/wikipedia.tab
	local result = {}
	for _, project in ipairs(projects) do
		result[project] = getData(mw.ext.data.get('Wikipedia statistics/rank/' .. project .. '.tab'))
	end
	return result
end

return makeData()