Module:SongContestData
Appearance
| This module is rated as pre-alpha. It is incomplete and may or may not be in active development. Do not use it in article namespace pages. A module remains in pre-alpha until its developer, or another editor who adopts it if it is abandoned for some time, considers the basic structure complete. |
| This module depends on the following other modules: |
Implements Template:SongContestData
Subpages
Usage
Data tables
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
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
main
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
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}}41{{#invoke:SongContestData|entryAmount|esc|2019|sf1}}41{{#invoke:SongContestData|entryAmount|esc|2019|sf2}}41{{#invoke:SongContestData|entryAmount|esc|2019|gf}}41
order
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 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 sortEntries(data, att, dir)
-- deep copy since data is non writable
local entries = {}
for _,v in pairs(data) do table.insert(entries, v) end
-- filter entries that do not have att
local filtered_data = {}
for _,v in pairs(entries) do
if value[att] then -- keep entries with valid att
table.insert(filtered_data, value)
end
end
-- sort entries based on att
table.sort(filtered_data, function(a, b)
if dir == 'a' then
return a[att] < b[att]
elseif dir == 'd' then
return a[att] > b[att]
end
end)
return filtered_data
end
function p.main(f)
local args = getArgs(f)
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
function p.entryAmount(f)
local args = getArgs(f)
local data = getData(args[1], args[2])
local amount = 0
for _ in pairs(data) do amount = amount + 1 end
return amount
end
function p.order(f)
local args = getArgs(f)
local data = getData(args[1], args[2])
local dir = args[4] or 'a' -- default ascending
return sortEntries(data, args(f)[3], dir)
end
return p