Module:Election results-STV: Difference between revisions

Content deleted Content added
+
+
 
(22 intermediate revisions by 2 users not shown)
Line 7:
local index, headings, showtotal = {}, {}, {}
local cols, rounds = 0, 1
local winner, winner_votesvalid = {0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
local valid = {0, 0, 0}
local invalidblank = {tonumber(args.invalidblank) or 0,}
local invalid = {tonumber(args.invalid) or 0}
Line 63 ⟶ 62:
local stop_flag = false
local i = 0
local has_votes = args['votes' .. i]
local has_votes2 = args['votes' .. i .. '_2']
local has_votes3 = args['votes' .. i .. '_3']
Line 99:
args['votes' .. i] = votesi
valid[1] = valid[1] + votesi
has_votes = true
end
if args['party' .. i] then
has_party = true
end
--[[Do something like this to reduce code duplication below
local has_votes = {}
for j = 2, 13 do
if args['votes' .. i .. "_" .. j] then
has_votes[j] = true
end
end]]--
if args['votes' .. i .. '_2'] then
has_votes2 = true
end
if args['votes' .. i .. '_3'] then
has_votes3 = true
end
if args['votes' .. i .. '_4'] then
has_votes4 = true
end
if args['votes' .. i .. '_5'] then
has_votes5 = true
end
if args['votes' .. i .. '_6'] then
has_votes6 = true
end
if args['votes' .. i .. '_7'] then
has_votes7 = true
end
if args['votes' .. i .. '_8'] then
has_votes8 = true
end
if args['votes' .. i .. '_9'] then
has_votes9 = true
end
if args['votes' .. i .. '_10'] then
has_votes10 = true
end
if args['votes' .. i .. '_11'] then
has_votes11 = true
end
if args['votes' .. i .. '_12'] then
has_votes12 = true
end
if args['votes' .. i .. '_13'] then
has_votes13 = true
end
if args['nopercentage'] then
Line 186 ⟶ 228:
 
local ovalid = {valid[1], valid[2], valid[3], valid[4], valid[5], valid[6], valid[7], valid[8], valid[9], valid[10], valid[11], valid[12], valid[13]}
if has_votes or args['valid'] then
max_rows = max_rows + 1
local i = max_rows
table.insert(index, i)
args['row' .. i] = 'Total'
args['votes' .. i] = showtotal.votes and valid[1] or nil
args['votes' .. i .. '_2'] = showtotal.votes_2 and valid[2] or nil
args['votes' .. i .. '_3'] = showtotal.votes_3 and valid[3] or nil
args['votes' .. i .. '_4'] = showtotal.votes_4 and valid[4] or nil
args['votes' .. i .. '_5'] = showtotal.votes_5 and valid[5] or nil
args['votes' .. i .. '_6'] = showtotal.votes_6 and valid[6] or nil
args['votes' .. i .. '_7'] = showtotal.votes_7 and valid[7] or nil
args['votes' .. i .. '_8'] = showtotal.votes_8 and valid[8] or nil
args['votes' .. i .. '_9'] = showtotal.votes_9 and valid[9] or nil
args['votes' .. i .. '_10'] = showtotal.votes_10 and valid[10] or nil
args['votes' .. i .. '_11'] = showtotal.votes_11 and valid[11] or nil
args['votes' .. i .. '_12'] = showtotal.votes_12 and valid[12] or nil
args['votes' .. i .. '_13'] = showtotal.votes_13 and valid[13] or nil
args['colour' .. i] = 'inherit'
args['color' .. i] = 'inherit'
args['row' .. i] = 'Total'
args['font-weight' .. i] = 'bold'
args['class' .. i] = 'sortbottom'
Line 281 ⟶ 333:
row
:tag('th')
:wikitext(args.firstround or 'First count')
:attr('colspan', 2)
--[[consider using a smaller function which accepts a text to handle this
local function create_row(row, text)
row
:tag('th')
:wikitext(text)
:attr('colspan', 2)
return row
end
]]
if has_votes2 then
row
:tag('th')
:wikitext(args.secondround or 'Second count')
:attr('colspan', 2)
end
Line 292 ⟶ 354:
row
:tag('th')
:wikitext(args.thirdround or 'Third count')
:attr('colspan', 2)
end
Line 298 ⟶ 360:
row
:tag('th')
:wikitext(args.fourthround or 'Fourth count')
:attr('colspan', 2)
end
Line 304 ⟶ 366:
row
:tag('th')
:wikitext(args.fifthround or 'Fifth count')
:attr('colspan', 2)
end
Line 310 ⟶ 372:
row
:tag('th')
:wikitext(args.sixthround or 'Sixth count')
:attr('colspan', 2)
end
Line 381 ⟶ 443:
cols = cols + 2
if has_votes2 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes3 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes4 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes5 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes6 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes7 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes8 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes9 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes10 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes11 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes12 then
secondrow
:tag('th')
:wikitext('Votes')
:attr('scope', 'col')
:done()
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:done()
cols = cols + 2
end
if has_votes13 then
secondrow
:tag('th')
Line 405 ⟶ 599:
:tag('th')
:wikitext('3')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes4 then
secondrow
:tag('th')
:wikitext('4')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes5 then
secondrow
:tag('th')
:wikitext('5')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes6 then
secondrow
:tag('th')
:wikitext('6')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes7 then
secondrow
:tag('th')
:wikitext('7')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes8 then
secondrow
:tag('th')
:wikitext('8')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes9 then
secondrow
:tag('th')
:wikitext('9')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes10 then
secondrow
:tag('th')
:wikitext('10')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes11 then
secondrow
:tag('th')
:wikitext('11')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes12 then
secondrow
:tag('th')
:wikitext('12')
:attr('scope', 'col')
:done()
cols = cols + 1
end
if has_votes13 then
secondrow
:tag('th')
:wikitext('13')
:attr('scope', 'col')
:done()
Line 415 ⟶ 689:
end
 
local rsuff = (rounds > 1) and {'', '_2'} or (rounds > 2) and {'', '_3'} or (rounds > 3) and {'', '_4'} or (rounds > 4) and {'', '_5'} or (rounds > 5) and {'', '_6'} or (rounds > 6) and {'', '_7'} or (rounds > 7) and {'', '_8'} or (rounds > 8) and {'', '_9'} or (rounds > 9) and {'', '_10'} or (rounds > 10) and {'', '_11'} or (rounds > 11) and {'', '_12'} or (rounds > 12) and {'', '_13'} or {''}
for i, v in ipairs(index) do
local has_votesrow = args['votes' .. v] or args['ivotes' .. v] or args['avotes' .. v] or args['ipct' .. v] or args['apct' .. v] or args['atotal' .. v]
local has_seatsrowhas_votesrow2 = args['seatsvotes' .. v .. '_2'] or args['iseatsivotes' .. v .. '_2'] or args['aseatsavotes' .. v .. '_2'] or args['ipct' .. v .. '_2']
local has_votesrow2has_votesrow3 = args['votes' .. v .. '_2_3'] or args['ivotes' .. v .. '_2_3'] or args['avotes' .. v .. '_2_3'] or args['ipct' .. v .. '_2'] or args['apct' .. v .. '_2'] or args['atotal' .. v .. '_2_3']
local has_seatsrow2has_votesrow4 = args['seatsvotes' .. v .. '_2_4'] or args['iseatsivotes' .. v .. '_2_4'] or args['aseatsavotes' .. v .. '_2_4'] or args['ipct' .. v .. '_4']
local has_votesrow3has_votesrow5 = args['votes' .. v .. '_3_5'] or args['ivotes' .. v .. '_3_5'] or args['avotes' .. v .. '_3_5'] or args['ipct' .. v .. '_3'] or args['apct' .. v .. '_3'] or args['atotal' .. v .. '_3_5']
local has_seatsrow3has_votesrow6 = args['seatsvotes' .. v .. '_3_6'] or args['iseatsivotes' .. v .. '_3_6'] or args['aseatsavotes' .. v .. '_3_6'] or args['ipct' .. v .. '_6']
local has_votesrow7 = args['votes' .. v .. '_7'] or args['ivotes' .. v .. '_7'] or args['avotes' .. v .. '_7'] or args['ipct' .. v .. '_7']
local has_votesrow8 = args['votes' .. v .. '_8'] or args['ivotes' .. v .. '_8'] or args['avotes' .. v .. '_8'] or args['ipct' .. v .. '_8']
local has_votesrow9 = args['votes' .. v .. '_9'] or args['ivotes' .. v .. '_9'] or args['avotes' .. v .. '_9'] or args['ipct' .. v .. '_9']
local has_votesrow10 = args['votes' .. v .. '_10'] or args['ivotes' .. v .. '_10'] or args['avotes' .. v .. '_10'] or args['ipct' .. v .. '_10']
local has_votesrow11 = args['votes' .. v .. '_11'] or args['ivotes' .. v .. '_11'] or args['avotes' .. v .. '_11'] or args['ipct' .. v .. '_11']
local has_votesrow12 = args['votes' .. v .. '_12'] or args['ivotes' .. v .. '_12'] or args['avotes' .. v .. '_12'] or args['ipct' .. v .. '_12']
local has_votesrow13 = args['votes' .. v .. '_13'] or args['ivotes' .. v .. '_13'] or args['avotes' .. v .. '_13'] or args['ipct' .. v .. '_13']
row = root:tag('tr')
:addClass(args['class' .. v])
Line 431 ⟶ 712:
local rcolor = get_color(args['rcolour' .. v] or args['rcolor' .. v] or nil)
 
if args['row' .. v] and has_party then
row
:css('background-color', rcolor)
:tag('td')
:attr('colspan', 3)
:wikitext(args['row' .. v])
end
if args['row' .. v] and not has_party then
row
:css('background-color', rcolor)
:tag('td')
:wikitext(args['row' .. v])
end
if has_party and not args['row' .. v] then
row
:tag('td')
Line 444 ⟶ 738:
:wikitext(args['cand' .. v])
end
if has_party and not args['row' .. v] then
row
:tag('td')
:wikitext(args['party' .. v])
end
if args['row' .. v]has_votes then
row
:css('background-color', rcolor)
:tag('td')
:wikitext(args['row' .. v])
end
if not has_nopercentage then
row:tag('td')
:css('text-align', 'right')
:wikitext(fmt(args['votes' .. v]))
end
row:tag('td')
:css('text-align', 'right')
:wikitext(pct(args['votes' .. v], valid[1]))
if has_nopercentage then
row:tag('td')
:css('text-align', 'right')
:wikitext(fmt(args['votes' .. v]))
end
if args['votes' .. v .. '_2'] then
Line 588 ⟶ 871:
:wikitext(pct(args['votes' .. v .. '_13'], valid[13]))
end
end
 
-- separating line
Line 601 ⟶ 885:
-- valid votes
 
local cs = cols - 2*rounds3 - (has_votes2has_party and 2 or 0) + (has_percentage and 1 or 02)
 
if args['invalidblank'] or args['invalid'] then
Line 812 ⟶ 1,096:
end
return tostring(root) .. tracking
end
end