Modul:ServiceAward

Source code project 1171.svg 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, 2300, "DYK 25 Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 4, "4. szintű", 210, 4200, "DYK 50 Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 5, "5. szintű", 360, 7200, "DYK Medal Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 6, "6. szintű", 585, 11700, "Veteran Editor Ribbon.png", "#B7B7B7", "#E8E8E8" },
	{ 7, "7. szintű", 910, 18200, "Veteran Editor Ribbon 2.png", "#B7B7B7", "#E8E8E8" },
	{ 8, "8. szintű", 1370, 27400, "Veteran Editor Ribbon 3.png", "#B7B7B7", "#E8E8E8" },
	{ 9, "9. szintű", 2010, 40200, "Veteran Editor Ribbon 4.png", "#B7B7B7", "#E8E8E8" },
	{ 10, "10. szintű", 2880, 57600, "Senior Editor.png", "#B7B7B7", "#E8E8E8" },
	{ 11, "11. szintű", 4030, 80600, "Master editor.png", "#B7B7B7", "#E8E8E8" },
	{ 12, "12. szintű", 5500, 110000, "Master editor 2.png", "#B7B7B7", "#E8E8E8" },
}

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

local RANKS_RANK_NAME_INDEX = 2;
local RANKS_NEEDED_ACTIVE_DAYS_INDEX = 3;
local RANKS_NEEDED_TOTAL_EDITS_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_NEXT_RANK_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 editsToNextRank = nextRank[RANKS_NEEDED_TOTAL_EDITS_INDEX]

			local userActiveDays = userData[USER_STATISTICS_ACTIVE_DAYS_INDEX]
			local userEdits = userData[USER_STATISTICS_TOTAL_EDITS_INDEX]

			if currentRank then
				daysToNextRank = daysToNextRank - currentRank[RANKS_NEEDED_ACTIVE_DAYS_INDEX]
				editsToNextRank = editsToNextRank - currentRank[RANKS_NEEDED_TOTAL_EDITS_INDEX]

				userActiveDays = userActiveDays - currentRank[RANKS_NEEDED_ACTIVE_DAYS_INDEX]
				userEdits = userEdits - currentRank[RANKS_NEEDED_TOTAL_EDITS_INDEX]
			end

			local editsStillNeeded = editsToNextRank - userEdits
			local editsStillNeededPercentage = editsStillNeeded / editsToNextRank
			local daysStillNeeded = daysToNextRank - userActiveDays
			local daysStillNeededPercentage = daysStillNeeded / daysToNextRank
 
			templateParams.userActiveDaysInRank = userActiveDays
			templateParams.activeDaysToNextRank = daysToNextRank
			templateParams.userEditsInRank = userEdits
			templateParams.editsToNextRank = editsToNextRank
			
			local editPercentage = userEdits / editsToNextRank
			local daysPercentage = userActiveDays / daysToNextRank
			local percentage = math.min(editPercentage, daysPercentage)
			templateParams.percentage = percentage
		end

		-- ret = ret .. " / Active days: "
		-- ret = ret .. userData[USER_STATISTICS_ACTIVE_DAYS_INDEX]
		-- ret = ret .. " / Total edits: "
		-- ret = ret .. userData[USER_STATISTICS_TOTAL_EDITS_INDEX]
	end
	
	ret = ret .. frame:expandTemplate{
		title = "Szolgálati érdemé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