----- Cell colors -----local COL_FST = 'gold' -- 1st placelocal COL_SND = 'silver' -- 2nd placelocal COL_TRD = '#C96' -- 3rd placelocal COL_LST = '#FE8080' -- Last placelocal COL_SFQ = 'navajowhite' -- Semi-Final qualifierlocal COL_BJQ = 'paleturquoise' -- Backup jury qualifierlocal COL_DSQ = '#A4EAA9' -- Disqualifed / withdrawn entry
----- Text -----local AQ = 'Automatic qualifier'local NQ = 'Failed to qualify'local NOSEMI = 'No semi-finals'local NA = 'N/A'local MILLSTREET = 'Kvalifikacija za Millstreet'local ESC1996Q = 'Eurovision Song Contest 1996#Qualifying round'
----------------------------------------------------------------------------------------------------
local getArgs = require('Module:Arguments').getArgslocal p =
local amountOfEntrieslocal usedLanguages =
function p.entry(f) return main(f, 'entry') endfunction p.year(f) return main(f, 'year') endfunction p.country(f) return main(f, 'country') endfunction p.list(f) return main(f, 'list') end
function main(f, reqOutput) local args = getArgs(f) local html = local contest = getContest(args['cont']) local id = args['id'] local country = args['cnty'] local year = args['y'] local show = args['s'] local entryNo = args['no'] local sortMethod = if not show then show = 'gf' end if not entryNo then entryNo = 1 end if show
'year' or reqOutput
'country' then -- Get all entries from year entries = getAllEntriesFrom else end amountOfEntries = tableLen(entries) local function getEntryNo(entry) local entryNo = 1 if entry.cntye then entryNo = entry.cntye end return entryNo end if reqOutput
--------------------------------------------------
local row = 0local spannedRows = local spannedCols = function createEntryRow(args) local html = local f = mw.getCurrentFrame local contest = args.contest local year = args.year local country = args.country if country and country['name'] then for i, name in ipairs(country['name']) do if name[2] then if contest.dates[tostring(year)] < name[2] then country = name[1] break end end country = name[1] end end local id = args.id local entryNo = args.entryNo local reqOutput = args.reqOutput local show = args.show local entry if country and year then entry = getEntry elseif id then entry = getEntry end if entry then row = row + 1 spannedCols = local id = entry.id local year = f:expandTemplate local draw local sf_draw = insertZeroBeforeSingleDigit(entry.sf_d) local gf_draw = insertZeroBeforeSingleDigit(entry.gf_d) if not sf_draw then sf_draw = entry.sf_h end if not gf_draw then gf_draw = entry.gf_h end local pl, pt local sf_pl = entry.sf_pl local gf_pl = entry.gf_pl local sf_pt = entry.sf_pt local gf_pt = entry.gf_pt if show then if show
usedLang then if songLang[2] then table.insert(lang, songLang[2]) else table.insert(lang, songLang[1]) end found = true end end if not found then table.insert(lang, createLangLink(songLang)) table.insert(usedLanguages, songLang[1]) end else table.insert(lang, createLangLink(songLang)) table.insert(usedLanguages, songLang[1]) end end if reqOutput
'year' then entryData = entryDataText = replaceNilValues(entryData, entryData) elseif reqOutput
'list' then entryData = entryDataText = replaceNilValues(entryData, entryData) end local function isNil(row) if entryData[row]
'year' then if (show
1 then rowStyling = 'font-weight:bold; background:' .. COL_FST .. ';' elseif (show
'sf1' or show
'string' and string.sub(data, 1, 4)
'country' then local gf_pl = getIndex(entryDataText, 'gf_pl') local gf_pt = getIndex(entryDataText, 'gf_pt') local sf_pl = getIndex(entryDataText, 'sf_pl') local sf_pt = getIndex(entryDataText, 'sf_pt') local colspan = 1 if not entry.id and entry.dq then if entryDataText[i]
2020 then data = 'Contest cancelled' else data = entry.dq end data = data .. ' X' colspan = 4 else break end else if gf_pt and isNil(gf_pt) then -- If no gf points if not isNil(sf_pl) or not isNil(sf_pt) then if entryDataText[i]
'esc' then if entry.y
1996 then data = '' .. NQ .. ' X' end end colspan = 2 end else if entryDataText[i]
'gf_pl' and gf_pl and isNil(gf_pl) then -- If no gf points and no gf placement data = NQ end end if entryDataText[i]
'esc' and entry.y
'esc' and entry.y >= 2004 then if (not isNil(gf_pl) and not isNil(gf_pt)) or entry.q then data = AQ colspan = 2 end else data = NOSEMI colspan = 2 end end end end if data then cellStyling = f:expandTemplate else data = end if colspan > 1 then cellStyling = cellStyling .. '; colspan="' .. colspan .. '"' if data
'id' or entryDataText[i]
'gf' and sf_draw then data = '' .. data .. '' end elseif entryDataText[i]
'gf' and not entry.gf_d and entry.gf_h) or (show
'sf2' or show
1 then data = '1st half' end if data
'year' then -- Year column cellStyling = 'text-align:center' elseif entryDataText[i]
'lang' then if type(data)
'table' then for _, v in ipairs(entry.langm) do createNote(v) end else createNote(langm) end end elseif entryDataText[i]
'pt' or entryDataText[i]
'gf_pt' or entryDataText[i]
'sf_pt' then cellStyling = 'text-align:right;' if reqOutput
'country' then if reqOutput
'gf_pl' or entryDataText[i]
'sf_pl' or entryDataText[i]
'sf_pl' or entryDataText[i]
amountOfEntries) or ((entryDataText[i]
'gf_pt') and gf_pl
'pl' or entryDataText[i]
amountOfEntries) then cellStyling = cellStyling .. ' background:' .. COL_LST .. '"' --data = tostring(data) .. ' ◁' else if show
'country' then local pl = gf_pl if entryDataText[i]
'sf_pt' then pl = sf_pl end if pl
2 then cellStyling = cellStyling .. ' background:' .. COL_SND .. '"' end if pl
'sf' or show
'sf2') and (gf_pl or gf_pt) then if entry.jury then cellStyling = cellStyling .. ' background:' .. COL_BJQ .. '"' --data = tostring(data) .. ' ‡' else cellStyling = cellStyling .. ' background:' .. COL_SFQ .. '"' --data = tostring(data) .. ' †' end end end end if data
'country' and entryDataText[i] ~= 'year' and entryDataText[i] ~= 'sf_pl' and entryDataText[i] ~= 'sf_pt' then calcAmountOfEntries(contest.id, entry.y, 'gf') local x = amountOfEntries if gf_pl
2 then cellStyling = cellStyling .. ' background:' .. COL_SND end if gf_pl
x then cellStyling = cellStyling .. ' background:' .. COL_LST end if entry.dq or entry.nq then cellStyling = cellStyling .. ' background:' .. COL_DSQ end end if i
function getContest(x) local contests = mw.loadData('Module:Sandbox/TheThomanski/Esc/data').contests local reqContest = 'esc' -- Default ESC if x then reqContest = string.lower(x) end local result for _, contest in ipairs(contests) do -- For every contest do if contest.id
function getEntry(args) local result local contest = args.contest local country = args.country -- Table, macedonia local year = args.year local id = args.id local entryNo = args.entryNo -- For multiple entries per country in a year (e.g. ESC 1956) if type(contest)
year) then -- If the entry is from the requested year result = entry end end elseif id then if (entry.id
function getAllEntriesFrom(args) local contest = getContest(args.contest) local entries = local draw = 1 local q_d = 0 local firstEntry = nil for i, entry in ipairs(contest.values) do -- For every entry in the contest do if args.from
tonumber(args.year) then -- Get all entries from year if args.show then if (args.show
'sf1' and entry.sf
'sf2' and entry.sf
'gf' and (entry.gf_d or entry.q)) -- Get all entries from Grand Final then if args.show
'draw' and entry.id then local found = false local oldEntry = entry.id local newEntry = entry.id if firstEntry
draw then table.insert(entries, entry) draw = draw + 1 found = true else newEntry = newEntry + 1 entry = getEntry if not entry or entry.y ~= firstEntry.y then entry = firstEntry newEntry = entry.id end gf_d = entry.gf_d end end else table.insert(entries, entry) end end else table.insert(entries, entry) end elseif args.from
function getEntryNoFromCountry(contest, id) if id then local entry = getEntry local country = entry.cnty if country['name'] then country = country['name'][1][1] end local entries = getAllEntriesFrom local extraEntries = -- For more than one entry in a year (e.g. ESC 1956) for i, v in ipairs(entries) do if extraEntries[v.y] then extraEntries[v.y] = extraEntries[v.y] + 1 else extraEntries[v.y] = 0 end if v.id
function getSemi(contest, id) local entry = getEntry if entry then if entry.sf then return 'sf' .. tostring(entry.sf) elseif entry.sf_d then return 'sf' end end return nilend
function replaceNilValues(entryData, entryDataText) local length = tableLen(entryDataText) for i = 1, length do if not entryData[i] then entryData[i] = 'nil_' .. i end endend
function calcAmountOfEntries(contest, year, show) amountOfEntries = tableLen(getAllEntriesFrom)end
--------------------------------------------------
function insertZeroBeforeSingleDigit(x) if x then if x < 10 then x = '0' .. x end end return xend
function getIndex(tab, reqV) if type(tab)
reqV then return i end end end return nilend
function processTable(tab) local str = if type(tab)
function tableLen(tab) local x = 0 if tab then for _ in pairs(tab) do x = x + 1 end end return xend
function hasValue(tab, val) if tab then if type(tab)
val or (type(v)
'string' then if tab
return p