Module:Election results: Difference between revisions

Administrator (talk | contribs)
m 1 revision imported
Administrator (talk | contribs)
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 37: Line 37:
end
end
local function pct(n, d)
local function pct(n, d)
-- Check if percentages should be shown
if args.no_percentages == "true" then
return '–'
end
n, d = tonumber(n), tonumber(d)
n, d = tonumber(n), tonumber(d)
if n and d and d > 0 then
if n and d and d > 0 then
Line 224: Line 229:
end
end


local ovalid = {valid[1], valid[2], valid[3]}
local ovalid = {valid[1], valid[2], valid[3]}
seats = ((args['total_seats'] or '') == 'TOTAL' and seats) or args['total_seats'] or seats
seats = ((args['total_seats'] or '') == 'TOTAL' and seats) or args['total_seats'] or seats
totseats = ((args['total_totseats'] or '') == 'TOTAL' and totseats) or args['total_totseats'] or totseats
totseats = ((args['total_totseats'] or '') == 'TOTAL' and totseats) or args['total_totseats'] or totseats
Line 232: Line 237:
st4t = ((args['total_st4t'] or '') == 'TOTAL' and st4t) or args['total_st4t'] or st4t
st4t = ((args['total_st4t'] or '') == 'TOTAL' and st4t) or args['total_st4t'] or st4t
st5t = ((args['total_st5t'] or '') == 'TOTAL' and st5t) or args['total_st5t'] or st5t
st5t = ((args['total_st5t'] or '') == 'TOTAL' and st5t) or args['total_st5t'] or st5t
if seats or totseats or st1t or st2t or st3t or st4t or st5t or args['total_sc'] or args['total_st1t'] or args['total_st2t'] or args['total_st3t'] or args['total_st4t'] or args['total_st5t'] or args['valid'] or ((rounds > 1) and args['valid2']) or ((rounds > 1) and args['valid3']) then
-- Skip adding total row if no_totals is set to true
if args.no_percentages ~= "true" and (seats or totseats or st1t or st2t or st3t or st4t or st5t or args['total_sc'] or args['total_st1t'] or args['total_st2t'] or args['total_st3t'] or args['total_st4t'] or args['total_st5t'] or args['valid'] or ((rounds > 1) and args['valid2']) or ((rounds > 1) and args['valid3'])) then
max_rows = max_rows + 1
max_rows = max_rows + 1
local i = max_rows
local i = max_rows
Line 260: Line 267:
ovalid[3] = tonumber(args['valid3']) or valid[3]
ovalid[3] = tonumber(args['valid3']) or valid[3]
end
end
-- build the table
-- build the table
local root = mw.html.create(args['embed'] and '' or 'table')
local root = mw.html.create(args['embed'] and '' or 'table')
Line 413: Line 419:
:done()
:done()
:tag('th')
:tag('th')
:wikitext(args.secondround or 'Second round')
:wikitext(args.secondround or 'Final round')
:attr('scope', 'col')
:attr('scope', 'col')
:attr('colspan', 4)
:attr('colspan', 4)
Line 425: Line 431:
:done()
:done()
:tag('th')
:tag('th')
:wikitext(args.secondround or 'Second round')
:wikitext(args.secondround or 'Final round')
:attr('scope', 'col')
:attr('scope', 'col')
:attr('colspan', 3)
:attr('colspan', 3)
Line 471: Line 477:
:done()
:done()
:tag('th')
:tag('th')
:wikitext(args.secondround or 'Second round')
:wikitext(args.secondround or 'Final round')
:attr('scope', 'col')
:attr('scope', 'col')
:attr('colspan', 2)
:attr('colspan', 2)