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: |
Usage
The module looks for data in Module:SongContestData/
{{{1}}}
/{{{2}}}
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}}
Keiino{{#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 |
- Examples
{{#invoke:SongContestData|entryAmount|esc|2019}}
41
order
- Required parameters
Parameter | Description |
---|---|
|1=
|
Contest |
|2=
|
Year |
|3=
|
Attribute to sort |
- Optional parameters
Parameter | Description | Default |
---|---|---|
|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 sortEntries(data, att, desc)
-- 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)
return desc and a[att] > b[att] or a[att] < b[att]
end)
return filtered_data
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 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])
return sortEntries(data, args[3], args[4])
end
return p