ಮಾಡ್ಯೂಲ್:Medals table
This module depends on the following other modules: |
A template for generating a medals table for a sporting event where the totals and ranks are automatically calculated.
Template basics
[ಬದಲಾಯಿಸಿ]{{Medals table | caption = | host = <!-- Text to display after host color box --> | show_limit = <!-- Will limit to displaying only the first N rows if this param is provided --> | remaining_text = <!-- Text to display for the remaining N rows (default is 'Remaining') --> | flag_template = <!-- Optional, will default to use Template:Flagteam --> | event = <!-- required IF flag_template requires a secondary param --> | team = <!-- Optional, will default to Nation --> | source = <!-- External link or reference --> ... <!-- For a list of valid IOC values, see [[List of IOC country codes]] --> | gold_IOC = | silver_IOC = | bronze_IOC = | host_IOC = <!-- leave blank UNLESS this is the host nation --> | name_IOC = <!-- Optional override of default which is {{flag_template|IOC}} | note_IOC = <!-- Option note that is added after the nation name --> }}
require('Module:No globals') local getArgs = require('Module:Arguments').getArgs
local p = {}
local function deflag(s) s = mw.ustring.gsub(s or , '%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%]', ) s = mw.ustring.gsub(s, '%[%[[Ii][Mm][Aa][Gg][Ee]:[^%[%]]*%]%]', ) s = mw.ustring.gsub(s, '<[^<>]*>', ) s = mw.ustring.gsub(s, '%s*%([A-Z][A-Z][A-Z]%)%s*$', ) while s:match('^%s*&[Nn][Bb][Ss][Pp];%s*') do s = mw.ustring.gsub(s, '^%s*&[Nn][Bb][Ss][Pp];%s*', ) end s = mw.ustring.gsub(s, '%s*&[Nn][Bb][Ss][Pp];%s*$', ) s = mw.ustring.gsub(s, '%s%s+', ' ') s = mw.ustring.gsub(s, '^%s*(.-?)%s*$', '%1') return s end
function p.createTable(frame, args) if not args then args = getArgs(frame) end
local team = args['team'] or 'Nation'
local root = mw.html.create() local host = args['host'] or local hostColor = '#ccccff' local defaultRowColor = '#f8f9fa' local flagTemplate = args['flag_template'] or 'flagteam' local event = args['event'] local legendpos = (args['legend_position'] or 't'):lower() local header, footer = , local totalGold = 0 local totalSilver = 0 local totalBronze = 0
local remainingGold = 0 local remainingSilver = 0 local remainingBronze = 0 local remainingStart = 0 local remainingEnd = 0 local limitReached = false local showLimit = tonumber(args['show_limit'])
-- build the legend if host ~= then if args['name_' .. host] then host = args['name_' .. host] host = 'Host nation (' .. deflag(host) .. ')' elseif host:match('^([A-Z][A-Z][A-Z])') then host = frame:expandTemplate{title = flagTemplate, args = {host, event} } host = 'Host nation (' .. deflag(host) .. ')' end host = host .. (args['host_note'] or ) host = frame:expandTemplate{title = 'color box', args = {hostColor, ' * ', 'border=darkgray'}} ..' '.. host end
local leading = if args['leading'] then leading = frame:expandTemplate{title = 'legend', args = {'#E9D66B', "Leading in that sport"}} end
if legendpos == 't' then header = header .. host .. leading else footer = footer .. host .. leading end
root = root :tag('table') :addClass('wikitable') :addClass('sortable') :addClass('plainrowheaders') :addClass('jquery-tablesorter') :css('text-align', 'center')
root:tag('caption') :wikitext(args['caption']) -- add the header row local row = root:tag('tr')
if args['hide_rank'] then else row:tag('th') :attr('scope', 'col') :wikitext('Rank') end row :tag('th') :attr('scope', 'col') :wikitext(team) :tag('th') :attr('scope', 'col') :addClass('headerSort') :css('width', '4em') :css('background-color', 'gold') :wikitext('Gold') :tag('th') :attr('scope', 'col') :addClass('headerSort') :css('width', '4em') :css('background-color', 'silver') :wikitext('Silver') :tag('th') :attr('scope', 'col') :addClass('headerSort') :css('width', '4em') :css('background-color', '#c96') :wikitext('Bronze') :tag('th') :attr('scope', 'col') :css('width', '4em') :wikitext('Total')
-- enumerate the rows local rowNums = {} local IOCs = {} for k,v in pairs(args) do k = ..k local IOC = k:match('^gold_([A-Z][A-Z][A-Z])$') or k:match('^gold_(%d+)$') or k:match('^silver_([A-Z][A-Z][A-Z])$') or k:match('^silver_(%d+)$') or k:match('^bronze_([A-Z][A-Z][A-Z])$') or k:match('^bronze_(%d+)$') if IOC and IOCs[IOC] == nil then IOCs[IOC] = 1 local gold = (tonumber(args['gold_' .. IOC]) or 0) local silver = (tonumber(args['silver_' .. IOC]) or 0) local bronze = (tonumber(args['bronze_' .. IOC]) or 0) local noskip = args['skip_' .. IOC] and 0 or 1 local nation = args['name_' .. IOC] or frame:expandTemplate{title = flagTemplate, args = {IOC, event} } nation = deflag(nation) if nation:match('%[%[[^%[%]%|]*%|([^%[%]]*)%]%]') then nation = nation:match('%[%[[^%[%]%|]*%|([^%[%]]*)%]%]') end if nation:match('%[%[([^%[%]%|]*)%]%]') then nation = nation:match('%[%[([^%[%]%|]*)%]%]') end table.insert(rowNums, {gold, silver, bronze, noskip, nation, IOC}) end end if args['team'] == 'Games' then table.sort(rowNums, function (a,b) return a[5] < b[5] end ) else table.sort(rowNums, function (a, b) return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2]) or (a[1] == b[1] and a[2] == b[2] and a[3] > b[3]) or (a[1] == b[1] and a[2] == b[2] and a[3] == b[3] and a[4] > b[4]) or (a[1] == b[1] and a[2] == b[2] and a[3] == b[3] and a[4] == b[4] and a[5] < b[5]) end ) end
local lastGold, lastSilver, lastBronze = -1 local rank = 0 local lastspan, lastrankcell = 1, nil for i, anum in ipairs(rowNums) do local IOC = anum[6] if args['skip_' .. IOC] then lastGold, lastSilver, lastBronze, lastspan = -1, -1, -1, 1 else rank = rank + 1 end local nation = args['name_' .. IOC] or frame:expandTemplate{title = flagTemplate, args = {IOC, event} } local gold = tonumber(args['gold_' .. IOC]) or 0 local silver = tonumber(args['silver_' .. IOC]) or 0 local bronze = tonumber(args['bronze_' .. IOC]) or 0 local isHost = args['host_' .. IOC] -- this is mainly for the parameter names example so you can override it. local total = args['total_' .. IOC] or gold + silver + bronze local color = isHost and hostColor or defaultRowColor
if args['grand_total'] then else totalGold = totalGold + gold totalSilver = totalSilver + silver totalBronze = totalBronze + bronze end
if args['host_' .. IOC] then nation = nation .. '*' end
if args['note_' .. IOC] then nation = nation .. args['note_' .. IOC] end
if showLimit and (rank>showLimit) then if remainingStart == 0 then remainingStart = rank end limitReached = true remainingGold = remainingGold + gold remainingSilver = remainingSilver + silver remainingBronze = remainingBronze + bronze else local row if args['leading_' .. IOC] then row = root:tag('tr'):css('background-color', '#E9D66B') color = '#E9D66B' else row = root:tag('tr') end
--Don't put the color on the row because of ranks spanning multiple rows. --:css('background-color', color)
if args['hide_rank'] then else if (gold == lastGold) and (silver == lastSilver) and (bronze == lastBronze) then lastspan = lastspan + 1 lastrankcell:attr('rowspan',lastspan) else lastspan = 1 if args['skip_' .. IOC] then lastrankcell = row:tag('td'):wikitext(frame:expandTemplate{title = 'sort', args = {'999', '–'}}) else lastrankcell = row:tag('td'):wikitext(rank) lastGold = gold lastSilver = silver lastBronze = bronze end end end row:tag('th') :attr('scope', 'row') :css('background-color', color) :css('text-align','left') :wikitext(nation) :tag('td') :wikitext(gold) :tag('td') :wikitext(silver) :tag('td') :wikitext(bronze) :tag('td') :wikitext(total) end remainingEnd = rank end
if limitReached then root:tag('tr') :tag('td') :wikitext(remainingStart..'–'..remainingEnd) :tag('td') :css('font-style', 'italic') :css('text-align','left') :wikitext(args['remaining_link'] or args['remaining_text'] or 'Remaining') :tag('td') :wikitext(remainingGold) :tag('td') :wikitext(remainingSilver) :tag('td') :wikitext(remainingBronze) :tag('td') :wikitext(remainingGold+remainingSilver+remainingBronze) end
if team:match('^[A-Z][A-Z][A-Z]$') or team:match('>[A-Z][A-Z][A-Z]<') then else team = team:lower() end if team:match('^games$') then team = 'game' end
local colspan if args['hide_rank'] then colspan = 1 else colspan = 2 end if args['hide_totals'] then else root:tag('tr') :css('background-color', '#eaebef') :addClass('sortbottom') :tag('th') :wikitext('Totals ('..remainingEnd..' '..team..'s)') :attr('scope', 'row') :css('background-color', '#eaebef') :css('font-weight', 'bold') :attr('colspan', colspan) :tag('td') :wikitext(args['total_gold'] or totalGold) :css('font-weight', 'bold') :tag('td') :wikitext(args['total_silver'] or totalSilver) :css('font-weight', 'bold') :tag('td') :wikitext(args['total_bronze'] or totalBronze) :css('font-weight', 'bold') :tag('td') :wikitext(args['grand_total'] or totalGold+totalSilver+totalBronze) :css('font-weight', 'bold') end
-- Build the rest of the footer
if args['source'] or args['notes'] then
if footer ~= then
footer = footer .. '
'
end
footer = frame:expandTemplate{ title = 'refbegin' } .. footer
if args['source'] then
footer = footer .. 'Source: ' .. args['source']
end
if args['notes'] then
if args['source'] then
footer = footer .. '
'
end
footer = footer .. 'Notes: ' .. args['notes']
end
footer = footer .. frame:expandTemplate{ title = 'refend' }
end
return header .. tostring(root) .. footer end
return p
Parameters
[ಬದಲಾಯಿಸಿ]Some of the optional parameters
Parameter | Explanation |
---|---|
caption |
The caption or title given to the table |
host |
The host entity. If set to a 3 letter code matching one of the rows, the host name will be automatically formatted. Otherwise this param will override the host text. |
flag_template |
Which of the many flag templates to use. If left blank, {{Flagcountry}} will be used.
|
event |
For flag templates which require a 2nd parameter (such as {{FlagIOCteam|<country>|<event>}} ) this param will be that 2nd param.
|
team |
An optional override for the header to column 2. The default is "Nation". |
hide_rank |
When set the rank column will be hidden. |
hide_totals |
When set the totals row will be hidden. |
For a list of valid IOC values, see List of IOC country codes
Blank with all IOC codes
[ಬದಲಾಯಿಸಿ]The below template contains a condensed version of the template with ALL IOC country codes included. Obviously not all are needed. You are free to pick and choose those that you need for your implementation of the template.
Template
|
---|
{{Medals table | caption = | host = <!-- Text to display after host color box --> | show_limit = <!-- Will limit to displaying only the first N rows if this param is provided --> | remaining_text = <!-- Text to display for the remaining N rows (default is 'Remaining') --> | flag_template = <!-- Optional, will default to use Template:Flagteam --> | event = <!-- required IF flag_template requires a secondary param --> | team = <!-- Optional, will default to Nation --> | source = <!-- External link or reference --> | gold_AFG = | silver_AFG = | bronze_AFG = | gold_ALB = | silver_ALB = | bronze_ALB = | gold_ALG = | silver_ALG = | bronze_ALG = | gold_AND = | silver_AND = | bronze_AND = | gold_ANG = | silver_ANG = | bronze_ANG = | gold_ANT = | silver_ANT = | bronze_ANT = | gold_ARG = | silver_ARG = | bronze_ARG = | gold_ARM = | silver_ARM = | bronze_ARM = | gold_ARU = | silver_ARU = | bronze_ARU = | gold_ASA = | silver_ASA = | bronze_ASA = | gold_AUS = | silver_AUS = | bronze_AUS = | gold_AUT = | silver_AUT = | bronze_AUT = | gold_AZE = | silver_AZE = | bronze_AZE = | gold_BAH = | silver_BAH = | bronze_BAH = | gold_BAN = | silver_BAN = | bronze_BAN = | gold_BAR = | silver_BAR = | bronze_BAR = | gold_BDI = | silver_BDI = | bronze_BDI = | gold_BEL = | silver_BEL = | bronze_BEL = | gold_BEN = | silver_BEN = | bronze_BEN = | gold_BER = | silver_BER = | bronze_BER = | gold_BHU = | silver_BHU = | bronze_BHU = | gold_BIH = | silver_BIH = | bronze_BIH = | gold_BIZ = | silver_BIZ = | bronze_BIZ = | gold_BLR = | silver_BLR = | bronze_BLR = | gold_BOL = | silver_BOL = | bronze_BOL = | gold_BOT = | silver_BOT = | bronze_BOT = | gold_BRA = | silver_BRA = | bronze_BRA = | gold_BRN = | silver_BRN = | bronze_BRN = | gold_BRU = | silver_BRU = | bronze_BRU = | gold_BUL = | silver_BUL = | bronze_BUL = | gold_BUR = | silver_BUR = | bronze_BUR = | gold_CAF = | silver_CAF = | bronze_CAF = | gold_CAM = | silver_CAM = | bronze_CAM = | gold_CAN = | silver_CAN = | bronze_CAN = | gold_CAY = | silver_CAY = | bronze_CAY = | gold_CGO = | silver_CGO = | bronze_CGO = | gold_CHA = | silver_CHA = | bronze_CHA = | gold_CHI = | silver_CHI = | bronze_CHI = | gold_CHN = | silver_CHN = | bronze_CHN = | gold_CIV = | silver_CIV = | bronze_CIV = | gold_CMR = | silver_CMR = | bronze_CMR = | gold_COD = | silver_COD = | bronze_COD = | gold_COK = | silver_COK = | bronze_COK = | gold_COL = | silver_COL = | bronze_COL = | gold_COM = | silver_COM = | bronze_COM = | gold_CPV = | silver_CPV = | bronze_CPV = | gold_CRC = | silver_CRC = | bronze_CRC = | gold_CRO = | silver_CRO = | bronze_CRO = | gold_CUB = | silver_CUB = | bronze_CUB = | gold_CYP = | silver_CYP = | bronze_CYP = | gold_CZE = | silver_CZE = | bronze_CZE = | gold_DEN = | silver_DEN = | bronze_DEN = | gold_DJI = | silver_DJI = | bronze_DJI = | gold_DMA = | silver_DMA = | bronze_DMA = | gold_DOM = | silver_DOM = | bronze_DOM = | gold_ECU = | silver_ECU = | bronze_ECU = | gold_EGY = | silver_EGY = | bronze_EGY = | gold_ERI = | silver_ERI = | bronze_ERI = | gold_ESA = | silver_ESA = | bronze_ESA = | gold_ESP = | silver_ESP = | bronze_ESP = | gold_EST = | silver_EST = | bronze_EST = | gold_ETH = | silver_ETH = | bronze_ETH = | gold_FIJ = | silver_FIJ = | bronze_FIJ = | gold_FIN = | silver_FIN = | bronze_FIN = | gold_FRA = | silver_FRA = | bronze_FRA = | gold_FSM = | silver_FSM = | bronze_FSM = | gold_GAB = | silver_GAB = | bronze_GAB = | gold_GAM = | silver_GAM = | bronze_GAM = | gold_GBR = | silver_GBR = | bronze_GBR = | gold_GBS = | silver_GBS = | bronze_GBS = | gold_GEO = | silver_GEO = | bronze_GEO = | gold_GEQ = | silver_GEQ = | bronze_GEQ = | gold_GER = | silver_GER = | bronze_GER = | gold_GHA = | silver_GHA = | bronze_GHA = | gold_GRE = | silver_GRE = | bronze_GRE = | gold_GRN = | silver_GRN = | bronze_GRN = | gold_GUA = | silver_GUA = | bronze_GUA = | gold_GUI = | silver_GUI = | bronze_GUI = | gold_GUM = | silver_GUM = | bronze_GUM = | gold_GUY = | silver_GUY = | bronze_GUY = | gold_HAI = | silver_HAI = | bronze_HAI = | gold_HKG = | silver_HKG = | bronze_HKG = | gold_HON = | silver_HON = | bronze_HON = | gold_HUN = | silver_HUN = | bronze_HUN = | gold_INA = | silver_INA = | bronze_INA = | gold_IND = | silver_IND = | bronze_IND = | gold_IRI = | silver_IRI = | bronze_IRI = | gold_IRL = | silver_IRL = | bronze_IRL = | gold_IRQ = | silver_IRQ = | bronze_IRQ = | gold_ISL = | silver_ISL = | bronze_ISL = | gold_ISR = | silver_ISR = | bronze_ISR = | gold_ISV = | silver_ISV = | bronze_ISV = | gold_ITA = | silver_ITA = | bronze_ITA = | gold_IVB = | silver_IVB = | bronze_IVB = | gold_JAM = | silver_JAM = | bronze_JAM = | gold_JOR = | silver_JOR = | bronze_JOR = | gold_JPN = | silver_JPN = | bronze_JPN = | gold_KAZ = | silver_KAZ = | bronze_KAZ = | gold_KEN = | silver_KEN = | bronze_KEN = | gold_KGZ = | silver_KGZ = | bronze_KGZ = | gold_KIR = | silver_KIR = | bronze_KIR = | gold_KOR = | silver_KOR = | bronze_KOR = | gold_KOS = | silver_KOS = | bronze_KOS = | gold_KSA = | silver_KSA = | bronze_KSA = | gold_KUW = | silver_KUW = | bronze_KUW = | gold_LAO = | silver_LAO = | bronze_LAO = | gold_LAT = | silver_LAT = | bronze_LAT = | gold_LBA = | silver_LBA = | bronze_LBA = | gold_LBN = | silver_LBN = | bronze_LBN = | gold_LBR = | silver_LBR = | bronze_LBR = | gold_LCA = | silver_LCA = | bronze_LCA = | gold_LES = | silver_LES = | bronze_LES = | gold_LIE = | silver_LIE = | bronze_LIE = | gold_LTU = | silver_LTU = | bronze_LTU = | gold_LUX = | silver_LUX = | bronze_LUX = | gold_MAD = | silver_MAD = | bronze_MAD = | gold_MAR = | silver_MAR = | bronze_MAR = | gold_MAS = | silver_MAS = | bronze_MAS = | gold_MAW = | silver_MAW = | bronze_MAW = | gold_MDA = | silver_MDA = | bronze_MDA = | gold_MDV = | silver_MDV = | bronze_MDV = | gold_MEX = | silver_MEX = | bronze_MEX = | gold_MGL = | silver_MGL = | bronze_MGL = | gold_MHL = | silver_MHL = | bronze_MHL = | gold_MKD = | silver_MKD = | bronze_MKD = | gold_MLI = | silver_MLI = | bronze_MLI = | gold_MLT = | silver_MLT = | bronze_MLT = | gold_MNE = | silver_MNE = | bronze_MNE = | gold_MON = | silver_MON = | bronze_MON = | gold_MOZ = | silver_MOZ = | bronze_MOZ = | gold_MRI = | silver_MRI = | bronze_MRI = | gold_MTN = | silver_MTN = | bronze_MTN = | gold_MYA = | silver_MYA = | bronze_MYA = | gold_NAM = | silver_NAM = | bronze_NAM = | gold_NCA = | silver_NCA = | bronze_NCA = | gold_NED = | silver_NED = | bronze_NED = | gold_NEP = | silver_NEP = | bronze_NEP = | gold_NGR = | silver_NGR = | bronze_NGR = | gold_NIG = | silver_NIG = | bronze_NIG = | gold_NOR = | silver_NOR = | bronze_NOR = | gold_NRU = | silver_NRU = | bronze_NRU = | gold_NZL = | silver_NZL = | bronze_NZL = | gold_OMA = | silver_OMA = | bronze_OMA = | gold_PAK = | silver_PAK = | bronze_PAK = | gold_PAN = | silver_PAN = | bronze_PAN = | gold_PAR = | silver_PAR = | bronze_PAR = | gold_PER = | silver_PER = | bronze_PER = | gold_PHI = | silver_PHI = | bronze_PHI = | gold_PLE = | silver_PLE = | bronze_PLE = | gold_PLW = | silver_PLW = | bronze_PLW = | gold_PNG = | silver_PNG = | bronze_PNG = | gold_POL = | silver_POL = | bronze_POL = | gold_POR = | silver_POR = | bronze_POR = | gold_PRK = | silver_PRK = | bronze_PRK = | gold_PUR = | silver_PUR = | bronze_PUR = | gold_QAT = | silver_QAT = | bronze_QAT = | gold_ROU = | silver_ROU = | bronze_ROU = | gold_RSA = | silver_RSA = | bronze_RSA = | gold_RUS = | silver_RUS = | bronze_RUS = | gold_RWA = | silver_RWA = | bronze_RWA = | gold_SAM = | silver_SAM = | bronze_SAM = | gold_SEN = | silver_SEN = | bronze_SEN = | gold_SEY = | silver_SEY = | bronze_SEY = | gold_SGP = | silver_SGP = | bronze_SGP = | gold_SKN = | silver_SKN = | bronze_SKN = | gold_SLE = | silver_SLE = | bronze_SLE = | gold_SLO = | silver_SLO = | bronze_SLO = | gold_SMR = | silver_SMR = | bronze_SMR = | gold_SOL = | silver_SOL = | bronze_SOL = | gold_SOM = | silver_SOM = | bronze_SOM = | gold_SRB = | silver_SRB = | bronze_SRB = | gold_SRI = | silver_SRI = | bronze_SRI = | gold_SSD = | silver_SSD = | bronze_SSD = | gold_STP = | silver_STP = | bronze_STP = | gold_SUD = | silver_SUD = | bronze_SUD = | gold_SUI = | silver_SUI = | bronze_SUI = | gold_SUR = | silver_SUR = | bronze_SUR = | gold_SVK = | silver_SVK = | bronze_SVK = | gold_SWE = | silver_SWE = | bronze_SWE = | gold_SWZ = | silver_SWZ = | bronze_SWZ = | gold_SYR = | silver_SYR = | bronze_SYR = | gold_TAN = | silver_TAN = | bronze_TAN = | gold_TGA = | silver_TGA = | bronze_TGA = | gold_THA = | silver_THA = | bronze_THA = | gold_TJK = | silver_TJK = | bronze_TJK = | gold_TKM = | silver_TKM = | bronze_TKM = | gold_TLS = | silver_TLS = | bronze_TLS = | gold_TOG = | silver_TOG = | bronze_TOG = | gold_TPE = | silver_TPE = | bronze_TPE = | gold_TTO = | silver_TTO = | bronze_TTO = | gold_TUN = | silver_TUN = | bronze_TUN = | gold_TUR = | silver_TUR = | bronze_TUR = | gold_TUV = | silver_TUV = | bronze_TUV = | gold_UAE = | silver_UAE = | bronze_UAE = | gold_UGA = | silver_UGA = | bronze_UGA = | gold_UKR = | silver_UKR = | bronze_UKR = | gold_URU = | silver_URU = | bronze_URU = | gold_USA = | silver_USA = | bronze_USA = | gold_UZB = | silver_UZB = | bronze_UZB = | gold_VAN = | silver_VAN = | bronze_VAN = | gold_VEN = | silver_VEN = | bronze_VEN = | gold_VIE = | silver_VIE = | bronze_VIE = | gold_VIN = | silver_VIN = | bronze_VIN = | gold_YEM = | silver_YEM = | bronze_YEM = | gold_ZAM = | silver_ZAM = | bronze_ZAM = | gold_ZIM = | silver_ZIM = | bronze_ZIM = }} |
Event & Flag Template
[ಬದಲಾಯಿಸಿ]If {{{event}}}
and {{{flag_template}}}
are given values, then the nation value will be rendered as {{<flag_template>|<IOC>|<event>}}
.
So for example, with the following params:
{{Medals table | event = 2018 Winter | flag_template = FlagIOCteam | nation1 = USA | nation2 = CAN }}
The nations will be rendered as United States (USA) & Canada (CAN)
Example
[ಬದಲಾಯಿಸಿ]{{Medals table | caption = | host = | show_limit = | remaining_text = | flag_template = | event = | source = <ref>[http://wuni15.sportresult.com/HIDE/en/MedalTally?sport=00&medalKind=DefaultSports Medal Tally]</ref> | gold_FRA = 7 | silver_FRA = 4 | bronze_FRA = 4 | gold_GBR = 5 | silver_GBR = 5 | bronze_GBR = 5 | gold_USA = 5 | silver_USA = 3 | bronze_USA = 2 | gold_AUS = 3 | silver_AUS = 5 | bronze_AUS = 7 | gold_RSA = 3 | silver_RSA = 4 | bronze_RSA = 3 | gold_GER = 1 | silver_GER = 3 | bronze_GER = 3 }}
Rank | Nation | Gold | Silver | Bronze | Total |
---|---|---|---|---|---|
1 | France (FRA) | 7 | 4 | 4 | 15 |
2 | Great Britain (GBR) | 5 | 5 | 5 | 15 |
3 | ಅಮೇರಿಕ ಸಂಯುಕ್ತ ಸಂಸ್ಥಾನ (USA) | 5 | 3 | 2 | 10 |
4 | ಆಸ್ಟ್ರೇಲಿಯಾ (AUS) | 3 | 5 | 7 | 15 |
5 | ದಕ್ಷಿಣ ಆಫ್ರಿಕಾ (RSA) | 3 | 4 | 3 | 10 |
6 | Germany (GER) | 1 | 3 | 3 | 7 |
Totals (6 nations) | 24 | 24 | 24 | 72 |
Example2
[ಬದಲಾಯಿಸಿ]{{Medals table | caption = 2015 Winter Universiade medal table | host = SVK | source = <ref>[http://wuni15.sportresult.com/HIDE/en/MedalTally?sport=00&medalKind=DefaultSports Medal Tally]</ref> | flag_template = flagIOC2 | event = 2015 Winter Universiade | team = | gold_RUS = 9 | silver_RUS = 9 | bronze_RUS = 9 | gold_KOR = 5 | silver_KOR = 5 | bronze_KOR = 5 | gold_ITA = 4 | silver_ITA = 4 | bronze_ITA = 4 | gold_1 = 1 | silver_1 = 1 | bronze_1 = 0 | name_1 = Independent Athletes | skip_1 = yes | note_1 = <ref>this is a note</ref> | gold_SVK = 0 | silver_SVK = 0 | bronze_SVK = 1 | host_SVK = yes }}
* Host nation (Slovakia)
Rank | Nation | Gold | Silver | Bronze | Total |
---|---|---|---|---|---|
1 | Russia | 9 | 9 | 9 | 27 |
2 | South Korea | 5 | 5 | 5 | 15 |
3 | Italy | 4 | 4 | 4 | 12 |
– | Independent Athletes[೩] | 1 | 1 | 0 | 2 |
4 | Slovakia* | 0 | 0 | 1 | 1 |
Totals (4 nations) | 19 | 19 | 19 | 57 |
References
[ಬದಲಾಯಿಸಿ]- ↑ Medal Tally
- ↑ Medal Tally
- ↑ this is a note
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function deflag(s)
s = mw.ustring.gsub(s or '', '%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%]', '')
s = mw.ustring.gsub(s, '%[%[[Ii][Mm][Aa][Gg][Ee]:[^%[%]]*%]%]', '')
s = mw.ustring.gsub(s, '<[^<>]*>', '')
s = mw.ustring.gsub(s, '%s*%([A-Z][A-Z][A-Z]%)%s*$', '')
while s:match('^%s*&[Nn][Bb][Ss][Pp];%s*') do
s = mw.ustring.gsub(s, '^%s*&[Nn][Bb][Ss][Pp];%s*', '')
end
s = mw.ustring.gsub(s, '%s*&[Nn][Bb][Ss][Pp];%s*$', '')
s = mw.ustring.gsub(s, '%s%s+', ' ')
s = mw.ustring.gsub(s, '^%s*(.-?)%s*$', '%1')
return s
end
function p.createTable(frame, args)
if not args then
args = getArgs(frame)
end
local team = args['team'] or 'Nation'
local root = mw.html.create()
local host = args['host'] or ''
local hostColor = '#ccccff'
local defaultRowColor = '#f8f9fa'
local flagTemplate = args['flag_template'] or 'flagteam'
local event = args['event']
local legendpos = (args['legend_position'] or 't'):lower()
local header, footer = '', ''
local totalGold = 0
local totalSilver = 0
local totalBronze = 0
local remainingGold = 0
local remainingSilver = 0
local remainingBronze = 0
local remainingStart = 0
local remainingEnd = 0
local limitReached = false
local showLimit = tonumber(args['show_limit'])
-- build the legend
if host ~= '' then
if args['name_' .. host] then
host = args['name_' .. host]
host = 'Host nation (' .. deflag(host) .. ')'
elseif host:match('^([A-Z][A-Z][A-Z])') then
host = frame:expandTemplate{title = flagTemplate, args = {host, event} }
host = 'Host nation (' .. deflag(host) .. ')'
end
host = host .. (args['host_note'] or '')
host = frame:expandTemplate{title = 'color box', args = {hostColor, ' * ', 'border=darkgray'}} ..' '.. host
end
local leading = ''
if args['leading'] then
leading = frame:expandTemplate{title = 'legend', args = {'#E9D66B', "'''Leading in that sport'''"}}
end
if legendpos == 't' then
header = header .. host .. leading
else
footer = footer .. host .. leading
end
root = root
:tag('table')
:addClass('wikitable')
:addClass('sortable')
:addClass('plainrowheaders')
:addClass('jquery-tablesorter')
:css('text-align', 'center')
root:tag('caption')
:wikitext(args['caption'])
-- add the header row
local row = root:tag('tr')
if args['hide_rank'] then else
row:tag('th')
:attr('scope', 'col')
:wikitext('Rank')
end
row
:tag('th')
:attr('scope', 'col')
:wikitext(team)
:tag('th')
:attr('scope', 'col')
:addClass('headerSort')
:css('width', '4em')
:css('background-color', 'gold')
:wikitext('Gold')
:tag('th')
:attr('scope', 'col')
:addClass('headerSort')
:css('width', '4em')
:css('background-color', 'silver')
:wikitext('Silver')
:tag('th')
:attr('scope', 'col')
:addClass('headerSort')
:css('width', '4em')
:css('background-color', '#c96')
:wikitext('Bronze')
:tag('th')
:attr('scope', 'col')
:css('width', '4em')
:wikitext('Total')
-- enumerate the rows
local rowNums = {}
local IOCs = {}
for k,v in pairs(args) do
k = ''..k
local IOC = k:match('^gold_([A-Z][A-Z][A-Z])$') or k:match('^gold_(%d+)$')
or k:match('^silver_([A-Z][A-Z][A-Z])$') or k:match('^silver_(%d+)$')
or k:match('^bronze_([A-Z][A-Z][A-Z])$') or k:match('^bronze_(%d+)$')
if IOC and IOCs[IOC] == nil then
IOCs[IOC] = 1
local gold = (tonumber(args['gold_' .. IOC]) or 0)
local silver = (tonumber(args['silver_' .. IOC]) or 0)
local bronze = (tonumber(args['bronze_' .. IOC]) or 0)
local noskip = args['skip_' .. IOC] and 0 or 1
local nation = args['name_' .. IOC] or
frame:expandTemplate{title = flagTemplate, args = {IOC, event} }
nation = deflag(nation)
if nation:match('%[%[[^%[%]%|]*%|([^%[%]]*)%]%]') then
nation = nation:match('%[%[[^%[%]%|]*%|([^%[%]]*)%]%]')
end
if nation:match('%[%[([^%[%]%|]*)%]%]') then
nation = nation:match('%[%[([^%[%]%|]*)%]%]')
end
table.insert(rowNums, {gold, silver, bronze, noskip, nation, IOC})
end
end
if args['team'] == 'Games' then
table.sort(rowNums, function (a,b)
return a[5] < b[5]
end
)
else
table.sort(rowNums, function (a, b)
return a[1] > b[1] or (a[1] == b[1] and a[2] > b[2])
or (a[1] == b[1] and a[2] == b[2] and a[3] > b[3])
or (a[1] == b[1] and a[2] == b[2] and a[3] == b[3] and a[4] > b[4])
or (a[1] == b[1] and a[2] == b[2] and a[3] == b[3] and a[4] == b[4] and a[5] < b[5])
end
)
end
local lastGold, lastSilver, lastBronze = -1
local rank = 0
local lastspan, lastrankcell = 1, nil
for i, anum in ipairs(rowNums) do
local IOC = anum[6]
if args['skip_' .. IOC] then
lastGold, lastSilver, lastBronze, lastspan = -1, -1, -1, 1
else
rank = rank + 1
end
local nation = args['name_' .. IOC] or
frame:expandTemplate{title = flagTemplate, args = {IOC, event} }
local gold = tonumber(args['gold_' .. IOC]) or 0
local silver = tonumber(args['silver_' .. IOC]) or 0
local bronze = tonumber(args['bronze_' .. IOC]) or 0
local isHost = args['host_' .. IOC]
-- this is mainly for the parameter names example so you can override it.
local total = args['total_' .. IOC] or gold + silver + bronze
local color = isHost and hostColor or defaultRowColor
if args['grand_total'] then else
totalGold = totalGold + gold
totalSilver = totalSilver + silver
totalBronze = totalBronze + bronze
end
if args['host_' .. IOC] then
nation = nation .. '*'
end
if args['note_' .. IOC] then
nation = nation .. args['note_' .. IOC]
end
if showLimit and (rank>showLimit) then
if remainingStart == 0 then remainingStart = rank end
limitReached = true
remainingGold = remainingGold + gold
remainingSilver = remainingSilver + silver
remainingBronze = remainingBronze + bronze
else
local row
if args['leading_' .. IOC] then
row = root:tag('tr'):css('background-color', '#E9D66B')
color = '#E9D66B'
else
row = root:tag('tr')
end
--Don't put the color on the row because of ranks spanning multiple rows.
--:css('background-color', color)
if args['hide_rank'] then else
if (gold == lastGold) and (silver == lastSilver) and (bronze == lastBronze) then
lastspan = lastspan + 1
lastrankcell:attr('rowspan',lastspan)
else
lastspan = 1
if args['skip_' .. IOC] then
lastrankcell = row:tag('td'):wikitext(frame:expandTemplate{title = 'sort', args = {'999', '–'}})
else
lastrankcell = row:tag('td'):wikitext(rank)
lastGold = gold
lastSilver = silver
lastBronze = bronze
end
end
end
row:tag('th')
:attr('scope', 'row')
:css('background-color', color)
:css('text-align','left')
:wikitext(nation)
:tag('td')
:wikitext(gold)
:tag('td')
:wikitext(silver)
:tag('td')
:wikitext(bronze)
:tag('td')
:wikitext(total)
end
remainingEnd = rank
end
if limitReached then
root:tag('tr')
:tag('td')
:wikitext(remainingStart..'–'..remainingEnd)
:tag('td')
:css('font-style', 'italic')
:css('text-align','left')
:wikitext(args['remaining_link'] or args['remaining_text'] or 'Remaining')
:tag('td')
:wikitext(remainingGold)
:tag('td')
:wikitext(remainingSilver)
:tag('td')
:wikitext(remainingBronze)
:tag('td')
:wikitext(remainingGold+remainingSilver+remainingBronze)
end
if team:match('^[A-Z][A-Z][A-Z]$') or team:match('>[A-Z][A-Z][A-Z]<') then else team = team:lower() end
if team:match('^games$') then team = 'game' end
local colspan
if args['hide_rank'] then
colspan = 1
else
colspan = 2
end
if args['hide_totals'] then else
root:tag('tr')
:css('background-color', '#eaebef')
:addClass('sortbottom')
:tag('th')
:wikitext('Totals ('..remainingEnd..' '..team..'s)')
:attr('scope', 'row')
:css('background-color', '#eaebef')
:css('font-weight', 'bold')
:attr('colspan', colspan)
:tag('td')
:wikitext(args['total_gold'] or totalGold)
:css('font-weight', 'bold')
:tag('td')
:wikitext(args['total_silver'] or totalSilver)
:css('font-weight', 'bold')
:tag('td')
:wikitext(args['total_bronze'] or totalBronze)
:css('font-weight', 'bold')
:tag('td')
:wikitext(args['grand_total'] or totalGold+totalSilver+totalBronze)
:css('font-weight', 'bold')
end
-- Build the rest of the footer
if args['source'] or args['notes'] then
if footer ~= '' then
footer = footer .. '<br>'
end
footer = frame:expandTemplate{ title = 'refbegin' } .. footer
if args['source'] then
footer = footer .. 'Source: ' .. args['source']
end
if args['notes'] then
if args['source'] then
footer = footer .. '<br>'
end
footer = footer .. 'Notes: ' .. args['notes']
end
footer = footer .. frame:expandTemplate{ title = 'refend' }
end
return header .. tostring(root) .. footer
end
return p