Difference between revisions of "Module:Sandbox/Jc86035/2"
Jump to navigation
Jump to search
blackwiki>Jc86035 m (dump) |
blackwiki>Jc86035 m (basic functionality) |
||
| Line 37: | Line 37: | ||
local result = '–' | local result = '–' | ||
| + | local highest, references | ||
local entity = mw.wikibase.getEntity(qid) | local entity = mw.wikibase.getEntity(qid) | ||
| Line 42: | Line 43: | ||
local data = entity.claims['P2291'] | local data = entity.claims['P2291'] | ||
if data and data[1] then | if data and data[1] then | ||
| − | + | for k, v in pairs(data) do | |
| − | + | if v.mainsnak.datavalue.value.id == chart then | |
| − | + | local tmp = tonumber(v.qualifiers.P1352[1].datavalue.value.amount) | |
| + | if tmp and (not highest or tmp > highest) then | ||
| + | highest = tmp | ||
| + | references = v.references -- for later implementation of references | ||
| + | end | ||
| + | end | ||
| + | end | ||
end | end | ||
end | end | ||
| − | return | + | result = tostring(highest) or result |
| + | |||
| + | return result | ||
end | end | ||
Revision as of 06:13, 14 August 2018
Documentation for this module may be created at Module:Sandbox/Jc86035/2/doc
local p = {}
local charts = {
-- CANADA
['CANADIAN HOT 100'] = 'Q472737',
['CA100'] = 'Q472737',
['CA-SINGLES'] = 'Q472737',
['CANADIAN ALBUMS CHART'] = 'Q680355',
['CANADIAN ALBUMS'] = 'Q680355',
['CA-ALBUMS'] = 'Q680355',
-- UNITED STATES
['BILLBOARD HOT 100'] = 'Q180072',
['BILLBOARD 100'] = 'Q180072',
['BB100'] = 'Q180072',
['US-SINGLES'] = 'Q180072',
['BILLBOARD 200'] = 'Q188819',
['BB200'] = 'Q188819',
['US-ALBUMS'] = 'Q188819',
}
local getArgs = require('Module:Arguments').getArgs
local function makeInvokeFunction(funcName)
-- makes a function that can be returned from #invoke, using
-- [[Module:Arguments]].
return function (frame)
local args = getArgs(frame, {parentFirst = true})
return p[funcName](args, frame)
end
end
p._main = function(args, frame)
local chart = mw.ustring.upper(args[1])
local qid = args[2]
if charts[chart] then chart = charts[chart] end
local result = '–'
local highest, references
local entity = mw.wikibase.getEntity(qid)
if entity and entity.claims then
local data = entity.claims['P2291']
if data and data[1] then
for k, v in pairs(data) do
if v.mainsnak.datavalue.value.id == chart then
local tmp = tonumber(v.qualifiers.P1352[1].datavalue.value.amount)
if tmp and (not highest or tmp > highest) then
highest = tmp
references = v.references -- for later implementation of references
end
end
end
end
end
result = tostring(highest) or result
return result
end
p.main = makeInvokeFunction('_main')
return p