Jump to content

Module:WikiProject metrics: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m should work now
add chart
Line 1: Line 1:
local p = {}
local p = {}


local Date = require('Module:Date')._Date
local Date = require("Module:Date")._Date
local lang = mw.language.new(mw.language.getContentLanguage().code)


local function getMonths(start)
local function getMonths(start)
Line 28: Line 29:
local months = getMonths(startMonth)
local months = getMonths(startMonth)
local list = {}
local list = {}

local lang = mw.language.new(mw.language.getContentLanguage().code)


for i, month in pairs(months) do
for i, month in pairs(months) do
Line 53: Line 52:


function p.chart(frame)
function p.chart(frame)
local baseTitle = frame:getParent():getTitle()
return "who needs graphs anyway?"
local startMonth = frame.args[1]

local months = getMonths(startMonth)
local xdata = {}
local ydata = {}

for i, month in pairs(months) do
local title = baseTitle .. "/" .. month:text("%B %Y")
local count = frame:preprocess("{{#lst:" .. title .. "|count}}")
table.insert(xdata, month:text("%b %Y"))
table.insert(ydata, count)
end

local chart = frame:expandTemplate{ title = "Graph:Chart", args = {
width = "600",
height = "200",
type = "line",
xAxisTitle = "Month",
yAxisTitle = "Number of articles created",
xType = "date",
yAxisMin = "0",
x = table.concat(xdata, ","),
y = table.concat(ydata, ",")
}}

local div = '<div style="text-align: center; margin: auto;">%s</div>'
return string.format(div, chart)
end
end



Revision as of 14:23, 28 July 2016

local p = {}

local Date = require("Module:Date")._Date
local lang = mw.language.new(mw.language.getContentLanguage().code)

local function getMonths(start)
	local month = Date("1 " .. start)
	local current = Date("currentdate")
	current = Date(current.year, current.month, 1)

	if month > current then
		return {}
	end

	local months = {month}

	while month < current do
		month = month + "1 month"
		table.insert(months, month)
	end

	return months
end

function p.list(frame)
	local baseTitle = frame:getParent():getTitle()
	local startMonth = frame.args[1]

	local months = getMonths(startMonth)
	local list = {}

	for i, month in pairs(months) do
		if i == 1 or month:text("%B") == "January" then
			local tag = '<span style="font-size: 120%%;">%s</span>'
			table.insert(list,  string.format(tag, month:text("%Y")))
		end

		local line = "* [[%s|%s]]: %s"
		local title = baseTitle .. "/" .. month:text("%B %Y")
		local count = frame:preprocess("{{#lst:" .. title .. "|count}}")
		count = lang:formatNum(tonumber(count))
		local item = string.format(line, title, month:text("%b"), count)
		table.insert(list, item)
	end

	return table.concat(list, "\n")
end

function p.recent(frame)
	return "nothing at all! :("
end

function p.chart(frame)
	local baseTitle = frame:getParent():getTitle()
	local startMonth = frame.args[1]

	local months = getMonths(startMonth)
	local xdata = {}
	local ydata = {}

	for i, month in pairs(months) do
		local title = baseTitle .. "/" .. month:text("%B %Y")
		local count = frame:preprocess("{{#lst:" .. title .. "|count}}")
		
		table.insert(xdata, month:text("%b %Y"))
		table.insert(ydata, count)
	end

	local chart = frame:expandTemplate{ title = "Graph:Chart", args = {
		width = "600",
		height = "200",
		type = "line",
		xAxisTitle = "Month",
		yAxisTitle = "Number of articles created",
		xType = "date",
		yAxisMin = "0",
		x = table.concat(xdata, ","),
		y = table.concat(ydata, ",")
	}}

	local div = '<div style="text-align: center; margin: auto;">%s</div>'
	return string.format(div, chart)
end

return p