Hoppa till innehållet

Modul:Sandlådan/Frisko

Från Wikipedia

Dokumentationen för denna modul kan skapas på Modul:Sandlådan/Frisko/dok

local p = {}
local wd = require( 'Modul:Wikidata2' )

function p.clubs()
    local entity = mw.wikibase.getEntity( "Q2339" )
    local claims = sortbyqualifier( entity:getBestStatements( 'P54' ), { ['sortbytime'] = 'inverted'} )
	local clubs = {}
	
    for key, value in pairs( claims ) do
    	local id = value['mainsnak']['datavalue']['value']['id']
		if isClub( id ) then
			clubs[#clubs+1] = '[[' .. getLabelByEntity( id ) .. ']]'
		end
    	
    end
    
   return table.concat( clubs, '<br>' )
    
end

function p.years()
	
    local entity = mw.wikibase.getEntity( "Q2339" )
    local claims = sortbyqualifier( entity:getBestStatements( 'P54' ), { ['sortbytime'] = 'inverted'} )
	local years = {}
	
	for key, value in pairs( claims ) do
		local id = value['mainsnak']['datavalue']['value']['id']
		if isClub( id ) then
			local endYear = ''
			if value['qualifiers']['P582'] then
				endYear = mw.wikibase.renderSnak( value['qualifiers']['P582'][1] )
			end
			years[#years+1] = mw.wikibase.renderSnak( value['qualifiers']['P580'][1] ) .. '–' .. endYear
		end
	end
	
	return table.concat( years, '<br>' )
		  
end

function p.stats()
	
    local entity = mw.wikibase.getEntity( "Q2339" )
    local claims = sortbyqualifier( entity:getBestStatements( 'P54' ), { ['sortbytime'] = 'inverted'} )
	local stats = {}
	
	for key, value in pairs( claims ) do
		local id = value['mainsnak']['datavalue']['value']['id']
		local played = ''
		local goals = ''
		
		if isClub( id ) then
		
			if value['qualifiers']['P1350'] then
				played = value['qualifiers']['P1350'][1]['datavalue']['value']['amount']
			end
			
			if value['qualifiers']['P1351'] then
				goals = '(' .. mw.wikibase.renderSnak( value['qualifiers']['P1351'][1] ) .. ')'
			end
			
			stats[#stats+1] = played .. ' ' .. goals
		
		end
	
	end

	return table.concat( stats, '<br>' )
		  
end

function getLabelByEntity( id )
	return mw.wikibase.getEntity( id ):getLabel( 'sv' )
end

function isClub( id )
	local isClub = false
    for key, value in pairs( mw.wikibase.getEntity( id ):getBestStatements( 'P31' ) ) do
    	if value['mainsnak']['datavalue']['value']['id'] == 'Q476028' then
    		isClub = true
    	end
    end
	return isClub
end

return p