Module:SportsRankings
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Module to display sports rankings of countries in various sports. The data on the rankings is held in module subpages so the lists can be updated in one location.
Data subpages
- SportsRankings/data/BSWW World Ranking
- SportsRankings/data/BSWW World Ranking/doc
- SportsRankings/data/FIBA Women's World Rankings
- SportsRankings/data/FIBA Women's World Rankings/doc
- SportsRankings/data/FIBA World Rankings
- SportsRankings/data/FIBA World Rankings/doc
- SportsRankings/data/FIFA Futsal Women's World Rankings
- SportsRankings/data/FIFA Futsal Women's World Rankings/doc
- SportsRankings/data/FIFA Futsal World Rankings
- SportsRankings/data/FIFA Futsal World Rankings/doc
- SportsRankings/data/FIFA Women's World Rankings
- SportsRankings/data/FIFA World Rankings
- SportsRankings/data/FIH Women's World Rankings
- SportsRankings/data/FIH Women's World Rankings/doc
- SportsRankings/data/FIH World Rankings
- SportsRankings/data/FIH World Rankings/doc
- SportsRankings/data/FIVB Women's World Rankings
- SportsRankings/data/FIVB Women's World Rankings/doc
- SportsRankings/data/FIVB World Rankings
- SportsRankings/data/FIVB World Rankings/doc
- SportsRankings/data/IIHF World Ranking
- SportsRankings/data/IIHF World Ranking/doc
- SportsRankings/data/IRL Wheelchair World Rankings
- SportsRankings/data/IRL Wheelchair World Rankings/doc
- SportsRankings/data/UEFA Coefficient Rankings
- SportsRankings/data/UEFA Coefficient Rankings/doc
- SportsRankings/data/WBSC Baseball5 World Rankings
- SportsRankings/data/WBSC Men's Softball World Rankings
- SportsRankings/data/WBSC Men's Softball World Rankings/sandbox
- SportsRankings/data/WBSC Women's Baseball World Rankings
- SportsRankings/data/WBSC Women's World Rankings
- SportsRankings/data/WBSC Women's World Rankings/doc
- SportsRankings/data/WBSC World Rankings
- SportsRankings/data/WBSC World Rankings/doc
- SportsRankings/data/WCFmen
- SportsRankings/data/WCFmixed
- SportsRankings/data/WCFmixed-doubles
- SportsRankings/data/WCFwheelchair
- SportsRankings/data/WCFwomen
- SportsRankings/data/Women's World Rugby Rankings
- SportsRankings/data/Women's World Rugby Rankings/doc
- SportsRankings/data/World Football Elo Ratings
- SportsRankings/data/World Rugby Rankings
- SportsRankings/data/World Rugby Rankings/doc
- SportsRankings/data/doc
Templates for single country rank (with flag and change):
- BSWW World Rankings: {{BSWW World Ranking}}
- FIBA World Rankings: {{FIBA World Rankings}}
- FIBA Women's World Rankings: {{FIBA Women's World Rankings}}
- FIFA World Rankings: {{FIFA World Rankings}}
- FIFA Women's World Rankings: {{FIFA Women's World Rankings}}
- FIH World Rankings: {{FIH World Rankings}}
- FIH Women's World Rankings: {{FIH Women's World Rankings}}
- IIHF World Rankings: {{IIHF World Ranking}}
- IIHF Women's World Rankings: {{IIHF Women's World Ranking}}
- IRL Wheelchair World Rankings: {{IRL Wheelchair World Rankings Team}}
- World Football Elo Ratings: {{World Football Elo Ratings}}
Template to generate rankings table:
Usage
- Show ranking of named country with change:
{{#invoke:SportsRankings|main|country|mdy}}
- List ranking from start ranking to end ranking (default: 1-10):
{{#invoke:SportsRankings|list|FIFA World Rankings|first|last}}
- List ranking from for names country with number of countries above and below:
{{#invoke:SportsRankings|list2|FIFA World Rankings|country name|number to display above and below named country}}
- Show ranking of a confederation:
{{#invoke:SportsRankings|list|FIH World Rankings|first|last|select=confederation|rank_header=FIH}}
Country examples:
Country examples | Code | Output | ||
---|---|---|---|---|
FIFA World Rankings for France | {{#invoke:SportsRankings|main |FIFA World Rankings|FRA}}
|
| ||
World Football Elo Ratings for France | {{#invoke:SportsRankings|main |World Football Elo Ratings|France}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
FIBA World Rankings for USA | {{#invoke:SportsRankings|main |FIBA World Rankings|USA}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
List example | Output | |||
FIFA World Rankings table (1-5) | {{#invoke:SportsRankings|list
|FIFA World Rankings
|1
|5
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
FIBA World Rankings table (1-5) | {{#invoke:SportsRankings|list
|FIBA World Rankings
|1
|5
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
FIBA Women's World Rankings table (1-5) | {{#invoke:SportsRankings|list
|FIBA Women's World Rankings
|1
|5
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
FIFA Women's World Rankings (1-5): | {{#invoke:SportsRankings|list
|FIFA Women's World Rankings
|1
|5
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
FIH World Rankings by confederation | {{#invoke:SportsRankings|list
|FIH World Rankings
|1
|65
|select=AfHF
|rankheader=FIH
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
World Football Elo Ratings(1-5): | {{#invoke:SportsRankings|list
|World Football Elo Ratings
|1
|5
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
UEFA Coefficient Rankings (+/-2): | {{#invoke:SportsRankings|list2
|UEFA Coefficient Rankings
|Luxembourg
|2
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
IIHF World Rankings (1-5) (with optional caption parameter): |
{{#invoke:SportsRankings|list
|IIHF World Rankings
|1
|5
caption=Men's IIHF World Rankings (INSERT_UPDATE_DATE)
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. | ||
IIHF Women's World Rankings (1-5) (with optional caption parameter): |
{{#invoke:SportsRankings|list
|IIHF Women's World Rankings
|1
|5
caption=Women's IIHF World Rankings (INSERT_UPDATE_DATE)
}}
|
Lua error in package.lua at line 80: module 'Module:No globals' not found. |
Usage
require('Module:No globals');
local p = {}
local error_msg = '<span style=\"font-size:100%\" class=\"error\"><code style=\"color:inherit; border:inherit; padding:inherit;\">|_template=</code> missing or empty</span>';
-- data for various rankings held in module subpages, e.g. "Module:SportsRankings/data/FIFA World Rankings"
local data = {} --[[ parameters containing data help in three tables
data.source = {} -- parameters for using in cite web (title, url, website)
data.updated = {} -- date of latest update (month, day, year)
data.rankings = {} -- the rankings list (country code, ranking, movement)
data.alias = {} -- alias list (country code, country name [=key])
--]]
local templateArgs = {} -- contains arguments from template involking module
local function getArgs(frame)
local parents = mw.getCurrentFrame():getParent()
for k,v in pairs(parents.args) do
--check content
if v and v ~= "" then
templateArgs[k]=v --parents.args[k]
end
end
end
local function loadData(frame)
local source = frame.args[1] -- source of rankings e.g. FIFA World Rankings
data = require('Module:SportsRankings/data/'.. source);
end
local function getDate()
if templateArgs['mdy'] and templateArgs['mdy'] ~= "" then
return data.updated['month'] .. " " .. data.updated['day'] .. ", " .. data.updated['year']
else
return data.updated['day'] .. " " .. data.updated['month'] .. " " .. data.updated['year']
end
end
local function addCiteWeb(frame) -- use cite web template
return frame:expandTemplate{ title = 'cite web' , args = {
url = data.source['url'], --"https://www.fifa.com/fifa-world-ranking/ranking-table/men/index.html",
title = data.source['title'], -- "The FIFA/Coca-Cola World Ranking",
website = data.source['website'], --"FIFA",
['date'] = getDate(),
['access-date'] = getDate()
}}
end
local function addReference(frame)
local text = ""
if data.source['text'] then text = data.source['text'] end
return frame:expandTemplate{ title = 'refn' , args = {
name=frame.args[1], --ranking used, e.g. "FIFA World Rankings",
text .. addCiteWeb(frame)
}}
end
--[[ the main function returning rankings
]]
function p.main(frame)
getArgs(frame) -- returns args table having checked for content
loadData(frame)
local outputString = ""
local country = templateArgs[1] -- country name or county code passed as parameter
local rank, move
for _,u in pairs(data.alias) do
if u[1]==country then
country = u[2] -- if alias (country code) then use country name as key
break
end
end
for _,v in pairs(data.rankings) do
if v[1]==country then
rank = v[2] -- get rank
move = v[3] -- get move from last ranking
break
end
end
if not rank then rank = 'NR' end
if rank ~= 'NR' then
outputString = outputString .. ' ' .. rank .. ' '
if move == 0 then -- if no change in ranking
outputString = outputString .. frame:expandTemplate{ title = 'steady' }
elseif move < 0 then -- if ranking down
outputString = outputString .. frame:expandTemplate{ title = 'decrease' } .. ' ' .. math.abs(move)
elseif move > 0 then -- if ranking up
outputString = outputString .. frame:expandTemplate{ title = 'increase' } .. ' ' .. move
end
else
outputString = outputString .. frame:expandTemplate{ title = 'Abbr', args = { "NR", "Not ranked"} }
-- {{Abbr|NR|Not ranked}}
end
outputString = outputString .. ' <small>(' .. getDate() .. ')</small>'
outputString = outputString .. addReference(frame)
return outputString
end
function p.list(frame)
getArgs(frame) -- returns args table having checked for content
loadData(frame)
local first, last = 1,10
first = tonumber(frame.args['2'])
last = tonumber(frame.args['3'])
local outputString = '{| class="wikitable" style="text-align:center;"'
outputString = outputString .. '\n|+FIFA Rankings as of ' .. getDate() .. '.' .. addReference(frame)
outputString = outputString .. '\n|-\n!Rank\n!Change\n!Team\n!Points '
local change,code = '', ''
--while i<last do
for k,v in pairs(data.rankings) do
if k >= first and k <= last then
outputString = outputString .. '\n|-\n|' .. v[2] -- rank
local move = v[3]
if move == 0 then -- if no change in ranking
change = frame:expandTemplate{ title = 'steady' }
elseif move < 0 then -- if ranking down
change = frame:expandTemplate{ title = 'decrease' } .. ' ' .. math.abs(move)
elseif move > 0 then -- if ranking up
change = frame:expandTemplate{ title = 'increase' } .. ' ' .. move
end
outputString = outputString .. '||' .. change
for _,u in pairs(data.alias) do
if u[2]==v[1] then
code = u[1] -- if alias (country code) then use country name as key
break
end
end
outputString = outputString .. '\n|style="text-align:left"|' .. frame:expandTemplate{ title = 'fb', args = {code} } -- country
outputString = outputString .. '||' .. v[1] -- country for now, later points
end
end
outputString = outputString .. "\n|}"
if 1==1 then return outputString end
for _,u in pairs(data.alias) do
if u[1]==country then
country = u[2] -- if alias (country code) then use country name as key
break
end
end
outputString = outputString .. ' <small>(' .. getDate() .. ')</small>'
outputString = outputString .. addReference(frame)
return outputString
end
return p