Module:Sandbox/AB-me/Eurovision scoreboard

local p = {}; local getArgs = require('Module:Arguments').getArgs; local frame = mw.getCurrentFrame;

local data = { year = nil, variant = nil, pointSystem = { 12, 10, 8, 7, 6, 5, 4, 3, 2, 1 }, contestants = {}, voters = {} };

local function handleCsvArg(key, value) if (value ~= nil) then local split = mw.text.split(value, ','); if (data[key] == nil or #data[key] == 0) then for i,v in ipairs(split) do				data[key][i] = frame:expandTemplate{ title = 'getalias', args = { v, 'shortname alias' }} end

end end end

local function writeTableHeader(stack) table.insert(stack, '|-' .. '\n'); table.insert(stack, '| colspan="2" style="background: #F2F2F2;" | ' .. '\n'); --table.insert(stack, '| ' .. '\n'); table.insert(stack, '|' .. frame:expandTemplate{ title = 'vert header', args = { nb = 'y', 'Total score' } } .. '\n') if (#data['voters'] > 0) then for i,v in ipairs(data.voters) do table.insert(stack, '|scope="col" ' .. frame:expandTemplate{ title = 'vert header', args = { nb = 'y', v }} .. '\n'); end end end

local function writeTableRow(stack, contestant, first) if (not first) then table.insert(stack, '|-' .. '\n'); end table.insert(stack, '|style="text-align:left;"|' .. contestant .. '\n'); local colCount = 0;

table.insert(stack, '|' .. '\n')

for i,v in ipairs(data.voters) do table.insert(stack, '|' .. '\n'); end end

local function _main(args) handleCsvArg('contestants', args.contestants); if (args.voters ~= nil) then handleCsvArg('voters', args.voters); else data.voters = data.contestants end local stack = {}; table.insert(stack, '{| class="wikitable plainrowheaders" style="text-align:center;"' .. '\n') writeTableHeader(stack); if (#data['contestants'] > 0) then table.insert(stack, '|-' .. '\n') table.insert(stack, '! rowspan="' .. #data.contestants .. '"' .. frame:expandTemplate{ title = 'vert header', args = { va = 'middle', 'Contestants' }} .. '\n') local first = true; for i,v in ipairs(data.voters) do			writeTableRow(stack, v, first); first = false; end end table.insert(stack, '|}' .. '\n') return table.concat(stack); end

function p.main(frame) local args = getArgs(frame); return _main(args); end

return p;