İçeriğe atla

Modül:Elo

Vikipedi, özgür ansiklopedi
Modül belgelemesi[oluştur]
local tbl = {}

local wikidata_mod = require("Modül:WikidataIB")

function tarih_getir(val)
	if val == nil then
		return nil
	end
	
	local yil = string.sub(val, 1, 4)
	local ay = string.sub(val, 5, 6)
	ay = tonumber(ay)

	local aylar = {"Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran",
					   "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
				  }
	
	return "(" .. aylar[ay] .. " " .. yil .. ")"
end

function tbl.getir(frame)
	local veri = require("Modül:Elo/veri")
	local val
	local tarih
	
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args

	local tip = args[1]
	local def_val = args[2]
	
	entity = mw.wikibase.getEntityObject()
	
	if entity then
		
		local id = wikidata_mod.getVal(entity, "P1440")

		if veri["ELO"][id] ~= nil then
			val = veri["ELO"][id][tip]
			
			if (tip == "GUNCELELO") then
				tarih = tarih_getir(veri["GUNCELTAR"])
				val = '[https://ratings.fide.com/profile/' .. id .. ' ' .. val .. ']'
			elseif (tip == "GUNCELSIRA") then
				tarih = tarih_getir(veri["GUNCELTAR"])
				if val ~= nil then
					val = '[https://ratings.fide.com/top_lists.phtml ' .. val .. ']'
				end
			elseif (tip == "YUK_ELO") then
				tarih = tarih_getir(veri["ELO"][id]["YUK_ELO_TAR"])
			elseif (tip == "YUK_SIRA") then
				tarih = tarih_getir(veri["ELO"][id]["YUK_SIRA_TAR"])
			end
			
			if val ~= nil then
				val = val .. " " .. tarih
			end
		else
			val = def_val
		end
	end
	
	return val
end

return tbl