Module:Election results-STV: Difference between revisions

Content deleted Content added
?
+
 
(14 intermediate revisions by 2 users not shown)
Line 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 98 ⟶ 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
Line 218 ⟶ 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
Line 237 ⟶ 248:
args['colour' .. i] = 'inherit'
args['color' .. i] = 'inherit'
args['row' .. i] = 'Total'
args['font-weight' .. i] = 'bold'
args['class' .. i] = 'sortbottom'
Line 323 ⟶ 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 334 ⟶ 354:
row
:tag('th')
:wikitext(args.thirdround or 'Third count')
:attr('colspan', 2)
end
Line 340 ⟶ 360:
row
:tag('th')
:wikitext(args.fourthround or 'Fourth count')
:attr('colspan', 2)
end
Line 346 ⟶ 366:
row
:tag('th')
:wikitext(args.fifthround or 'Fifth count')
:attr('colspan', 2)
end
Line 352 ⟶ 372:
row
:tag('th')
:wikitext(args.sixthround or 'Sixth count')
:attr('colspan', 2)
end
Line 423 ⟶ 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 560 ⟶ 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 573 ⟶ 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 717 ⟶ 871:
:wikitext(pct(args['votes' .. v .. '_13'], valid[13]))
end
end
 
-- separating line
Line 730 ⟶ 885:
-- valid votes
 
local cs = cols - 2*rounds3 - (has_votes2has_party and 2 or 0) + (has_nopercentage and 1 or 02)
 
if args['invalidblank'] or args['invalid'] then
Line 941 ⟶ 1,096:
end
return tostring(root) .. tracking
end
end