Module:Election results/sandbox: Difference between revisions

Content deleted Content added
+
+
 
(24 intermediate revisions by 3 users not shown)
Line 9:
local winner, winner_votes = {0, 0, 0}, {0, 0, 0}
local valid = {0, 0, 0}
local invalidblank = {tonumber(args.invalidblank) or 0, tonumber(args.invalidblank2) or 0, tonumber(args.invalidblank3) or 0}
local invalid = {tonumber(args.invalid) or 0, tonumber(args.invalid2) or 0, tonumber(args.invalid3) or 0}
local blank = {tonumber(args.blank) or 0, tonumber(args.blank2) or 0, tonumber(args.blank3) or 0}
Line 76 ⟶ 75:
local stop_flag = false
local i = 0
local has_votes = args['invalidblank'] or args['invalid'] or args['totalvotes'] or args['electorate'] or args['turnout']
local has_votes2 = args['invalidblank2'] or args['invalid2'] or args['totalvotes2'] or args['electorate2'] or args['turnout2']
local has_votes3 = args['votes' .. i .. '_3'] or args['ivotes' .. i .. '_3']
local has_seats2 = args['seats' .. i .. '_2'] or args['iseats' .. i .. '_2']
Line 142 ⟶ 141:
rounds = (rounds < 2) and 2 or rounds
end
if args['valid2'] or args['invalidblank2'] or args['invalid2'] or args['totalvotes2'] or args['electorate2'] or args['turnout2'] then
rounds = (rounds < 2) and 2 or rounds
end
Line 264 ⟶ 263:
-- build the table
local root = mw.html.create(args['embed'] and '' or 'table')
if args['embed'] == nil and args['floatright'] then
root
:addClass('wikitable sortable floatright')
:tag('tdcaption')
:wikitext(args.invalidnotecaption)
:done()
elseif args['invalidembed'] == nil then
root
:addClass('wikitable sortable')
Line 277 ⟶ 282:
:tag('th')
:css('text-align', 'center')
:css('backgroundcolor', 'var( --color-base, #F8F9FA202122 )')
:css('background', 'var( --background-color-neutral, #F8F9FA )')
:wikitext(args['image'])
end
Line 285 ⟶ 291:
:tag('td')
:css('text-align', 'center')
:css('backgroundcolor', 'var( --color-base, #F8F9FA202122 )')
:css('background', 'var( --background-color-neutral, #F8F9FA )')
end
topcell:tag('div')
Line 339 ⟶ 346:
:attr('rowspan', rowspan)
:attr('colspan', 2)
if headings['vp'] then
row
:tag('tdth')
:wikitext('Running mate')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done()
cols = cols + 1
end
row
:tag('th')
Line 366 ⟶ 382:
cols = cols + 1
end
if headings['vp'] and not has_alliance then
row
:tag('th')
Line 690 ⟶ 706:
:tag('td')
:attr('rowspan', args['candspan' .. v] or args['aspan' .. v])
:attr('scope', 'row')
:wikitext(args['cand' .. v])
end
Line 695 ⟶ 712:
row
:tag('td')
:attr('rowspan', args['candspan' .. v] or args['aspan' .. v])
:wikitext(args['vp' .. v])
end
Line 701 ⟶ 719:
:tag('td')
:attr('rowspan', args['aspan' .. v])
:attr('scope', 'row')
:wikitext(args['alliance' .. v])
end
Line 715 ⟶ 734:
:attr('rowspan', args['aspan' .. v])
:attr('colspan', 3)
:attr('scope', 'row')
:wikitext(args['alliance' .. v])
end
if args['alliance' .. v] and args['party' .. v] and not has_cand then
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:attr('scope', 'row')
:wikitext(args['alliance' .. v])
elseif args['alliance' .. v] and args['party' .. v] and args.dsv then
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:attr('scope', 'row')
:wikitext(args['alliance' .. v])
elseif roundsargs['alliance' >.. 1v] and args['invalid2party' .. v] then
row
:tag('td')
Line 723 ⟶ 755:
:wikitext(args['alliance' .. v])
end
if args['party' .. v] and not has_alliance orand args['cand' .. v] and has_party and not has_alliancedsv then
row
:tag('td')
:attr('scope', 'row')
:wikitext(args['party' .. v])
elseif args['party' .. v] and not has_cand and not has_alliance then
row
:tag('td')
:attr('scope', 'row')
:wikitext(args['party' .. v])
elseif args['party' .. v] and not has_alliance or args['cand' .. v] and has_party and not has_alliance then
row
:tag('td')
Line 733 ⟶ 775:
:tag('td')
:attr('colspan', cs)
:attr('scope', 'row')
:wikitext(args['row' .. v])
end
Line 753 ⟶ 796:
:tag('td')
:attr('colspan', 2)
:attr('scope', 'row')
:wikitext('Total')
end
Line 759 ⟶ 803:
:css('font-style', 'italic')
:tag('td')
:attr('scope', 'row')
:wikitext('Total')
end
Line 766 ⟶ 811:
:tag('td')
:attr('colspan', 3)
:attr('scope', 'row')
:wikitext('Total')
end
Line 1,039 ⟶ 1,085:
end
-- separating line
if args['valid'] or args['valid2'] or args['valid3'] or args['invalidblankinvalid'] or args['invalidblank2invalid2'] or args['invalidblank3invalid3'] or args['totalvotes'] or args['totalvotes2'] or args['totalvotes3'] or args['electorate'] or args['electorate2'] or args['electorate3'] or args['turnout'] or args['turnout2'] or args['turnout3'] or args['source'] then
row = root
:tag('tr')
Line 1,045 ⟶ 1,091:
row
:tag('td')
:css('backgroundcolor', 'var( --color-base, #eaecf0202122 )')
:css('background', 'var( --background-color-neutral, #eaecf0 )')
:attr('colspan', cols)
end
-- valid votes
if args['invalidblank'] or args['invalidblank2'] or args['invalidblank3'] or args['invalid'] or args['invalid2'] or args['invalid3'] then
row = root
:tag('tr')
Line 1,061 ⟶ 1,108:
:css('text-align', 'left')
:css('font-weight', 'normal')
:css('color', 'inherit')
:css('background', 'inherit')
if args['invalidblank'] or args['invalid'] then
row
:tag('td')
:wikitext(fmt(ovalid[1]))
:tag('td')
:wikitext(pct(ovalid[1], ovalid[1] + invalidblank[1] + invalid[1] + blank[1]))
elseif not args['invalid'] or not args['invalidblank'] then
row
:tag('td')
Line 1,093 ⟶ 1,141:
:wikitext()
end
if rounds > 1 and args['invalidblank2'] or rounds > 1 and args['invalid2'] then
row
:tag('td')
:wikitext(fmt(ovalid[2]))
:tag('td')
:wikitext(pct(ovalid[2], ovalid[2] + invalidblank[2] + invalid[2] + blank[2]))
elseif rounds > 1 and not args['invalidblank2'] or rounds > 1 and not args['invalid2'] then
row
:tag('td')
Line 1,124 ⟶ 1,172:
:wikitext()
end
if args['invalidblank3'] or args['invalid3'] then
row
:tag('td')
:wikitext(fmt(ovalid[3]))
:tag('td')
:wikitext(pct(ovalid[3], ovalid[3] + invalidblank[3] + invalid[3] + blank[3]))
elseif has_seats3 and not args['invalidblank3'] or has_seats3 and not args['invalid3'] then
row
:tag('td')
Line 1,157 ⟶ 1,205:
:addClass('sortbottom')
:css('text-align', 'right')
if args['invalidblankinvalidonly'] or args['blank'] then
row
:tag('th')
:wikitext('Invalid/blank votes')
:wikitext(args.invalidnote)
:attr('scope', 'row')
:attr('colspan', cs)
:css('text-align', 'left')
:css('font-weight', 'normal')
:css('color', 'inherit')
:css('background', 'inherit')
else
elseif args['invalid'] then
row
:tag('th')
:wikitext('Invalid/blank votes')
:wikitext(args.invalidnote)
:attr('scope', 'row')
Line 1,176 ⟶ 1,224:
:css('text-align', 'left')
:css('font-weight', 'normal')
:css('color', 'inherit')
:css('background', 'inherit')
end
if args['invalidblankinvalid'] then
row
:tag('td')
:wikitext(fmt(invalidblank[1]))
:tag('td')
:wikitext(pct(invalidblank[1], ovalid[1] + invalidblank[1]))
elseif args['invalid'] then
row
:tag('td')
Line 1,190 ⟶ 1,233:
:tag('td')
:wikitext(pct(invalid[1], ovalid[1] + invalid[1] + blank[1]))
elseif not args['invalidblank'] or not args['invalid'] then
row
:tag('td')
Line 1,215 ⟶ 1,258:
:wikitext()
end
if rounds > 1 and args['invalidblank2invalid2'] then
row
:tag('td')
:wikitext(fmt(invalidblank[2]))
:tag('td')
:wikitext(pct(invalidblank[2], ovalid[2] + invalidblank[2]))
elseif rounds > 1 and args['invalid2'] then
row
:tag('td')
Line 1,227 ⟶ 1,264:
:tag('td')
:wikitext(pct(invalid[2], ovalid[2] + invalid[2] + blank[2]))
elseif rounds > 1 and not args['invalid2'] or rounds > 1 and not args['invalidblank2'] then
row
:tag('td')
Line 1,252 ⟶ 1,289:
:wikitext()
end
if has_seats3 and args['invalidblank3invalid3'] or has_votes3 and args['invalidblank3invalid3'] then
row
:tag('td')
:wikitext(fmt(invalidblank[3]))
:tag('td')
:wikitext(pct(invalidblank[3], ovalid[3] + invalidblank[3] + invalid[3] + blank[3]))
elseif has_seats3 and args['invalid3'] or has_votes3 and args['invalid3'] then
row
:tag('td')
Line 1,264 ⟶ 1,295:
:tag('td')
:wikitext(pct(invalid[3], ovalid[3] + invalid[3] + blank[3]))
elseif has_seats3 and not args['invalidblank3'] or has_seats3 and not args['invalid3'] then
row
:tag('td')
Line 1,288 ⟶ 1,319:
end
-- blank votes
if args['blank'] or args['blank2'] or args['blank3'] then
row = root:tag('tr')
:addClass('sortbottom')
Line 1,299 ⟶ 1,330:
:css('text-align', 'left')
:css('font-weight', 'normal')
:css('color', 'inherit')
:css('background', 'inherit')
elseifif args['invalidblank'] then
row
:tag('td')
:wikitext(fmt(blank[1]))
:tag('td')
:wikitext(pct(blank[1], ovalid[1] + invalid[1] + blank[1]))
else
row
:tag('td')
:wikitext(fmt(invalidblank[1]))
:tag('td')
:wikitext(fmt(invalidblank[2]))
end
if has_seats2 and not headings['sw'] then
row
Line 1,384 ⟶ 1,424:
end
-- total
if args['invalidblank'] or args['invalid'] or args['totalvotes'] or args['invalidblank2'] or args['invalid2'] or args['totalvotes2'] then
row = root:tag('tr')
:addClass('sortbottom')
Line 1,397 ⟶ 1,437:
:css('background', 'inherit')
:css('color', 'inherit')
if not args['totalvotes'] and args['invalid'] or not args['totalvotes'] and args['invalidblank'] then
row
:tag('td')
:wikitext(fmt(ovalid[1] + invalidblank[1] + invalid[1] + blank[1]))
:tag('td')
:wikitext(pct(1, 1))
Line 1,409 ⟶ 1,449:
:tag('td')
:wikitext('–')
elseif not args['invalid'] and not args['totalvotes'] or not args['invalidblank'] and not args['totalvotes']then
row
:tag('td')
Line 1,434 ⟶ 1,474:
:wikitext()
end
if rounds > 1 and args['invalid2'] and not args['totalvotes2'] or rounds > 1 and args['invalidblank2'] and not args['totalvotes2'] then
row
:tag('td')
:wikitext(fmt(ovalid[2] + invalidblank[2] + invalid[2] + blank[2]))
:tag('td')
:wikitext(pct(1, 1))
Line 1,471 ⟶ 1,511:
:wikitext()
end
if has_seats3 and not args['totalvotes3'] and args['invalidblank3invalid3'] or has_votes3 and not args['totalvotes3'] and args['invalid3'] then
row
:tag('td')
:wikitext(fmt(ovalid[3] + invalidblank[3] + invalid[3] + blank[3]))
:tag('td')
:wikitext(pct(1, 1))
Line 1,523 ⟶ 1,563:
:tag('td')
:wikitext(fmt(electorate[1]))
if args['invalidblank'] and args['electorate'] and not args['totalvotes'] or args['invalid'] and args['electorate'] and not args['totalvotes'] then
row
:tag('td')
:wikitext(args.turnout or pct(ovalid[1] + invalidblank[1] + invalid[1] + blank[1], electorate[1]))
elseif args['totalvotes'] and args['electorate'] then
row
Line 1,562 ⟶ 1,602:
:tag('td')
:wikitext(fmt(electorate[2]))
if args['invalid2'] and args['electorate2'] or args['invalidblank2'] and args['electorate2'] then
row
:tag('td')
:wikitext(args.turnout2 or pct(ovalid[2] + invalidblank[2] + invalid[2] + blank[2], electorate[2]))
elseif args['totalvotes2'] and args['electorate2'] then
row
Line 1,602 ⟶ 1,642:
:tag('td')
:wikitext(fmt(electorate[3]))
if args['invalid3'] and args['electorate3'] or args['invalidblank3'] and args['electorate3'] then
row
:tag('td')
:wikitext(args.turnout3 or pct(ovalid[3] + invalidblank[3] + invalid[3] + blank[3], electorate[3]))
elseif args['totalvotes3'] and args['electorate3'] then
row
Line 1,643 ⟶ 1,683:
row
:tag('td')
:css('backgroundcolor', 'var( --color-base, #eaecf0202122 )')
:css('background', 'var( --background-color-neutral, #eaecf0 )')
:attr('colspan', cols)
end
Line 1,657 ⟶ 1,698:
:css('text-align', 'left')
:css('font-weight', 'normal')
:css('color', 'inherit')
:css('background', 'inherit')
for k=1, rounds do
Line 1,715 ⟶ 1,757:
:css('text-align', 'left')
:css('font-weight', 'normal')
:css('color', 'inherit')
:css('background', 'inherit')
for k=1, rounds do