Module:Medal tally
local p = {}
function p.render(frame)
local args = frame:getParent().args
local header = args.header or "Medal Tally"
local class = args.class or ""
local result = {}
table.insert(result, string.format('<table class="wikitable %s" style="text-align:center;">', class))
table.insert(result, string.format('<caption>%s</caption>', header))
table.insert(result, '<tr><th>Rank</th><th>Team</th><th style="background-color: #FFD700;">Gold</th><th style="background-color: C0C0C0;">Silver</th><th style="background-color: #CD7F32;">Bronze</th><th>Total</th></tr>')
local medals = {}
local totalGold, totalSilver, totalBronze = 0, 0, 0
for i = 1, 8 do
local team = args['team' .. i]
local gold = tonumber(args['gold' .. i]) or 0
local silver = tonumber(args['silver' .. i]) or 0
local bronze = tonumber(args['bronze' .. i]) or 0
local total = gold + silver + bronze
if team then
table.insert(medals, {rank = i, team = team, gold = gold, silver = silver, bronze = bronze, total = total})
totalGold = totalGold + gold
totalSilver = totalSilver + silver
totalBronze = totalBronze + bronze
end
end
table.sort(medals, function(a, b)
if a.gold ~= b.gold then return a.gold > b.gold end
if a.silver ~= b.silver then return a.silver > b.silver end
return a.bronze > b.bronze
end)
for index, entry in ipairs(medals) do
table.insert(result, string.format('<tr><td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td></tr>',
index, entry.team, entry.gold, entry.silver, entry.bronze, entry.total))
end
local totalMedals = totalGold + totalSilver + totalBronze
table.insert(result, string.format('<tr><th colspan="2">Total</th><td>%d</td><td>%d</td><td>%d</td><td>%d</td></tr>',
totalGold, totalSilver, totalBronze, totalMedals))
table.insert(result, '</table>')
return table.concat(result, "\n")
end
return p
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.