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 = {}
local calculators = {}
-- 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
function calculators.linear(n)
local topWW = n.top * (n.fa*getCount('topFA') + n.a*getCount('topA') + n.ga*getCount('topGA') + n.b*getCount('topB') + n.c*getCount('topC') + n.start*getCount('topStart') + n.stub*getCount('topStub'))
local highWW = n.high * (n.fa*getCount('highFA') + n.a*getCount('highA') + n.ga*getCount('highGA') + n.b*getCount('highB') + n.c*getCount('highC') + n.start*getCount('highStart') + n.stub*getCount('highStub'))
local midWW = n.mid * (n.fa*getCount('midFA') + n.a*getCount('midA') + n.ga*getCount('midGA') + n.b*getCount('midB') + n.c*getCount('midC') + n.start*getCount('midStart') + n.stub*getCount('midStub'))
local lowWW = n.low * (n.fa*getCount('lowFA') + n.a*getCount('lowA') + n.ga*getCount('lowGA') + n.b*getCount('lowB') + n.c*getCount('lowC') + n.start*getCount('lowStart') + n.stub*getCount('lowStub'))
return (topWW + highWW + midWW + lowWW) / total
end
function calculators.exponential(n)
local topWW = (n.fa^n.top)*getCount('topFA') + (n.a^n.top)*getCount('topA') + (n.ga^n.top)*getCount('topGA') + (n.b^n.top)*getCount('topB') + (n.c^n.top)*getCount('topC') + (n.start^n.top)*getCount('topStart') + (n.stub^n.top)*getCount('topStub')
local highWW = (n.fa^n.high)*getCount('highFA') + (n.a^n.high)*getCount('highA') + (n.ga^n.high)*getCount('highGA') + (n.b^n.high)*getCount('highB') + (n.c^n.high)*getCount('highC') + (n.start^n.high)*getCount('highStart') + (n.stub^n.high)*getCount('highStub')
local midWW = (n.fa^n.mid)*getCount('midFA') + (n.a^n.mid)*getCount('midA') + (n.ga^n.mid)*getCount('midGA') + (n.b^n.mid)*getCount('midB') + (n.c^n.mid)*getCount('midC') + (n.start^n.mid)*getCount('midStart') + (n.stub^n.mid)*getCount('midStub')
local lowWW = (n.fa^n.low)*getCount('lowFA') + (n.a^n.low)*getCount('lowA') + (n.ga^n.low)*getCount('lowGA') + (n.b^n.low)*getCount('lowB') + (n.c^n.low)*getCount('lowC') + (n.start^n.low)*getCount('lowStart') + (n.stub^n.low)*getCount('lowStub')
return (topWW + highWW + midWW + lowWW) / total
end
local function importanceAdjusted()
local constants = {top=2, high=1.5, mid=1, low=0.5, fa=0, a=1, ga=2, b=3, c=4, start=5, stub=6}
return calculators.linear(constants)
end
local function reverseImportanceAdjusted()
local constants = {top=0.5, high=1, mid=1.5, low=2, fa=0, a=1, ga=2, b=3, c=4, start=5, stub=6}
return calculators.linear(constants)
end
local function exponentialImportanceAdjusted()
local constants = {top=4, high=2, mid=1, low=0.5, fa=0, a=0.25, ga=0.5, b=1, c=2, start=3, stub=4}
return calculators.exponential(constants)
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 reverseImportanceAdjustedRatio()
return reverseImportanceAdjusted() / original()
end
-- Table definitions
local columns = {{"Ω", original},
{"Importance-adjusted WikiWork (ι)", importanceAdjusted},
{"Reverse importance-adjusted WikiWork (ν)", reverseImportanceAdjusted},
{"Importance ratio (ρ)", importanceRatio},
{"ι/Ω", importanceAdjustedRatio},
{"ν/Ω", reverseImportanceAdjustedRatio},
{"Exponential importance-adjusted WikiWork (ε)", exponentialImportanceAdjusted},
}
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