Modul:Europamandate

Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


local p = {}
local full = require('Module:Partei').full
local farbe = require('Modul:Partei').farbe
local sitze = require('Modul:Partei').parteisitze
local pipelink = require('Module:Partei').pipelink
local getArgs = require('Module:Arguments').getArgs

function p.variation(frame)
	local args = getArgs(frame)
	local a = string.sub(args[1], 1, 1)
	if a == '+' or (tonumber(a) and tonumber(a) > 0) then pos = true zeichen = '+' elseif a == '0' then unv = true zeichen = '' else zeichen = '-' end
	local symbol = pos and '▲' or unv and '▬' or '▼'
	local value = tonumber(a) and args[1] or mw.ustring.sub(args[1], 2)
	local farbe = pos and '00CC00' or unv and '00AAFF' or 'FF0000'
	if args[2] == 'f' then bild = '<span style="color:#'..farbe..'>'..symbol..'</span>' else bild = symbol end
	return '<span data-sort-value="' ..zeichen..value.. '">'..bild..' '..value..'</span>'
end

function p.fraktionen(frame)
	local args = getArgs(frame)
	local index, data = {}, {}
	local i = 0
	for a = 1, 100 do i = i + 1
		if args['l'..i] or args['f'..i] or args['p'..i] or args['g'..i] then table.insert(index, i) end
		if args['l'..i] then liste = true end
		if args['f'..i] then fraktion = true end
		if args['a'..i] then vereinigung = true end
		if args['p'..i] and not vereinigung then partei = true end
		if args['g'..i] then gruppe = true end
		if args['r'..i] then richtung = true end
		if args['fv'..i] then fvorsitzender = true end
		if args['k'..i] or args['v'..i] then kand = true end
		if args['e'..i] or args['ee'..i] then eupartei = true end
		if args['ef'..i] then eufraktion = true end
	end
	local num = 1
	local gesamt = 0
	while args['s'..num] do
		data[num] = {
			s = tonumber(args['s'..num]),
		}				
		gesamt = gesamt + data[num].s
		num = num+1
	end

	if gruppe then cspan = 4 elseif partei then cspan = 3 end
	col = 2 + ((args['f1'] or args['l1'] and args['s1'] and not eufraktion) and 1 or 0) + (partei and 2 or 0) + (gruppe and 1 or 0) + (kand and 1 or 0) + (eupartei and 1 or 0) + (eufraktion and 1 or 0) + (args['a1'] and 1 or 0) + (args['r1'] and 1 or 0) + (args['fv1'] and 1 or 0) + (args['v1'] and 1 or 0) + (args['prozent'] and 1 or 0) + (args['d1'] and 1 or 0) + (args['z1'] and 1 or 0) + (args['s1'] and 1 or 0) + (args['w1'] and 1 or 0)

	local function pzn(frame)
		local args = getArgs(frame)
		local a = tonumber(args[1])
		local b = tonumber(args[2])
		if a and b then
			x = string.format('%.1f', a / b * 100)
			y = string.gsub(x, "%.", "%,")
			return y
		else
			return ''
		end
	end

	local root = mw.html.create('table'):addClass('wikitable')
	row = root:tag('tr')
	
	if args['z1'] then
		row:tag('th')
			:wikitext(args['zeichen'] or 'N.')
	end
	if liste then
		row:tag('th')
			:wikitext(partei and 'Listen und Parteien' or 'Listen')
			:attr('colspan', gruppe and 4 or partei and 3 or 2)
		if args['s1'] then
			row:tag('th')
				:wikitext('Mandate')
		end
		row:tag('th')
			:wikitext(args['s1'] and '[[Fraktion im Europäischen Parlament|Fraktion]]' or '[[Europäische politische Partei|Europapartei]]')
		if kand then
			row:tag('th')
				:wikitext(args['amt'] or 'Erstplatzierter<br/>in der Liste')
		end
		if args['wahlkreis'] or args['w1'] then
			row:tag('th')
				:wikitext(args['wahlkreis'] or 'Wahlkreis')
		end
	elseif fraktion then
		row:tag('th')
			:attr('colspan', '2')
			:wikitext('[[Fraktion im Europäischen Parlament|Fraktion]]')
		if args['r1'] then
			row:tag('th')
				:wikitext('Richtung')
		end
		if args['fv1'] then
			row:tag('th')
				:wikitext('Fraktions-<br/>vorsitzender')
		end
		row:tag('th')
			:wikitext('Mandate')
		if args['prozent'] then
			row:tag('th')
				:wikitext('% Mandate')
		end
		if args['d1'] then
			row:tag('th')
				:wikitext('+/-')
		end
		if partei then
			row:tag('th')
				:attr('colspan', '2')
				:wikitext('Partei')
			row:tag('th')
				:wikitext('Mandate')
		end
	end

	for i, v in ipairs(index) do
		row = root:tag('tr')

		if liste then
			if args['z'..v] then
				row:tag('th')
					:wikitext(args['z'..v])
					:attr('rowspan', args['n'..v] or 1)
			end
			if args['l'..v] or args['a'..v] then
				row:tag('td')
					:css('background-color', '#'..farbe({(args['farbliste'] == '1' and args['p'..v] or args['l'..v]) or args['l'..v] or args['a'..v]}))
					:attr('rowspan', args['n'..v] or 1)
			end
			if args['l'..v] then
				row:tag('td')
					:wikitext(args['l'..v]..((args['tl'..v] and args['lang']) and '<div style="font-size:90%">'..frame:expandTemplate{title = 'lang', args = {args['lang'], args['tl'..v]}}..'</div>' or ''))
					:attr('rowspan', args['n'..v] or 1)
					:attr('colspan', ((gruppe and not args['g'..v]) and (args['p'..v] and 2 or 3) or ((partei and not gruppe and not args['p'..v]) and 2 or 1)))
			end
			if args['g'..v] then
				row:tag('td')
					:wikitext(args['g'..v]..((args['tg'..v] and args['lang']) and '<div style="font-size:90%">'..frame:expandTemplate{title = 'lang', args = {args['lang'], args['tg'..v]}}..'</div>' or ''))
					:attr('rowspan', args['ng'..v] or 1)
					:attr('colspan', args['p'..v] and 1 or 2)
			end
			if args['p'..v] then
				row:tag('td')
					:wikitext(args['p'..v]..((args['tp'..v] and args['lang']) and '<div style="font-size:90%">'..frame:expandTemplate{title = 'lang', args = {args['lang'], args['tp'..v]}}..'</div>' or ''))
			end
			if (args['p'..v] or args['g'..v] or args['l'..v]) and eupartei then
				row:tag('td')
					:wikitext((args['e'..v] and pipelink({args['e'..v], 'EP'}) or '&ndash;')..(args['ee'..v] or ''))
			end
			if args['s'..v] then
				row:tag('td')
					:wikitext(sitze({args['s'..v], gesamt, args['p'..v] or args['l'..v]}))
			end
			if args['ef'..v] then
				row:tag('td')
					:wikitext(pipelink({args['ef'..v], 'EU'}))
			end
			if args['k'..v] then
				row:tag('td')
					:wikitext(args['k'..v])
					:attr('rowspan', args['n'..v])
			end
			if args['v'..v] then
				row:tag('td')
					:wikitext(args['v'..v])
			end
			if args['w'..v] then
				row:tag('td')
					:wikitext(args['w'..v])
					:attr('rowspan', (args['g'..v] and (args['ng'..v] or 1) or args['n'..v] or 1))
			end
		elseif fraktion then
			if args['n'..v] then
				local num = v
				mitglieder = 0
				while args['s'..num] do
					data[num] = {
						m = tonumber(args['s'..num]) or 0,
						}
					mitglieder = (mitglieder + data[num].m) or 0
					num = num + 1
					if num > v - 1 + (tonumber(args['n'..v]) or 0) then break end
				end
				mandate = mitglieder else mandate = args['s'..v]
			end

			if args['f'..v] then
				fullfraktion = full({args['f'..v], 'EU'})
				row:tag('td')
					:css('background-color', '#'..farbe({fullfraktion}))
					:attr('rowspan', args['n'..v])
				row:tag('td')
					:wikitext(fullfraktion)
					:attr('rowspan', args['n'..v] or 1)
				if richtung then
					row:tag('td')
						:wikitext(args['r'..v] or '&ndash;')
						:attr('rowspan', args['n'..v] or 1)
				end
				if fvorsitzender then
					row:tag('td')
						:wikitext(args['fv'..v] or '&ndash;')
						:attr('rowspan', args['n'..v] or 1)
				end
				row:tag('td')
					:wikitext(sitze({mandate, gesamt, fullfraktion}))
					:attr('rowspan', args['n'..v] or 1)
				if args['prozent'] then
					row:tag('td')
						:wikitext(pzn({mandate, gesamt}))
						:css('text-align', 'right')
						:css('padding-right', '2em')
						:attr('rowspan', args['n'..v])
				end
				if args['d'..v] then
					row:tag('td')
						:wikitext(args['d'..v])
						:css('text-align', 'center')
						:attr('rowspan', args['n'..v])
				end
			end
			if args['p'..v] then
				row:tag('td')
					:css('background-color', "#"..farbe({(args['p'.. v])}))
				row:tag('td')
					:wikitext(args['p'..v])
				row:tag('td')
					:wikitext(sitze({args['s'..v], gesamt, args['p'..v]}))
			end
		end
	end
	if args['url'] or args['quellen'] then
		row = root:tag('tr')
			row:tag('td')
				:attr('colspan', col)
		row = root:tag('tr')
			row:tag('td')
				:wikitext(args['quellen'] and 'Quellen: '..args['quellen'] or 'Quelle: ['.. args['url']..' '..(args['quelle'] or 'Europäisches Parlament')..']')
				:attr('colspan', col)
	end
	
	return root
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.