Module:ICCProgression
local _module = {}
_module.create = function(frame)
------------- Functions -------------
local strFind = string.find
local strMatch = string.match
local strSplit = mw.text.split
local strFormat = string.format
local strTrim = mw.text.trim
local strSub = string.sub
local strUpper = string.upper
------------- Arguments -------------
local args = frame.args
local matchesPerTeam = tonumber(args.matchesPerTeam) or error("Invalid or missing parameter 'matchesPerTeam'")
local teams = strSplit(args.teams or error("Invalid or missing parameter 'teams'"), ',', true)
local playoffLabels = {}
if args.playoffLabels and args.playoffLabels ~= "" then
playoffLabels = strSplit(args.playoffLabels, ',', true)
end
local numPlayoffs = #playoffLabels
local matchReportArticle = args.matchReportArticle or ''
local caption = args.caption
local colours_win = "#99FF99"
local colours_loss = "#FFDDDD"
local colours_tie = "#FFFFCC"
local colours_noResult = "#DFDFFF"
local colours_eliminated = "#DCDCDC"
local classes_win = "yes table-yes2"
local classes_loss = "no table-no2"
local classes_tie = "table-partial"
local classes_noResult = "noresult"
local output = {}
local function print(s)
table.insert(output, s)
end
-- Header
print(strFormat([[
{| class="wikitable" style="text-align: center; font-size: 100%%"
%s
! scope="col" rowspan="2" | Team
! colspan="%d" style="border-left: 4px solid #454545" | Group matches
]], caption and '|+ ' .. caption or '', matchesPerTeam))
if numPlayoffs > 0 then
print(strFormat('! colspan="%d" style="border-left: 4px solid #454545" | Play-offs\n', numPlayoffs))
end
print('|-\n')
for i = 1, matchesPerTeam do
print(strFormat('! scope="col" style="width: 45px;%s" | %d\n', i == 1 and " border-left: 4px solid #454545" or "", i))
end
for i = 1, numPlayoffs do
print(strFormat('! scope="col" style="width: 40px;%s" | %s\n', i == 1 and " border-left: 4px solid #454545" or "", strTrim(playoffLabels[i])))
end
local argCounter = 1
-- Rows
for i = 1, #teams do
local team = strTrim(teams[i])
print('\n|-\n! scope="row" style="text-align: left; padding-right: 10px" | ' .. team .. '\n')
local groupResultsRaw = args[argCounter] or ''
local playoffResultsRaw = args[argCounter + 1] or ''
argCounter = argCounter + 2
local g_results = strSplit(groupResultsRaw, ',', true)
local p_results = strSplit(playoffResultsRaw, ',', true)
local runningScore = 0
-- 1. Group Stage
for j = 1, matchesPerTeam do
local resultData = strTrim(g_results[j] or "")
local cellStart = (j == 1) and '| style="border-left: 4px solid #454545; ' or '|| style="'
if resultData ~= "" then
local res = strUpper(strSub(resultData, 1, 1))
if not strFind("WLTN", res) then
error(strFormat("Invalid Result '%s' for %s. Use W, L, T, or N.", res, team))
end
local match_id = strMatch(resultData, '%d+%a?')
local bonus = tonumber(strMatch(resultData, '%+(%d+)')) or 0
if res == 'W' then runningScore = runningScore + 2
elseif res == 'T' or res == 'N' then runningScore = runningScore + 1 end
runningScore = runningScore + bonus
local color = (res == 'W' and colours_win) or (res == 'L' and colours_loss) or (res == 'T' and colours_tie) or colours_noResult
local class = (res == 'W' and classes_win) or (res == 'L' and classes_loss) or (res == 'T' and classes_tie) or classes_noResult
print(strFormat('%sbackground-color: %s" class="%s" | [[%s#match%s|%d]] ', cellStart, color, class, matchReportArticle, match_id or '', runningScore))
else
print(cellStart .. '" | ')
end
end
-- 2. Play-offs
if numPlayoffs > 0 then
for k = 1, numPlayoffs do
local pData = strTrim(p_results[k] or "")
local cellStart = (k == 1) and '|| style="border-left: 4px solid #454545; ' or '|| style="'
if pData ~= "" then
local res = strUpper(strSub(pData, 1, 1))
if not strFind("WLTNE", res) then
error(strFormat("Invalid Play-off Result '%s' for %s. Use W, L, T, N, or E.", res, team))
end
local match_id = strMatch(pData, '%d+%a?')
local color = (res == 'W' and colours_win) or (res == 'L' and colours_loss) or (res == 'T' and colours_tie) or (res == 'E' and colours_eliminated) or colours_noResult
if res == 'E' then
print(strFormat('%sbackground-color: %s" | — ', cellStart, color))
else
print(strFormat('%sbackground-color: %s" | [[%s#match%s|%s]] ', cellStart, color, matchReportArticle, match_id or '', res))
end
else
-- Check if there is a result in ANY future column for this team
local hasFutureResult = false
for future = k + 1, #p_results do
if strTrim(p_results[future] or "") ~= "" then
hasFutureResult = true
break
end
end
if hasFutureResult then
print(cellStart .. '" | → ')
else
print(cellStart .. '" | ')
end
end
end
end
end
-- Footer Legend
print(strFormat([[
|}
{| class="wikitable" style="text-align: center; font-size: 90%%"
| class="%s" style="background-color: %s" | Win
| class="%s" style="background-color: %s" | Loss
| class="%s" style="background-color: %s" | Tie
| class="%s" style="background-color: %s" | No result
| style="background-color: %s" | Eliminated
|}
<ul style="font-size: 85%%">
<li>'''Note''': The total points at the end of each group match are listed.</li>
<li>'''Note''': Click on the points or results to see the match summary.</li>
</ul>
]], classes_win, colours_win, classes_loss, colours_loss, classes_tie, colours_tie, classes_noResult, colours_noResult, colours_eliminated))
return table.concat(output)
end
return _module
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.