local mDisambiguation = require('Module:Disambiguation')local mRedirect = require('Module:Redirect')
local function getData(ranking) if ranking
local function formatName(nameIn) local name = nameIn local comma = mw.ustring.find(name, ", ") if comma
"x" then return name else return "" .. name .. "" end end
local title = mw.title.new(name) local defaultDisambig = mw.title.new(name .. ' (tennis)') if defaultDisambig.exists then return "" .. name .. "" end
if title.exists then local content = title:getContent if not mDisambiguation.isDisambiguation(content) and not mDisambiguation.isDisambiguation(mRedirect.luaMain(content)) then return "" .. name .. "" end return "" .. name .. "" .. "" end return nameend
local p =
function p.createNavbox(frame) local ranking = frame.args[1] local country = frame.args[2] local nationality = frame.args[3] local data = getData(ranking) local templateParams = local lang = mw.getContentLanguage local countryDataCur = assert(data["current"]["per-country"][country], "Invalid country code '" .. country .. "' specified for Module:ATP rankings") local countryDataPrev = data["previous"]["per-country"][country]
local flagicon = frame:expandTemplate templateParams["name"] = "Top male singles tennis players by country" templateParams["title"] = "Association of Tennis Professionals " .. flagicon .. " Top " .. nationality .. " male " .. ranking .. " tennis players" templateParams["above"] = "As of " .. data["current"]["as-of"] .. "" templateParams["state"] = frame:getParent.args["state"] or "autocollapse" templateParams["listclass"] = "hlist" templateParams["list1"] = "" local lastRankings = for i, entry in ipairs(countryDataPrev) do lastRankings[entry["name"]] = entry["rank"] end
local listKey = "list1" for i, entry in ipairs(countryDataCur) do if i
11 then break end local changeDirection = "increase" local changeAmount = "" if lastRankings[entry["name"]]
entry["rank"] then changeDirection = "steady" elseif lastRankings[entry["name"]] >= entry["rank"] then -- decrease in value means in increase in ranking changeDirection = "increase" changeAmount = lastRankings[entry["name"]] - entry["rank"] else changeDirection = "decrease" changeAmount = entry["rank"] - lastRankings[entry["name"]] end
changeDirection = frame:expandTemplate local tied = "" if entry["tied"] then tied = "T" end
templateParams[listKey] = templateParams[listKey] .. "* " .. i .. ". " .. formatName(entry["name"]) .. " (" .. tied .. lang:formatNum(entry["rank"]) .. " " .. changeDirection .. changeAmount .. ")\n" end
return frame:expandTemplateend
return p