Module:Sandbox/Jc86035/2 Explained

local p =

-- CHARTS TABLE – Wikidata entity IDs for each chart.local charts =

local getArgs = require('Module:Arguments').getArgs

local function makeInvokeFunction(funcName) -- makes a function that can be returned from #invoke, using -- . return function (frame) local args = getArgs(frame,) return p[funcName](args, frame) endend

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 i, v in ipairs(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 = i end end end references = references and data[references].references end end result = highest and tostring(highest) or result return resultend

p.main = makeInvokeFunction('_main')

return p