יחידה:שחמטאי

מתוך ויקיפדיה, האנציקלופדיה החופשית

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:שחמטאי/תיעוד

local p = {}
--[[
Filters statements to chess player
]]
function p.filterChessPlayer( propertyVals )
	local tempVals = {}
    for i, property in ipairs(propertyVals) do
    	local propValue = property.mainsnak and property.mainsnak.datavalue
    	if propValue and propValue.value then
			if propValue.value['id'] ~= 'Q10873124' then
				table.insert(tempVals, property)
			end
		end
	end
	return tempVals
end

function extractDate(p)
	local exDate = p and p.qualifiers
	exDate = exDate and exDate['P585']
	exDate = exDate and exDate[1]
	exDate = exDate and exDate.datavalue
	exDate = exDate and exDate.value
	exDate = exDate and exDate.time
	return exDate
end

function dateSorter(a,b)
	local aDate = extractDate(a)
	if not aDate then return b end -- nil protection
	local bDate = extractDate(b)
	if not bDate then return a end -- nil protection

	return aDate>bDate
end

--[[
Filters statements to chess player
]]
function p.filterLatestEloRating( propertyVals )
	local tempVals = {}
    for i, property in ipairs(propertyVals) do
    	-- TODO: filter latest
    	table.insert(tempVals, property)
	end
	table.sort(tempVals, dateSorter)
	return tempVals
end

return p