Jump to content

Module:NPVIC status and Module:NPVIC status/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
Avoided redirect for Georgia. Clean-up.
 
No edit summary
 
Line 2: Line 2:


function getstates(frame)
function getstates(frame)
local states = frame:expandTemplate{ title = 'section transclude', args = { frame.args[1] } }
local states = frame:expandTemplate{ title = 'section transclude', args = { frame.args['section'] } }
if states == '' then states = frame.args[1] end
if states == '' then
states = frame.args[1]
end
return states
return states
end
end
Line 15: Line 17:
for state in mw.ustring.gmatch( states, "%a%a" ) do
for state in mw.ustring.gmatch( states, "%a%a" ) do
seats = frame:expandTemplate{ title = 'USHRseats', args = { state } }
seats = frame:expandTemplate{ title = 'USHRseats', args = { state } }
if state == 'DC' then seats = 1 end
if state=='DC' then seats=1 end
if type(tonumber(seats)) == 'nil' then
if type(tonumber(seats))=='nil' then
total = error("Unrecognized state")
total = error("Unrecognized state")
break
break
Line 29: Line 31:
function p.percent(frame)
function p.percent(frame)
local EVs = p.EVs(frame)
local EVs = p.EVs(frame)
if frame.args[1] then
denom = 538
denom = frame.args[1]
places = 1
else
if frame.args[2] then denom = frame.args[2] end
denom = 538
if frame.args[3] then places = frame.args[3] end
end
if frame.args[2] then
places = frame.args[2]
else
places = 1
end
percent = frame:expandTemplate{ title = 'percent', args = { EVs, denom, places} }
percent = frame:expandTemplate{ title = 'percent', args = { EVs, denom, places} }
return percent
return percent
Line 41: Line 49:
local total = 0
local total = 0
for state in mw.ustring.gmatch( states, "%a%a" ) do
for state in mw.ustring.gmatch( states, "%a%a" ) do
if state ~= 'DC' then total = total + 1 end
if state~='DC' then
total = total + 1
end
end
end
if total == 0 then
if total==0 then
return frame:expandTemplate{ title = 'error', args = { 'Value not available when editing this section in isolation.' } }
return frame:expandTemplate{ title = 'error', args = { 'Value not available when editing this section in isolation.' } }
else
else
if frame.args[2] == 'spell' then
if frame.args[1]=='spell' then
total = frame:expandTemplate{ title = 'spellnum per MOS', args = { total } }
total = frame:expandTemplate{ title = 'spellnum per MOS', args = { total } }
end
end
Line 56: Line 66:
local states = getstates(frame)
local states = getstates(frame)
local size = frame.args['size'] or '325px'
local size = frame.args['size'] or '325px'

if frame.args[1] == 'passed' then
if frame.args['section']=='passed' then
color = 'green'
color = 'green'
elseif frame.args[1] == 'pending' then
elseif frame.args['section']=='pending' then
color = 'yellow'
color = 'yellow'
end
end
local overlays = ''
local overlays = ''
for state in mw.ustring.gmatch( states, "%a%a" ) do
for state in mw.ustring.gmatch( states, "%a%a" ) do
Line 76: 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_target = state_name
local dab = ''
if state == 'DC' then
if state_name=='New York' or state_name=='Washington' then
dab=' (state)'
link_target = 'Washington, D.C.'
elseif state == 'GA' then
link_target = 'Georgia (U.S. state)'
elseif state == 'NY' then
link_target = 'New York (state)'
elseif state == 'WA' then
link_target = 'Washington (state)'
end
end
signatories = signatories .. '\n* ' .. ' [[' .. link_target .. '|' .. state_name .. ']]'
signatories = signatories .. '\n* ' .. ' [[' .. state_name .. dab .. '|' .. state_name .. ']]'
end
end
return signatories
return signatories
Line 95: Line 99:
--
--
--end
--end



return p
return p