Module:Sandbox/Julio974fr/positions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
local p = {}

--[[
	Note: These score are not cardinal, they don't express the
	‘real’ left-to-right position of the parties; they are ordinal,
	meaning they give the left-to-right *ordering* of the parties.
	(with the exception of 0.500 which indicates the center) ]]

local positionsData = {
	Q661771    = 0.090, -- AL
	Q116313549 = 0.095, -- AL-PdA
	Q438524    = 0.100, -- AL
	Q303745    = 0.200, -- SP/PS
	Q659739    = 0.300, -- GPS/PES
	Q667718    = 0.400, -- EVP
	Q545900    = 0.450, -- GLP/PVL
	Q659461    = { -- CVP/PDC
		{1, 0.900},
		{1980, 0.600},
	},
	Q100934025 = 0.640, --DM/LC/AdC
	Q151768    = 0.700, --BDP
	Q202638    = { -- FDP/PLR
		{1, 0.600},
		{1980, 0.750},
	},
	Q13850128  = 0.775, -- FDP.DL/PLR (after merger)
	Q667785    = 0.800, -- LPS/PLS
	Q385258    = { -- SVP/UDC
		{1, 0.750},
		{1980, 0.900},
	},
	Q667836    = 0.920, -- EDU/UDF
	Q660046    = 0.940, -- SD/DS
}

function p._fetch(args)
	if not args[1] then
		mw.addWarning("parameter 1 should be a party QID.")
	end
	if not args[2] then
		mw.addWarning("parameter 2 should be a year")
		return nil
	end
	
	if not positionsData[args[1]] then
		mw.addWarning('No position set for '..args[1])
		return 0.5
	end
	
	local partyData = positionsData[args[1]]
	
	if type(partyData) == 'number' then
		return partyData
	end
	
	local position -- If multiple positions for multiple years
	for _, v in ipairs(partyData) do
		if v[1] <= args[2] then position = v[2] end
	end
	
	return position
end

function p.fetch(frame)
	-- Initialise and populate variables
	local getArgs = require("Module:Arguments").getArgs
	local args = getArgs(frame)
	
	return p._fetch(args)
end

return p