Ugrás a tartalomhoz

Modul:ServiceAward

Ellenőrzött
A Wikipédiából, a szabad enciklopédiából

ServiceAward[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local levels = {
	{ 1, "1. szintű", 30, 600, "DYK 100 Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 2, "2. szintű", 60, 1200, "DYK 200 Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 3, "3. szintű", 115, 2400, "DYK 25 Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 4, "4. szintű", 210, 4500, "DYK 50 Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 5, "5. szintű", 360, 7900, "DYK Medal Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 6, "6. szintű", 585, 14000, "Veteran Editor Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 7, "7. szintű", 910, 21800, "Veteran Editor Ribbon 2.png", "#B7B7B7", "#E8E8E8" },
	{ 8, "8. szintű", 1370, 32880, "Veteran Editor Ribbon 3.png", "#B7B7B7", "#E8E8E8" },
	{ 9, "9. szintű", 2010, 48240, "Veteran Editor Ribbon 4.png", "#B7B7B7", "#E8E8E8" },
	{ 10, "10. szintű", 2880, 69120, "Senior Editor.png", "#B7B7B7", "#E8E8E8" },
	{ 11, "11. szintű", 4030, 96720, "Master editor.png", "#B7B7B7", "#E8E8E8" },
	{ 12, "12. szintű", 5500, 132000, "Master editor 2.png", "#B7B7B7", "#E8E8E8" },
}

local statistics = mw.loadData('Modul:ServiceAward/stat-wsp')

local RANKS_RANK_NAME_INDEX = 2;
local RANKS_NEEDED_ACTIVE_DAYS_INDEX = 3;
local RANKS_NEEDED_TOTAL_CONTRIBUTIONS_INDEX = 4;
local RANKS_IMAGE_INDEX = 5;
local RANKS_ID_COLOR_INDEX = 6;
local RANKS_BACKGROUND_COLOR_INDEX = 7;

local USER_STATISTICS_RANK_INDEX = 1;
local USER_STATISTICS_ACTIVE_DAYS_INDEX = 2;
local USER_STATISTICS_TOTAL_EDITS_INDEX = 3;
local USER_STATISTICS_TOTAL_LOG_EVENTS_INDEX = 4;


local p = {}

function p.serviceAwardStatus(frame)
	local args = frame.args
	local userName = args.userName
	
	if not(userName) then
		return "Nem adtál meg szerkesztőnevet!"
	end

	local ret = ""
	local templateParams = {}

	local userData = statistics[userName]
	if userData then
		templateParams.userName = userName
		
		local currentRank = nil
		if not(userData[USER_STATISTICS_RANK_INDEX] == -1) then
			currentRank = levels[userData[USER_STATISTICS_RANK_INDEX]]
			templateParams.currentRank = currentRank[RANKS_RANK_NAME_INDEX]
		end

		local nextRank = nil
		
		local nextRankIndex = userData[USER_STATISTICS_RANK_INDEX];
		if nextRankIndex == -1 then
			nextRankIndex = 1
		else
			nextRankIndex = nextRankIndex + 1
		end
		
		if table.getn(levels) >= nextRankIndex then
			nextRank = levels[nextRankIndex]
			templateParams.nextRank = nextRank[RANKS_RANK_NAME_INDEX]
		end

		if nextRank then
			local daysToNextRank = nextRank[RANKS_NEEDED_ACTIVE_DAYS_INDEX]
			local contributionsToNextRank = nextRank[RANKS_NEEDED_TOTAL_CONTRIBUTIONS_INDEX]

			local userActiveDays = userData[USER_STATISTICS_ACTIVE_DAYS_INDEX]
			local userEdits = userData[USER_STATISTICS_TOTAL_EDITS_INDEX]
			local userLogEvents = userData[USER_STATISTICS_TOTAL_LOG_EVENTS_INDEX]
			local userContributions = userEdits + userLogEvents

			if currentRank then
				daysToNextRank = daysToNextRank - currentRank[RANKS_NEEDED_ACTIVE_DAYS_INDEX]
				contributionsToNextRank = contributionsToNextRank - currentRank[RANKS_NEEDED_TOTAL_CONTRIBUTIONS_INDEX]

				userActiveDays = userActiveDays - currentRank[RANKS_NEEDED_ACTIVE_DAYS_INDEX]
				userContributions = userContributions - currentRank[RANKS_NEEDED_TOTAL_CONTRIBUTIONS_INDEX]
			end

			local contributionsStillNeeded = contributionsToNextRank - userContributions
			local contributionsStillNeededPercentage = contributionsStillNeeded / contributionsToNextRank
			local daysStillNeeded = daysToNextRank - userActiveDays
			local daysStillNeededPercentage = daysStillNeeded / daysToNextRank
 
			templateParams.userActiveDaysInRank = userActiveDays
			templateParams.activeDaysToNextRank = daysToNextRank
			templateParams.userContributionsInRank = userContributions
			templateParams.contributionsToNextRank = contributionsToNextRank
			
			local contributionsPercentage = userContributions / contributionsToNextRank
			local daysPercentage = userActiveDays / daysToNextRank
			local percentage = math.min(contributionsPercentage, daysPercentage)
			templateParams.percentage = percentage
		end
	end
	
	ret = ret .. frame:expandTemplate{
		title = "Szolgálati Emlékérem/Előrehaladás/Keret",
		args = templateParams,
	}

	return ret
end

function p.serviceAwardUserBox(frame)
	local args = frame.args
	local userName = args.userName
	
	if not(userName) then
		return "Nem adtál meg szerkesztőnevet!"
	end

	local ret = ""
	local templateParams = {}

	local userBoxBorderColor = nil
	local userBoxIdColor = nil
	local userBoxBackgroundColor = nil
	local userBoxTextColor = args.userBoxTextColor
	if userBoxTextColor == nil or userBoxTextColor == "" then
		userBoxTextColor = "#000"
	end
	local userBoxBorderWidth = args.userBoxBorderWidth
	if userBoxBorderWidth == nil or userBoxBorderWidth == "" then
		userBoxBorderWidth = "1"
	end
	
	local userBoxIconContent = "◯"
	local userBoxTextContent = "Ez a szerkesztő még nem rendelkezik elegendő szerkesztéssel ahhoz, hogy Szolgálati Érdemérmet kapjon."
	
	local userData = statistics[userName]
	if userData then
		local currentRank = nil
		if not(userData[USER_STATISTICS_RANK_INDEX] == -1) then
			currentRank = levels[userData[USER_STATISTICS_RANK_INDEX]]
			
			userBoxIconContent = "[[Kép:" .. currentRank[RANKS_IMAGE_INDEX] .. "|50px]]"
			userBoxTextContent = "Ez a szerkesztő '''[[Wikipédia:Szolgálati Emlékérem|" .. currentRank[RANKS_RANK_NAME_INDEX] .. "]]'''."
			
			userBoxBorderColor = currentRank[RANKS_ID_COLOR_INDEX]
			userBoxIdColor = currentRank[RANKS_ID_COLOR_INDEX]
			userBoxBackgroundColor = currentRank[RANKS_BACKGROUND_COLOR_INDEX]
		else
			userBoxIdColor = currentRank[RANKS_ID_COLOR_INDEX]
			userBoxBackgroundColor = currentRank[RANKS_BACKGROUND_COLOR_INDEX]
		end
	end
	
	if args.userBoxIdColor ~= nil and args.userBoxIdColor ~= "" then
		userBoxIdColor = args.userBoxIdColor
	end
	
	if args.userBoxBackgroundColor ~= nil and args.userBoxBackgroundColor ~= "" then
		userBoxBackgroundColor = args.userBoxBackgroundColor
	end
	
	if args.userBoxBorderColor ~= nil and args.userBoxBorderColor ~= "" then
		userBoxBorderColor = args.userBoxBorderColor
	end
	
	if userBoxIdColor == nil then
		userBoxIdColor = "#B7B7B7"
	end
	
	if userBoxBackgroundColor == nil then
		userBoxBackgroundColor = "#E8E8E8"
	end
	
	if userBoxBorderColor == nil then
		userBoxBorderColor = "#B7B7B7"
	end
	
	ret = ret .. frame:expandTemplate{
		title = "Userbox",
		args = {
			[0] = userBoxBorderColor, -- 0
			[1] = userBoxIdColor, -- 1
			[2] = userBoxBackgroundColor, -- 2
			[3] = userBoxIconContent, -- 3
			[4] = userBoxTextContent, -- 4
			[5] = "left", -- 5
			[6] = userBoxTextColor, -- 6
			[7] = userBoxTextColor, -- 7
			[8] = "8pt", -- 8
			[9] = "14pt", -- 9
			[10] = userBoxBorderWidth -- 10
		},
	}

	return ret
end

return p