local libraryUtil = require('libraryUtil')
local p =
--Award class.--local function Award(o) local Award = o or local checkSelf = libraryUtil.makeCheckSelfFunction('Sandbox/Gonnym/sometest8', 'Award', Award, 'Sandbox/Gonnym/sometest8 object')
function Award:setWins(value) if (value) then Award.numOfWins = value else Award.numOfWins = 0 end end function Award:setNominations(value) if (value) then Award.numOfNominations = value else Award.numOfNominations = 0 end end return Awardend
local function isValidParameter(param, pattern) if (mw.ustring.sub(param, -mw.ustring.len(pattern), -1)
--Local function which is used to compare entries in a list.--local function compare(a, b) return a[1] < b[1]end
local function getOrderedArgs(args) local orderedArgs = local i = 1 for k, v in pairs(args) do orderedArgs[i] = i = i + 1 end
table.sort(orderedArgs, compare) return orderedArgsend
local function getAwardsList(args) local orderedArgs = getOrderedArgs(args) local list = local data = mw.loadData('Module:Sandbox/Gonnym/sometest8/awards')
for i, v in ipairs(orderedArgs) do local currentArg = orderedArgs[i] local paramName = currentArg[1] local value = currentArg[2] mw.log("Param name: " .. paramName)
local awardName = data.getAwardNameFromParameter[paramName:sub(1, -2)] -- Check if parameter is on the award list. if (awardName) then local award = Award -- Check if award was already added to list. if (list[awardName]) then -- Award was present in list; Use previous entry. award = list[awardName] else -- New award in list; Create new entry. award.name = awardName end -- Check if the award is for Nominations or Wins. if (isValidParameter(paramName, "N")) then award.numOfNominations = value list[awardName] = award elseif (isValidParameter(paramName, "W")) then award.numOfWins = value list[awardName] = award else -- Not one of the above; Might be a malformed parameter name. end
-- The parameter is not on the award list; Check if it is a custom "award" parameter. elseif (paramName:sub(1, -2)
end
return listend
function p._orderAwards(args) local list = getAwardsList(args)
-- for i, v in ipairs(list) do-- currentAward = list[i]-- args["label" .. i] = currentAward.name-- args["data" .. i .. "a"] = currentAward.numOfWins-- args["data" .. i .. "b"] = currentAward.numOfNominations-- end
return 0end
local function sumValues(args) local sum = 0
for i, v in ipairs(args) do if (args[i]) then sum = sum + args[i] end end return sumend
local function getValues(args, pattern) local list = for name, value in pairs(args) do if (isValidParameter(name, pattern)) then table.insert(list, value) end end return listend
function p._nominations(args) local nominations = getValues(args, "N") return sumValues(nominations)end
function p._wins(args) local wins = getValues(args, "W") return sumValues(wins)end
local function makeInvokeFunc(funcName) return function (frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) return p[funcName](args) endend
p.orderAwards = makeInvokeFunc('_orderAwards')
p.nominations = makeInvokeFunc('_nominations')
p.wins = makeInvokeFunc('_wins')
return p
--