Module:IndianPremierLeagueProgression
Appearance
Usage
{{#invoke:IndianPremierLeagueProgression|create|parameters}}
This module has only one function: create.
Named parameters
- caption
- Optional. Specifies a caption for the top of the table.
- teams
- A comma-separated list of the participating teams. These will automatically be wikilinked in the table.
- matchesPerTeam
- The number of group stage matches per team.
- matchReportArticle
- Optional. The name of the article on which the match scorecards exist. The scorecard for each match must be on the specified article and must be accessible via an element with the
id
attribute set tomatchN
, where N is the match number (the{{anchor}}
template may be used for this purpose). If not specified, it will be the article from which the module is invoked. - knockoutType
- Specifies the model of the playoff stage. This can be one of two values: 1, to use the 2008-2010 model (2 semifinals/final), or 2, to use the current model (2 qualifiers/eliminator/final).
Data
- All unnamed parameters are used to represent data.
- Each of the teams mentioned in the teams parameter take two data parameters, in the order in which they are mentioned. The first team in the teams parameter uses the 1st and 2nd parameters, the second team uses the 3rd and 4th parameters, the third team uses the 5th and 6th parameters ans so on.
- Odd-numbered parameters represent group stage data, even-numbered parameters represent playoff data.
- The value of each data parameter consists of one or more result fields, separated by commas. The order of the result fields must be the same order in which the matches were played.
- Each result field starts with one of the letters W (win), L (loss), N (no result), E or U, followed by the match number. (E and U are used only in the playoff stage data and must not be followed by a match number)
- Points in the group stage will be inferred from the result fields.
- For playoff stage only
- If the
knockoutType
parameter is set to 1, the playoff stage data for each team can have a maximum of two result fields: the first for either of the semifinals, and the second for the final. - If the
knockoutType
parameter is set to 2, the playoff stage data for each team can have a maximum of three result fields: the first for the first qualifier or the eliminator, the second for the second qualifier and the third for the final. - The result field E indicates that the team has been eliminated. It must be the last result in the playoff data, after the result of the match that caused the elimination. For teams eliminated in the group stage, the playoff stage data for the team must only consist of an E.
- The result field U indicates that the team does not have to play the match, but is not eliminated. This should only be used only used when the
knockoutType
parameter is set to 2, and is used as the second result for the team that has won the first qualifier and progressed directly into the final.
--[[
Module for generating league progresion tables intended for use in Indian Premier League season articles.
]]
local _module = {}
_module.create = function(frame)
local strSplit = mw.text.split
local strFormat = string.format
local args = frame.args
local matchesPerTeam = tonumber(args.matchesPerTeam)
local ktype = tonumber(args.knockoutType)
local teams = strSplit(args.teams, '%s*,%s*')
local colours = { W = "#99FF99", L = "#FFDDDD", N = "#DFDFFF", E = "#DCDCDC" }
local classes = { W = "yes table-yes2", L = "no table-no2", N = "noresult", E = "" }
local points = { W = 2, L = 0, N = 1, U = 0 }
local groupStageHeaders = {}
for i = 1, matchesPerTeam do
-- Generate the headers for each group match
groupStageHeaders[i] = ((i == 1) and '! style="width: 30px; border-left: 4px solid #454545"' or '!! style="width: 30px"') .. ' scope="col" | ' .. i .. ' '
end
local knockoutTypeMatches = { 2, 3 }
local kMatches = knockoutTypeMatches[ktype]
if not kMatches then
error("Invalid knockout type: " .. ktype)
end
--[[
Headers specific to each knockout type
]]
local knockoutHeaders = {
-- Knockout type 1 (used from 2008 to 2010)
[[
! scope="col" style="width: 32px; border-left: 4px solid #454545" | <abbr title="Semi-final">SF</abbr>
! scope="col" style="width: 32px" | <abbr title="Final">F</abbr>]],
-- Knockout type 2 (used from 2011 onwards)
[[
! scope="col" style="width: 32px; border-left: 4px solid #454545" | <abbr title="Qualifier 1 or Eliminator">Q1/E</abbr>
! scope="col" style="width: 32px" | <abbr title="Qualifier 2">Q2</abbr>
! scope="col" style="width: 32px" | <abbr title="Final">F</abbr>]]
}
--[[
Common header
]]
local header = strFormat(
[[
{| class="wikitable" style="text-align: center"
! scope="col" rowspan="2" | Team
! colspan="%d" style="border-left: 4px solid #454545" | Group matches
! colspan="%d" style="border-left: 4px solid #454545" | Playoffs
|-
%s
%s
]],
matchesPerTeam, kMatches, table.concat(groupStageHeaders), knockoutHeaders[ktype])
--[[
Common footer
]]
local footer = strFormat(
[[
|}
{| class="wikitable" style="float: right; width: 20%%; text-align: center; margin-right: 5%%"
| class="yes table-yes2" style="background-color: %s" | Win
| class="no table-no2" style="background-color: %s" | Loss
| class="noresult" style="background-color: %s" | No result
|}
* '''Note''': The total points at the end of each group match are listed.
* '''Note''': Click on the points (group matches) or W/L (playoffs) to see the match summary.
]],
colours.W, colours.L, colours.N)
local body = {}
local argCounter = 1
--[[
Formats a result
label: The label to display in the table
result: The result of the match (W = win, L = loss, N = no result, U = unplayed)
match: The match number to link to
]]
local formatResult = function(label, result, match)
if result == 'U' then
return '" | '
end
local style = 'background-color: ' .. colours[result] .. (first and '; border-left: 4px solid #454545' or '')
return style .. '" class="' .. classes[result] .. '" | [[#match' .. match .. '|' .. label .. ']] '
end
-- Generate the table
for i = 1, #teams do
local team = teams[i]
local listing = '|-\n! scope="row" style="text-align: left; padding-right: 10px" | [[' .. team .. ']]\n' -- Add the team name
local group, knockout = strSplit(args[argCounter], '%s*,%s*'), strSplit(args[argCounter + 1], '%s*,%s*') -- Split the results at commas
local runningScore = 0
argCounter = argCounter + 2
-- Check that the number of results is less than or equal to the maximum number of matches
if #group > matchesPerTeam then
error("Too many results for group stage (expecting no more than " .. matchesPerTeam .. ", got " .. #group .. ") (team: " .. team ..")")
end
if #knockout > kMatches then
error("Too many results for knockout stage (expecting no more than " .. kMatches .. ", got " .. #knockout .. ") (team: " .. team ..")")
end
for j = 1, matchesPerTeam do
local r = group[j]
listing = listing .. ((j == 1) and '| style="border-left: 4px solid #444444;' or '|| style="')
if r then
-- If there is a result, get its identifier (first character) and match number (remaining characters)
local result, match = r:sub(1, 1):upper(), r:sub(2)
local p = points[result]
if p then
runningScore = runningScore + p -- Add the points to the running score
else
-- If the result identifier is not in the points dictionary, it is invalid
error("Unsupported result: " .. r .. ", expecting 'W', 'L', 'N' or 'U' as first character (team: " .. team .. ")")
end
listing = listing .. formatResult(runningScore, result, match)
else
-- Result not given
listing = listing .. '" | '
end
end
listing = listing .. '\n'
for j = 1, kMatches do
local r = knockout[j]
listing = listing .. ((j == 1) and '| style="border-left: 4px solid #444444;' or '|| style="')
if r then
local result, match = r:sub(1, 1):upper(), r:sub(2)
if result == 'E' then -- Eliminated
listing = listing .. 'background-color: ' .. colours.E .. '" colspan="' .. kMatches - j + 1 .. '" | '
if knockout[j + 1] then
-- Check that there are no more results after an E
error("'E' should be the last result in the playoff result list (team: " .. team .. ")")
end
break
elseif not points[result] then -- Check the points dictionary to see if the result identifier is valid
error("Unsupported result: " .. r .. ", expecting 'W', 'L', 'N' or 'U' as first character (team: " .. team .. ")")
end
listing = listing .. formatResult(result, result, match)
else
-- Result not given
listing = listing .. '" | '
end
end
body[i] = listing
end
return header .. table.concat(body, '\n') .. footer
end
return _module