Module:User:Happy5214/WikiWork
Appearance
To add a new WikiWork function, simply add the function to the statistics section of the module and include it in the columns table. Use getCount()
to get the number of articles with a given class and importance. The function must return a number, which will be displayed in the table on User:Happy5214/New WikiWork.
local p = {}
-- Global imports
local getArgs = require('Module:Arguments').getArgs
local math = require "Module:Math"
local round = math._precision_format
local insert = table.insert
-- Statistics
local stats, total
local top, high, mid, low
local fa, a, ga, b, c, start, stub
-- Utility
local function pad(number)
return round(tostring(number), '3')
end
local function getCount(type)
return stats[type] or 0
end
-- Setup
local function setup()
top = getCount('topFA') + getCount('topA') + getCount('topGA') + getCount('topB') + getCount('topC') + getCount('topStart') + getCount('topStub')
high = getCount('highFA') + getCount('highA') + getCount('highGA') + getCount('highB') + getCount('highC') + getCount('highStart') + getCount('highStub')
mid = getCount('midFA') + getCount('midA') + getCount('midGA') + getCount('midB') + getCount('midC') + getCount('midStart') + getCount('midStub')
low = getCount('lowFA') + getCount('lowA') + getCount('lowGA') + getCount('lowB') + getCount('lowC') + getCount('lowStart') + getCount('lowStub')
fa = getCount('topFA') + getCount('highFA') + getCount('midFA') + getCount('lowFA')
a = getCount('topA') + getCount('highA') + getCount('midA') + getCount('lowA')
ga = getCount('topGA') + getCount('highGA') + getCount('midGA') + getCount('lowGA')
b = getCount('topB') + getCount('highB') + getCount('midB') + getCount('lowB')
c = getCount('topC') + getCount('highC') + getCount('midC') + getCount('lowC')
start = getCount('topStart') + getCount('highStart') + getCount('midStart') + getCount('lowStart')
stub = getCount('topStub') + getCount('highStub') + getCount('midStub') + getCount('lowStub')
total = top + high + mid + low
end
-- Statistics
local function original()
return (a + 2*ga + 3*b + 4*c + 5*start + 6*stub) / total
end
local function importanceAdjusted()
local topWW = 2 * (getCount('topA') + 2*getCount('topGA') + 3*getCount('topB') + 4*getCount('topC') + 5*getCount('topStart') + 6*getCount('topStub'))
local highWW = 1.5 * (getCount('highA') + 2*getCount('highGA') + 3*getCount('highB') + 4*getCount('highC') + 5*getCount('highStart') + 6*getCount('highStub'))
local midWW = 1 * (getCount('midA') + 2*getCount('midGA') + 3*getCount('midB') + 4*getCount('midC') + 5*getCount('midStart') + 6*getCount('midStub'))
local lowWW = 0.5 * (getCount('lowA') + 2*getCount('lowGA') + 3*getCount('lowB') + 4*getCount('lowC') + 5*getCount('lowStart') + 6*getCount('lowStub'))
return (topWW + highWW + midWW + lowWW) / total
end
local function newImportanceAdjusted()
local topWW = 0.5 * (getCount('topA') + 2*getCount('topGA') + 3*getCount('topB') + 4*getCount('topC') + 5*getCount('topStart') + 6*getCount('topStub'))
local highWW = 1 * (getCount('highA') + 2*getCount('highGA') + 3*getCount('highB') + 4*getCount('highC') + 5*getCount('highStart') + 6*getCount('highStub'))
local midWW = 1.5 * (getCount('midA') + 2*getCount('midGA') + 3*getCount('midB') + 4*getCount('midC') + 5*getCount('midStart') + 6*getCount('midStub'))
local lowWW = 2 * (getCount('lowA') + 2*getCount('lowGA') + 3*getCount('lowB') + 4*getCount('lowC') + 5*getCount('lowStart') + 6*getCount('lowStub'))
return (topWW + highWW + midWW + lowWW) / total
end
local function importanceRatio()
return (2*top + 1.5*high + 1*mid + 0.5*low) / total
end
local function importanceAdjustedRatio()
return importanceAdjusted() / original()
end
local function newImportanceAdjustedRatio()
return newImportanceAdjusted() / original()
end
-- Table definitions
local columns = {{"Ω", original},
{"Importance-adjusted WikiWork (ι)", importanceAdjusted},
{"New importance-adjusted WikiWork (ν)", newImportanceAdjusted},
{"Importance ratio (ρ)", importanceRatio},
{"ι/Ω", importanceAdjustedRatio},
{"ν/Ω", newImportanceAdjustedRatio},
}
function p._wikiwork()
setup()
local cells = {}
for k,v in ipairs(columns) do
insert(cells, pad(v[2]()))
end
return '| ' .. table.concat(cells, ' || ')
end
function p.wikiwork(frame)
stats = getArgs(frame)
return p._wikiwork()
end
function p.header(frame)
local headers = {}
for k,v in ipairs(columns) do
insert(headers, v[1])
end
return '! ' .. table.concat(headers, ' !! ')
end
return p