Bước tới nội dung

Mô đun:Tiến độ giải thưởng phục vụ

Bách khoa toàn thư mở Wikipedia
Tài liệu mô đun[tạo]
local navbar = require('Module:Navbar')._navbar
local mm = require('Module:Math')
local p = {}

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 = mm._round(current / total * 100, 1)
	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>Hoàn thành <span style="font-size: 120%;"><b>' .. percentDone .. '%</b></span></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 = {
	'[[Wikipedia:Giải thưởng phục vụ#Sagacious Editor (or Ephoros of the Encyclopedia)|Sagacious Editor]]',
	'[[Wikipedia:Giải thưởng phục vụ#Ultimate Vanguard Editor (or Cardinal Gom, the August Togneme of the Encyclopedia)|Ultimate Vanguard Editor]]',
	'[[Wikipedia:Giải thưởng phục vụ#Senior Vanguard Editor (or Supreme Gom, the Most Exalted Togneme of the Encyclopedia)|Senior Vanguard Editor]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Tiên Khởi (hay Lord Gom, the Highest Togneme of the Encyclopedia)|BTV Tiên Khởi]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Bô lão Thượng cấp (hay Lord High Togneme Laureate)|BTV Bô lão Thượng cấp]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Bô lão (hay Lord High Togneme Vicarus)|BTV Bô lão]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thượng cấp IV (hay Looshpah Laureate of the Encyclopedia)|BTV Thượng cấp IV]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thượng cấp III (hay Most Plusquamperfect Looshpah Laureate)|BTV Thượng cấp III]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thượng cấp II (hay Auspicious Looshpah)|BTV Thượng cấp II]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thượng cấp (hay Illustrious Looshpah)|BTV Thượng cấp]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thâm niên III (hay Labutnum of the Encyclopedia)|BTV Thâm niên III]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thâm niên II (hay Most Pluperfect Labutnum)|BTV Thâm niên II]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Thâm niên (hay Labutnum)|BTV Thâm niên]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Kỳ cựu IV (hay Tutnum of the Encyclopedia)|Veteran Editor IV]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Kỳ cựu III (hay Most Perfect Tutnum)|BTV Kỳ cựu III]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Kỳ cựu II (hay Grand Tutnum)|BTV Kỳ cựu II]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Kỳ cựu (hay Tutnum)|BTV Kỳ cựu]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV Kinh nghiệm (hay Grognard Mirabilaire)|BTV Kinh nghiệm]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV trung cấp (hay Grognard Extraordinaire)|BTV trung cấp, cấp độ 4]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV trung cấp (hay Grognard Extraordinaire)|BTV trung cấp, cấp độ 3]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV trung cấp (hay Grognard Extraordinaire)|BTV trung cấp, cấp độ 2]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV trung cấp (hay Grognard Extraordinaire)|BTV trung cấp]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV nghiệp dư (hay Grognard)|BTV nghiệp dư, cấp độ 4]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV nghiệp dư (hay Grognard)|BTV nghiệp dư, cấp độ 3]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV nghiệp dư (hay Grognard)|BTV nghiệp dư, cấp độ 2]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV nghiệp dư (hay Grognard)|BTV nghiệp dư]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV sơ cấp (hay Novato)|BTV sơ cấp, cấp độ 4]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV sơ cấp (hay Novato)|BTV sơ cấp, cấp độ 3]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV sơ cấp (hay Novato)|BTV sơ cấp, cấp độ 2]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV sơ cấp (hay Novato)|BTV sơ cấp]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV mới vào nghề (hay Tân thủ)|BTV mới vào nghề, cấp độ 4]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV mới vào nghề (hay Tân thủ)|BTV mới vào nghề, cấp độ 3]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV mới vào nghề (hay Tân thủ)|BTV mới vào nghề, cấp độ 2]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV mới vào nghề (hay Tân thủ)|BTV mới vào nghề]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV đã đăng kí (hay Người ký kết)|BTV đã đăng kí, cấp độ 4]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV đã đăng kí (hay Người ký kết)|BTV đã đăng kí, cấp độ 3]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV đã đăng kí (hay Người ký kết)|BTV đã đăng kí, cấp độ 2]]',
	'[[Wikipedia:Giải thưởng phục vụ#BTV đã đăng kí (hay Người ký kết)|BTV đã đăng kí]]',
	'Wikipedian',
}
local levelTime = {
	8035.5, 7305, 6574.5, 5844, 5113.5, 4383, 3652.4, 2922, 2556.7, 2191.5, 1826.2, 1643.6, 
	1461, 1278.4, 1095.7, 913.1, 730.5, 547.9, 501.75, 456.25, 410.75, 365.25, 
	319.1, 273.6, 228.1, 182.6, 160.3, 137.3, 114.3, 91.3, 75.5, 60.5, 45.5, 30.5, 
	24, 16, 8, 1, 0,
}
local levelEdits = {
	205000, 175000, 150000, 132000, 114000, 96000, 78000, 60000, 51000, 42000, 33000, 28500,
	24000, 20000, 16000, 12000, 8000, 6000, 5500, 5000, 4500, 4000, 3500, 3000, 2500, 
	2000, 1750, 1500, 1250, 1000, 800, 600, 400, 200, 150, 100, 50, 1, 0,
}
function p.serviceLevel(args)
	--Inputs
	local editorTime = tonumber(stripToNil(args.editorTime))
	local edits = tonumber(stripToNil(args.edits))
	local styleoverride = stripToNil(args.styleoverride)
	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, 39, 1 do
		if editorTime >= levelTime[x] then
			timeLevel = x
			break
		end
	end
	-- Fine "level" of editor based on edits
	for y = 1, 39, 1 do
		if edits >= levelEdits[y] then
			editLevel = y
			break
		end
	end
	
	-- Set user level and the next level up
	if timeLevel == editLevel then
		if timeLevel == 1 then
			userLevel = levelNames[1]
			topLevel = true
		else
			userLevel = levelNames[editLevel]
			nextLevel = levelNames[editLevel-1]
			lowEdits = levelEdits[editLevel]
			highEdits = levelEdits[editLevel-1]
			lowTime = levelTime[editLevel]
			highTime = levelTime[editLevel-1]
			needsBoth = true
		end
	elseif timeLevel < editLevel then
		userLevel = levelNames[editLevel]
		nextLevel = levelNames[editLevel-1]
		lowEdits = levelEdits[editLevel]
		highEdits = levelEdits[editLevel-1]
		lowTime = levelTime[editLevel]
		highTime = levelTime[editLevel-1]
		needsEdits = true
	else
		userLevel = levelNames[timeLevel]
		nextLevel = levelNames[timeLevel-1]
		lowEdits = levelEdits[timeLevel]
		highEdits = levelEdits[timeLevel-1]
		lowTime = levelTime[timeLevel]
		highTime = levelTime[timeLevel-1]
		needsTime = true
	end
	
	-- Build notice
	-- First paragraph
	fullMessage = fullMessage .. styleoverride .. '">' ..
					navbar({"Bản mẫu:Tiến độ giải thưởng phục vụ",style="float:right",mini=1}) ..
					'Hiện tại, biên tập viên này đã giành được giải thưởng <b>' .. userLevel .. '</b> .<br><br>'
	if topLevel then
		fullMessage = fullMessage .. '<div>Đây là cấp độ cao nhất mà một biên tập viên có thể đạt được!</div>'
	else
		fullMessage = fullMessage .. '<div>Để đạt đến cấp độ tiếp theo, ' .. nextLevel .. ', ' .. genderoverride .. ' phải đáp ứng '
		if needsBoth then
			fullMessage = fullMessage .. 'yêu cầu <b>chỉnh sửa</b> và <b>thời gian</b>.</div>'
		elseif needsEdits then
			fullMessage = fullMessage .. 'yêu cầu <b>chỉnh sửa</b>.</div>'
		else
			fullMessage = fullMessage .. 'yêu cầu <b>thời gian</b>.</div>'
		end
	
		-- Second paragra / progress bars
		if displayall or needsBoth or needsEdits then
			fullMessage = fullMessage .. 'Tiến tới cấp độ tiếp theo (bằng cách chỉnh sửa): [&nbsp;' ..
							'<span class="plainlinks">[' .. url .. ' ' ..
							(edits - lowEdits) .. ']</span>&nbsp;/&nbsp;' ..
							(highEdits - lowEdits) .. '&nbsp;]'
			fullMessage = fullMessage .. progressBar(edits - lowEdits, highEdits - lowEdits)
		end
		if displayall or needsBoth or needsTime then
			fullMessage = fullMessage .. 'Tiến tới cấp độ tiếp theo (theo thời gian): [&nbsp;' ..
							(editorTime - lowTime) .. '&nbsp;ngày&nbsp;/&nbsp;' ..
							(highTime - lowTime) .. '&nbsp;ngày&nbsp;]'
			fullMessage = fullMessage .. progressBar(editorTime - lowTime, highTime - lowTime)
		end
		fullMessage = fullMessage .. '</div>'
	end
	return fullMessage
end

function p.main(frame)
	return p.serviceLevel(frame.args)
end

return p