Jump to content

Module:NPVIC status: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Undid revision 1151018116 by Brainiac242 (talk) Prefer to assign value to signatories in one place
No edit summary
Line 86: Line 86:
for state in mw.ustring.gmatch( states, "%a%a" ) do
for state in mw.ustring.gmatch( states, "%a%a" ) do
state_name = frame:expandTemplate{ title = 'US State Abbrev', args = { state } }
state_name = frame:expandTemplate{ title = 'US State Abbrev', args = { state } }
local link = state_name
local link_target = state_name
if state == 'DC' then
if state == 'DC' then
link = 'Washington, D.C.'
link_target = 'Washington, D.C.'
elseif state == 'NY' then
link_target = 'New York (state)'
elseif state == 'WA' then
link_target = 'Washington (state)'
else
end
end
signatories = signatories .. '\n* ' .. ' [[' .. link_target .. '|' .. state_name .. ']]'
if state == 'NY' then
link = 'New York (state)'
end
if state == 'WA' then
link = 'Washington (state)'
end
signatories = signatories .. '\n* ' .. ' [[' .. link .. '|' .. state_name .. ']]'
end
end
return signatories
return signatories

Revision as of 13:14, 21 April 2023

local p = {}

function getstates(frame)
	local states = frame:expandTemplate{ title = 'section transclude', args = { frame.args[1] } }
	if states == '' then
		states = frame.args[1]
	end
	return states
end

function p.EVs(frame)
	local states = getstates(frame)
	if not states then
		return frame:expandTemplate{ title = 'error', args = { 'Value not available when editing this section in isolation.' } }
	else
		local total = 0
		for state in mw.ustring.gmatch( states, "%a%a" ) do
			seats = frame:expandTemplate{ title = 'USHRseats', args = { state } }
			if state=='DC' then seats=1 end
			if type(tonumber(seats))=='nil' then
				total = error("Unrecognized state")
				break
			else
				total = total + seats + 2
			end
		end
		return total
	end
end

function p.percent(frame)
	local EVs = p.EVs(frame)
	if frame.args[2] then
		denom = frame.args[2]
	else
		denom = 538
	end
	if frame.args[3] then
		places = frame.args[3]
	else
		places = 1
	end
	percent = frame:expandTemplate{ title = 'percent', args = { EVs, denom, places} }
	return percent
end

function p.states(frame)
	local states = getstates(frame)
	local total = 0
	for state in mw.ustring.gmatch( states, "%a%a" ) do
		if state~='DC' then
			total = total + 1
		end
	end
	if total==0 then
		return frame:expandTemplate{ title = 'error', args = { 'Value not available when editing this section in isolation.' } }
	else
		if frame.args[2]=='spell' then
			total = frame:expandTemplate{ title = 'spellnum per MOS', args = { total } }
		end
		return total
	end
end

function p.overlays(frame)
	local states = getstates(frame)
	local size = frame.args['size'] or '325px'

	if frame.args[1]=='passed' then
		color = 'green'
	elseif frame.args[1]=='pending' then
		color = 'yellow'
	end
		
	local overlays = ''
	for state in mw.ustring.gmatch( states, "%a%a" ) do
		state_overlay = '<div style=\"position: absolute; left: 0px; top: 0px\">[[File:' .. state .. ' ' .. color .. ' 21.svg|' .. size .. ']]</div>'
		overlays = overlays .. state_overlay
	end
	return overlays
end

function p.signatories(frame)
	local states = frame:expandTemplate{ title = 'section transclude', args = { 'passed' } }
	local signatories = ''
	for state in mw.ustring.gmatch( states, "%a%a" ) do
		state_name = frame:expandTemplate{ title = 'US State Abbrev', args = { state } }
		local link_target = state_name
		if state == 'DC' then
			link_target = 'Washington, D.C.'
		elseif state == 'NY' then
			link_target = 'New York (state)'
		elseif state == 'WA' then
			link_target = 'Washington (state)'
		else
		end
		signatories = signatories .. '\n* ' .. '&nbsp;[[' .. link_target .. '|' .. state_name .. ']]'
	end
	return signatories
end

--function p.progress_bar(frame)
--	local
--	
--end


return p