Module:SongContestData
Appearance
![]() | This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
![]() | This module depends on the following other modules: |
Implements Template:SongContestData
Subpages
[edit]Usage
[edit]Data tables
[edit]The module looks for data in Module:SongContestData/
, with {{{1}}}
/{{{2}}}
{{{1}}}
being the contest, and {{{2}}}
being the year. All of these subpages should return a table consisting of a list of entries, identified by the ISO country code of the country that competed. Each of these entries consist of another table, with a list of all attributes of the entry, as shown below:
return {
al = {
number = 1,
artist = 'Singer',
title = 'Song',
-- etc
},
ad = {
-- attributes
},
am = {
-- attributes
},
-- etc
}
Attributes
[edit]Below is a full list of all the attributes that the data templates may use:
Attribute | Value | Description | Example |
---|---|---|---|
number
|
number
|
Unique entry number of the song in the contest; increases with every new entry across all editions of the contest. | number = 1556,
|
broadcaster
|
string
|
The broadcaster that provided the entry. Must be an identifier from Template:Broadcaster for the corresponding country. | broadcaster = 'avrotros',
|
artistn
|
string
|
The nth artist's stage name. Must only be used when the artist uses a stage name with that entry (i.e. no first + last name). The n digit may be omitted if they're the first or only artist. Do not use the same n digit for artist_firstn and artist_lastn in the case of combining multiple artists.
|
artist = '5miinust', artist2 = 'Puuluup',
|
artist_firstn
|
The nth artist's first and last name. Must always be used in combination with each other, using the same n digit. The n digit may be omitted if they're the first or only artist. Do not use the same n digit for artistn in the case of combining multiple artists.
|
artist_first = 'Zala', artist_last = 'Kralj', artist_first2 = 'Gašper', artist_last2 = 'Šantl',
| |
artist_lastn
| |||
artist_articlen
|
Wikipedia article name of the nth artist. The n digit may be omitted if they're the first or only artist. All artists should generally have a link to the artist's article or a redirect to an article. Please note WP:NOTBROKEN. |
article_artist = 'zalagasper',
| |
artist_onelink
|
boolean
|
Used by Template:SongContestArtist. When set to true , it takes artist_article1 and spans the link over all artists, instead of an individual link for every artist.
|
artist_onelink = true,
|
artist_featn
|
string
|
The nth featuring artist's stage name. Must only be used when the artist uses a stage name with that entry (i.e. no first + last name). The n digit may be omitted if they're the first or only artist. Do not use the same n digit for artist_feat_firstn and artist_feat_lastn in the case of combining multiple artists.
|
|
artist_feat_firstn
|
The nth featuring artist's first and last name. Must always be used in combination with each other, using the same n digit. The n digit may be omitted if they're the first or only artist. Do not use the same n digit for artist_featn in the case of combining multiple artists.
|
||
artist_feat_lastn
| |||
artist_feat_articlen
|
Wikipedia article name of the nth featuring artist. The n digit may be omitted if they're the first or only artist. All artists should generally have a link to the artist's article or a redirect to an article. Please note WP:NOTBROKEN. | ||
artist_feat_onelink
|
boolean
|
Used by Template:SongContestArtist. When set to true , it takes artist_feat_article1 and spans the link over all artists, instead of an individual link for every artist.
|
|
title
| |||
title_article
| |||
title_lang
| |||
title_native
| |||
title_native_script
| |||
lang
| |||
writer
| |||
sf
| |||
sf_draw
| |||
sf_pl
| |||
sf_pt
| |||
sf_q
| |||
gf
| |||
gf_draw
| |||
gf_pl
| |||
gf_pt
|
Functions
[edit]main
[edit]Returns an attribute value from an entry
{{#invoke:SongContestData|main}}
- Required parameters
Parameter | Description |
---|---|
|1=
|
Contest |
|2=
|
Year |
|3=
|
Entry |
|4=
|
Attribute |
- Examples
{{#invoke:SongContestData|main|esc|2019|no|artist}}
{{#invoke:SongContestData|main|esc|2019|no|title}}
Spirit in the Sky{{#invoke:SongContestData|main|esc|2019|no|gf_pt}}
331
entryAmount
[edit]Returns the amount of entries in a given contest year
{{#invoke:SongContestData|entryAmount}}
- Required parameters
Parameter | Description |
---|---|
|1=
|
Contest |
|2=
|
Year |
- Optional parameters
Parameter | Description |
---|---|
|3=
|
Show |
- Examples
{{#invoke:SongContestData|entryAmount|esc|2019}}
41{{#invoke:SongContestData|entryAmount|esc|2019|sf}}
35{{#invoke:SongContestData|entryAmount|esc|2019|sf1}}
17{{#invoke:SongContestData|entryAmount|esc|2019|sf2}}
18{{#invoke:SongContestData|entryAmount|esc|2019|gf}}
26
order
[edit]Returns a sorted table of the entries from a contest.
- Required parameters
Parameter | Description |
---|---|
|1=
|
Contest |
|2=
|
Year |
- Optional parameters
Parameter | Description | Default |
---|---|---|
|3=
|
Attribute to sort. If unset, the function defaults to sorting by its common country name in English | |
|desc=
|
Sorts descending if set, otherwise sorts ascending | |
|excludeAtt='String'
|
Excludes entries with set attribute | |
|excludeVal=value
|
Excludes entries where the value of the |excludeAtt= attribute is equal to this parameter
|
|
|excludeInvert=true/false
|
Inverts exclusion. Excludes entries where the value of the |excludeAtt= attribute is not equal to |excludeVal=
|
false |
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
local function processOutput(o)
if type(o) == "table" then
local result = {}
for _, v in pairs(o) do
table.insert(result, tostring(v))
end
return table.concat(result, ";")
end
return o
end
local function getData(contest, year)
return mw.loadData('Module:SongContestData/'..contest..'/'..year)
end
local function filterData(data, att, excludeAtt, excludeVal, excludeInvert)
-- copy data table and filter entries that have exclude
local filtered_data = {}
for k, v in pairs(data) do
local shouldExclude = (excludeAtt and v[excludeAtt] == nil) or
(excludeAtt and v[excludeAtt] and excludeVal and (
(not excludeInvert and v[excludeAtt] == excludeVal) or -- normal exclusion
(excludeInvert and v[excludeAtt] ~= excludeVal) -- inverted exclusion
))
if (v[att] or not att) and not shouldExclude then
filtered_data[k] = v
end
end
return filtered_data
end
local function sortEntries(data, att, desc)
-- store original keys for sorting
local keys = {}
for k in pairs(data) do
table.insert(keys, k)
end
if not att then
-- use the common country name for sorting instead of ISO country code when no attribute is provided
local isoName = require('Module:ISO 3166').luaname
local nameMap = {}
for _, k in ipairs(keys) do
nameMap[k] = isoName({k}) or k -- precompute names
end
-- sort keys alphabetically
table.sort(keys, function(a, b)
local aName = nameMap[a]
local bName = nameMap[b]
return desc and aName > bName or aName < bName
end)
else
-- sort keys based on the corresponding attribute values
table.sort(keys, function(a, b)
local aVal, bVal = data[a][att], data[b][att]
return desc and aVal > bVal or aVal < bVal
end)
end
return keys
end
p.main = makeInvokeFunc('_main')
function p._main(args)
local data = getData(args[1], args[2])
local entryData = data[args[3]]
if entryData and entryData[args[4]] then
return processOutput(entryData[args[4]])
end
return ""
end
p.entryAmount = makeInvokeFunc('_entryAmount')
function p._entryAmount(args)
local data = getData(args[1], args[2])
local show = args[3]
if show then
local code = string.match(show, "[a-zA-Z]+")
local num = tonumber(string.match(show, "%d+"))
data = filterData(data, nil, code, num, true)
end
local amount = 0
for _ in pairs(data) do amount = amount + 1 end
return amount
end
p.order = makeInvokeFunc('_order')
function p._order(args)
local data = getData(args[1], args[2])
local att = args[3]
local filtered_data = filterData(data, att, args['excludeAtt'], args['excludeVal'], args['excludeInvert'] or false)
return sortEntries(filtered_data, att, args['desc'] or false)
end
p.getEntryData = makeInvokeFunc('_getEntryData')
function p._getEntryData(args)
local data = getData(args[1], args[2])
return data[args[3]]
end
return p