Jump to content

Module:Service award progress

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Primefac (talk | contribs) at 22:43, 27 June 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local function stripToNil(text)
	-- If text is a string, return its trimmed content, or nil if empty.
	-- Otherwise return text (which may, for example, be nil).
	if type(text) == 'string' then
		text = text:match('(%S.-)%s*$')
	end
	return text
end
local function progressBar(current, total)
	local percentDone = math.floor(current / total * 100)
	local leftBar = ''
	local rightBar = ''
	if percentDone >= 100 then
		leftBar = 100
		rightBar = 0
	else
		leftBar = current / total * 100
		rightBar = (100-current) / total * 100
	end
	local progBarText = '<div style="width:75%; margin:auto; text-align:center;">' ..
			'<p><span style="font-size: 120%;"><b>' .. percentDone .. '%</b></span> completed</p>' ..
			'<p style="border:1px solid #c8ccd1; padding:1px; overflow:hidden;">' ..
			'<span style="width: ' .. leftBar .. '%; height: 2px; background:#00af32; float:left;">&nbsp;</span>' ..
			'<span style="width: ' .. rightBar .. '%; height: 2px; background:#eaecf0; float:left;">&nbsp;</span>' ..
			'</p></div>'
	
	return progBarText
end
local levelNames = {
	"Wikipedian",
	"[[Wikipedia:Service awards#Registered Editor (or Signator)|Registered Editor]]",
	"[[Wikipedia:Service awards#Registered Editor (or Signator)|Registered Editor, level 2]]",
	"[[Wikipedia:Service awards#Registered Editor (or Signator)|Registered Editor, level 3]]",
	"[[Wikipedia:Service awards#Registered Editor (or Signator)|Registered Editor, level 4]]",
	"[[Wikipedia:Service awards#Novice Editor (or Burba)|Novice Editor]]",
	"[[Wikipedia:Service awards#Novice Editor (or Burba)|Novice Editor, level 2]]",
	"[[Wikipedia:Service awards#Novice Editor (or Burba)|Novice Editor, level 3]]",
	"[[Wikipedia:Service awards#Novice Editor (or Burba)|Novice Editor, level 4]]",
	"[[Wikipedia:Service awards#Apprentice Editor (or Novato)|Apprentice Editor]]",
	"[[Wikipedia:Service awards#Apprentice Editor (or Novato)|Apprentice Editor, level 2]]",
	"[[Wikipedia:Service awards#Apprentice Editor (or Novato)|Apprentice Editor, level 3]]",
	"[[Wikipedia:Service awards#Apprentice Editor (or Novato)|Apprentice Editor, level 4]]",
	"[[Wikipedia:Service awards#Journeyman Editor (or Grognard)|Journeyman Editor]]",
	"[[Wikipedia:Service awards#Journeyman Editor (or Grognard)|Journeyman Editor, level 2]]",
	"[[Wikipedia:Service awards#Journeyman Editor (or Grognard)|Journeyman Editor, level 3]]",
	"[[Wikipedia:Service awards#Journeyman Editor (or Grognard)|Journeyman Editor, level 4]]",
	"[[Wikipedia:Service awards#Yeoman Editor (or Grognard Extraordinaire)|Yeoman Editor]]",
	"[[Wikipedia:Service awards#Yeoman Editor (or Grognard Extraordinaire)|Yeoman Editor, level 2]]",
	"[[Wikipedia:Service awards#Yeoman Editor (or Grognard Extraordinaire)|Yeoman Editor, level 3]]",
	"[[Wikipedia:Service awards#Yeoman Editor (or Grognard Extraordinaire)|Yeoman Editor, level 4]]",
	"[[Wikipedia:Service awards#Experienced Editor (or Grognard Mirabilaire)|Experienced Editor]]",
	"[[Wikipedia:Service awards#Veteran Editor (or Tutnum)|Veteran Editor]]",
	"[[Wikipedia:Service awards#Veteran Editor II (or Grand Tutnum)|Veteran Editor II]]",
	"[[Wikipedia:Service awards#Veteran Editor III (or Most Perfect Tutnum)|Veteran Editor III]]",
	"[[Wikipedia:Service awards#Veteran Editor IV (or Tutnum of the Encyclopedia)|Veteran Editor IV]]",
	"[[Wikipedia:Service awards#Senior Editor (or Labutnum)|Senior Editor]]",
	"[[Wikipedia:Service awards#Senior Editor II (or Most Pluperfect Labutnum)|Senior Editor II]]",
	"[[Wikipedia:Service awards#Senior Editor III (or Labutnum of the Encyclopedia)|Senior Editor III]]",
	"[[Wikipedia:Service awards#Master Editor (or Illustrious Looshpah)|Master Editor]]",
	"[[Wikipedia:Service awards#Master Editor II (or Auspicious Looshpah)|Master Editor II]]",
	"[[Wikipedia:Service awards#Master Editor III (or Most Plusquamperfect Looshpah Laureate)|Master Editor III]]",
	"[[Wikipedia:Service awards#Master Editor IV (or Looshpah Laureate of the Encyclopedia)|Master Editor IV]]",
	"[[Wikipedia:Service awards#Grandmaster Editor (or Lord High Togneme Vicarus)|Grandmaster Editor]]",
	"[[Wikipedia:Service awards#Grandmaster Editor First-Class (or Lord High Togneme Laureate)|Grandmaster Editor First-Class]]",
	"[[Wikipedia:Service awards#Vanguard Editor (or Lord Gom, the Highest Togneme of the Encyclopedia)|Vanguard Editor]]",
	"[[Wikipedia:Service awards#Senior Vanguard Editor (or Supreme Gom, the Most Exalted Togneme of the Encyclopedia)|Senior Vanguard Editor]]",
	"[[Wikipedia:Service awards#Ultimate Vanguard Editor (or Cardinal Gom, the August Togneme of the Encyclopedia)|Ultimate Vanguard Editor]]",
}
local levelTime = {
	0,
	1,
	8,
	16,
	24,
	30.5,
	45.5,
	60.5,
	75.5,
	91.3,
	114.3,
	137.3,
	160.3,
	182.6,
	228.1,
	273.6,
	319.1,
	365.25,
	410.75,
	456.25,
	501.75,
	547.9,
	730.5,
	913.1,
	1095.7,
	1278.4,
	1461,
	1643.6,
	1826.2,
	2191.5,
	2556.7,
	2922,
	3652.4,
	4383,
	5113.5,
	5844,
	6574.5,
	7305,
}
local levelEdits = {
	0,
	1,
	50,
	100,
	150,
	200,
	400,
	600,
	800,
	1000,
	1250,
	1500,
	1750,
	2000,
	2500,
	3000,
	3500,
	4000,
	4500,
	5000,
	5500,
	6000,
	8000,
	12000,
	16000,
	20000,
	24000,
	28500,
	33000,
	42000,
	51000,
	60000,
	78000,
	96000,
	114000,
	132000,
	150000,
	175000,
}
local function serviceLevel(args)
	--Inputs
	local editorTime = tonumber(stripToNil(args.editorTime))
	local edits = tonumber(stripToNil(args.edits))
	local styleoverride = stripToNil(args.styleoverride)
	local style = stripToNil(args.style)
	local genderoverride = stripToNil(args.genderoverride)
	local url = stripToNil(args.url)
	
	--Other Variables
	local timeLevel = '' -- Level associated with time
	local editLevel = '' -- Level associated with edits
	local userLevel = '' -- Full name of current user level
	local lowEdits = '' -- Minimum number of edits for current user level
	local lowTime = '' -- Minimum amount of time for current user level
	local highEdits = '' -- Max number of edits for current user level
	local highTime = '' -- Max amount of time for current user level
	local nextLevel = '' -- Full name of next user level
	local fullMessage = '<div style="' -- Output seed
	local topLevel = false
	local needsEdits = false
	local needsTime = false
	local needsBoth = false
	local displayall = false
	if stripToNil(args.displayall) == 'yes' then
		displayall = true
	end
	
	-- Find "level" of editor based on time
	for x = 1, 38, 1 do
		if editorTime > levelTime[x] then
			timeLevel = x
			lowTime = levelTime[x]
			highTime = levelTime[x+1]
			break
		end
	end
	-- Fine "level" of editor based on edits
	for y = 1, 38, 1 do
		if edits > levelEdits[y] then
			editLevel = y
			lowEdits = levelEdits[y]
			highEdits = levelEdits[y]
			break
		end
	end
	
	-- Set user level and the next level up
	if timeLevel == editLevel then
		if timeLevel == 38 then
			userLevel = levelNames[38]
			topLevel = true
		else
			userLevel = levelNames[timeLevel]
			nextLevel = levelNames[timeLevel+1]
			needsBoth = true
		end
	elseif timeLevel > editLevel then
		userLevel = levelNames[editLevel]
		nextLevel = levelNames[editLevel+1]
		needsEdits = true
	else
		userLevel = levelNames[timeLevel]
		nextLevel = levelNames[timeLevel+1]
		needsTime = true
	end
	
	-- Build notice
	-- First paragraph
	fullMessage = fullMessage .. styleoverride .. '">{{navbar|Template:Service award progress|style=float:right|mini=1}}' ..
					'Currently, this editor has earned the <b>' .. userLevel .. '</b> service award.<br><br>'
	if topLevel then
		fullMessage = fullMessage .. '<div>This is the highest level achievable by an editor!</div>'
	else
		fullMessage = fullMessage .. '<div>To get to the next level, ' .. nextLevel .. ', ' .. genderoverride .. ' to meet the '
		if needsBoth then
			fullMessage = fullMessage .. '<b>editing</b> and the <b>time</b> requirement.</div>'
		elseif needsEdits then
			fullMessage = fullMessage .. '<b>editing</b> requirement.</div>'
		else
			fullMessage = fullMessage .. '<b>time</b> requirement.</div>'
		end
	end
	-- Second paragra / progress bars
	if displayall or needsBoth then
		fullMessage = fullMessage .. 'Progress towards the next level (by edits): [&nbsp;' ..
						'<span class="plainlinks">[' .. url .. ' ' ..
						lang:formatnum(edits - lowEdits) .. ']</span>&nbsp;/&nbsp;' ..
						lang:formatnum(highEdits - lowEdits) .. '&nbsp;]'
		fullMessage = fullMessage .. progressBar(edits - lowEdits, highEdits - lowEdits)
		fullMessage = fullMessage .. 'Progress towards the next level (by time): [&nbsp;' ..
						lang:formatnum(editorTime - lowTime) .. '&nbsp;days&nbsp;/&nbsp;' ..
						lang:formatnum(highTime - lowTime) .. '&nbsp;days&nbsp;]'
		fullMessage = fullMessage .. progressBar(editorTime - lowTime, highTime - lowTime)
	elseif needsEdits then
		fullMessage = fullMessage .. 'Progress towards the next level (by edits): [&nbsp;' ..
						'<span class="plainlinks">[' .. url .. ' ' ..
						lang:formatnum(edits - lowEdits) .. ']</span>&nbsp;/&nbsp;' ..
						lang:formatnum(highEdits - lowEdits) .. '&nbsp;]'
		fullMessage = fullMessage .. progressBar(edits - lowEdits, highEdits - lowEdits)
	else
		fullMessage = fullMessage .. 'Progress towards the next level (by time): [&nbsp;' ..
						lang:formatnum(editorTime - lowTime) .. '&nbsp;days&nbsp;/&nbsp;' ..
						lang:formatnum(highTime - lowTime) .. '&nbsp;days&nbsp;]'
		fullMessage = fullMessage .. progressBar(editorTime - lowTime, highTime - lowTime)
	end
	
	return fullMessage
end

local function main(frame)
	return 'The inputs were: ' .. frame.args.editorTime .. frame.args.edits .. frame.args.styleoverride .. frame.args.style .. frame.args.genderoverride .. frame.args.url

	--return serviceLevel(frame.args)
end