Pāriet uz saturu

Modulis:RatingFIDE

Vikipēdijas lapa

Lua kļūda Modulis:Documentation, 144. rinda: message: type error in message cfg.container (string expected, got nil).

local p = {}

function p.GetRating(frame)
	local args = frame:getParent().args
    local PlayerIDstr = args['ID'] or frame.args['ID']
    local NeedSource = args['Atsauce']=='jā' or frame.args['Atsauce']=='jā'
    if PlayerIDstr == nil then return "Ievadiet šahista id" end
    local PlayerID = tonumber(PlayerIDstr)

	local tabular = mw.ext.data.get("FIDE Standard rating.tab")
	if tabular == nil then return "Nav tabulas ar datiem" end
	local Rating = nil
	for k,v in pairs(tabular.data) do
		--do return v[1].." ".. v[2] .." ".. PlayerID end
		if v[1] == PlayerID then
			Rating = v[2]
			break 
		end
	end
	if Rating == nil then 
		if args[1]==nil then 
	    	CallSite = mw.wikibase.getEntityObject() 
	    else
	    	CallSite = mw.wikibase.getEntityObject(string.match( args[1], "Q%d+")) 
		end		
		if (CallSite == nil) or (CallSite.claims.P1087 == nil) then
			Rating = "Nav datu"
		else
			
	        local latest, latestTime
	        latestTime = "+1900-01-01T00:00:00Z"
	        for k, v in ipairs(CallSite.claims.P1087) do
	        	--do return v.qualifiers.P585[1].datavalue.value.time end
	            if v.qualifiers.P585[1].datavalue.value.time > latestTime then
	                latest = CallSite.claims.P1087[k].mainsnak.datavalue.value.amount
	                latestTime = v.qualifiers.P585[1].datavalue.value.time
	            end
	        end
			Rating = string.sub(latest, 2) .. " (" .. string.sub(latestTime, 7, 8) .. "." .. string.sub(latestTime, 2, 5) .. ")"
		end
	else
		if NeedSource then Rating = Rating .. frame:callParserFunction{name = '#tag:ref', args = {'['.. tabular.sources ..']'}} end
	end
	return Rating 
end

return p