Module:WikiProject metrics explained

local p =

local Date = require("Module:Date")._Datelocal 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 =

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

return monthsend

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 = '

%s' table.insert(list, string.format(tag, month:text("%Y"))) end

local line = "* %s: %s" local title = baseTitle .. "/" .. month:text("%B %Y")

if mw.title.new(title).exists then local count = frame:preprocess("") count = lang:formatNum(tonumber(count)) local item = string.format(line, title, month:text("%b"), count) table.insert(list, item) end end

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

local function getList(frame, baseTitle, month, cols) local title = baseTitle .. "/" .. month:text("%B %Y")

if not mw.title.new(title).exists then return "" end

local list = frame:preprocess("") local output = string.format("

%s

\n", month:text("%B %Y"))

output = output .. frame:expandTemplate

if cols ~= nil then local div = '\n

' output = output .. string.format(div, cols, cols, cols) end

output = output .. "\n" .. list

if cols ~= nil then output = output .. "\n

" end

return outputend

function p.recent(frame) local baseTitle = frame:getParent:getTitle local cols = frame.args[1] local now = Date("currentdate") local output = getList(frame, baseTitle, now, cols) if now.day < 10 then local older = getList(frame, baseTitle, now - "1 month", cols) output = output .. "\n" .. older end return outputend

function p.chart(frame) local baseTitle = frame:getParent:getTitle local startMonth = frame.args[1] local now = Date("currentdate") local currentMonth = Date(now.year, now.month, 1)

local months = getMonths(startMonth) local xdata = local y1data = local y2data =

for i, month in pairs(months) do local title = baseTitle .. "/" .. month:text("%B %Y") if mw.title.new(title).exists then local count = frame:preprocess("") mw.logObject(count) table.insert(xdata, month:text("%Y-%m-%d")) table.insert(y1data, count) if month ~= currentMonth then table.insert(y2data, count) end end end

local chart = frame:expandTemplate

local div = '

%s

' return string.format(div, chart)end

return p