Module:Sports games
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module is similar to Module:Sports results, but the matches are arranged linearly by game number.
Usage
<syntaxhighlight lang=wikitext>
Team | Game | ||
---|---|---|---|
1 | 2 | 3 | |
AAA | BBB 100–90 | CCC 99–96 | DDD 89–90 |
BBB | AAA 90–100 | DDD 120–111* | CCC 103–101 |
CCC | DDD 101–89 | AAA 96–99 | BBB 101–103 |
DDD | CCC 89–101 | BBB 111–120* | AAA 90–89 |
Updated to match(es) played on unknown. Source: [citation needed]
Legend: Blue = win; Red = loss; Matches with lighter background shading were decided after overtime. (*) Number of asterisks denotes number of overtime periods
</syntaxhighlight>
Legend: Blue = win; Red = loss; Matches with lighter background shading were decided after overtime. (*) Number of asterisks denotes number of overtime periods
- An asterisk can be appended to indicate an overtime result.
- For events where teams only play each other once, the
auto
keyword can be used to automatically fill in the score for the other team. - To override the default match column width, use
|match_col_width=
with a width in pixels. - To override the default table font size, use
|font_size=
with the size as a percentage (note that less than 85% is discouraged).
Example
<syntaxhighlight lang=wikitext>
Team | Game | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
Barangay Ginebra (BGSM) | CON 100–86 | MAG 91–93 | ROS 107–102 | BWB 90–87 | TER 110–99 | PHX 77–82 | SMB 82–95 | MER 110–96 | TNT 86–78 | NP 103–93 | NLEX 103–99 |
Blackwater (BWB) | CON 103–84 | MER 84–91 | TER 87–97 | PHX 106–111 | BGSM 87–90 | ROS 110–115 | MAG 84–105 | TNT 96–105 | NLEX 97–104 | NP 89–106 | SMB 117–125 |
Converge (CON) | BWB 84–103 | TNT 98–101* | BGSM 86–100 | SMB 96–105 | PHX 98–99 | NP 95–111 | TER 103–94* | MER 99–105 | MAG 80–88 | NLEX 103–107 | ROS 111–112 |
Magnolia (MAG) | TNT 110–102 | PHX 107–92 | NP 112–74 | BGSM 93–91 | NLEX 99–72 | BWB 105–84 | SMB 94–90 | ROS 110–113 | TER 104–91 | CON 88–80 | MER 80–85 |
Meralco (MER) | ROS 107–102 | BWB 91–84 | SMB 83–93 | TNT 109–95 | NLEX 96–94 | NP 125–99 | CON 105–99 | BGSM 96–110 | MAG 85–80 | PHX 83–93 | TER 109–102 |
NLEX | PHX 101–113 | SMB 117–113* | TER 112–113 | NP 112–104 | MAG 72–99 | MER 94–96 | ROS 101–113 | TNT 97–113 | BWB 104–97 | CON 107–103 | BGSM 99–103 |
NorthPort (NP) | TER 108–103 | ROS 113–103 | MAG 74–112 | NLEX 104–112 | TNT 128–123* | CON 111–95 | SMB 115–101 | MER 99–125 | PHX 104–113 | BWB 106–89 | BGSM 93–103 |
Phoenix Super LPG (PHX) | NLEX 113–101 | MAG 92–107 | ROS 99–98 | BWB 111–106 | TER 103–84 | CON 99–98 | BGSM 82–77 | NP 113–104 | SMB 96–117 | MER 93–83 | TNT 96–116 |
Rain or Shine (ROS) | MER 102–107 | NP 103–113 | PHX 98–99 | BGSM 102–107 | SMB 110–115 | BWB 115–110 | NLEX 113–101 | MAG 113–110 | TER 116–105 | TNT 119–112 | CON 112–111 |
San Miguel (SMB) | NLEX 113–117* | MER 93–83 | CON 105–96 | ROS 115–110 | NP 101–115 | MAG 90–94 | BGSM 95–82 | TNT 98–93 | PHX 117–96 | TER 132–110 | BWB 125–117 |
Terrafirma (TER) | NP 103–108 | BWB 97–87 | NLEX 113–112 | TNT 93–133 | PHX 84–103 | BGSM 99–110 | CON 94–103* | MAG 91–104 | ROS 105–116 | SMB 110–132 | MER 102–109 |
TNT | MAG 102–110 | CON 101–98* | TER 133–93 | MER 95–109 | NP 123–128* | NLEX 113–97 | BWB 105–96 | SMB 93–98 | BGSM 78–86 | ROS 112–119 | PHX 116–96 |
Updated to match(es) played on unknown. Source: PBA.ph results
Legend: Blue = win; Red = loss; Matches with lighter background shading were decided after overtime. (*) Number of asterisks denotes number of overtime periods
</syntaxhighlight>
Legend: Blue = win; Red = loss; Matches with lighter background shading were decided after overtime. (*) Number of asterisks denotes number of overtime periods
Team | Game | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
Barangay Ginebra (BGSM) | CON 100–86 | MAG 91–93 | ROS 107–102 | BWB 90–87 | TER 110–99 | PHX 77–82 | SMB 82–95 | MER 110–96 | TNT 86–78 | NP 103–93 | NLEX 103–99 |
Blackwater (BWB) | CON 103–84 | MER 84–91 | TER 87–97 | PHX 106–111 | BGSM 87–90 | ROS 110–115 | MAG 84–105 | TNT 96–105 | NLEX 97–104 | NP 89–106 | SMB 117–125 |
Converge (CON) | BWB 84–103 | TNT 98–101* | BGSM 86–100 | SMB 96–105 | PHX 98–99 | NP 95–111 | TER 103–94* | MER 99–105 | MAG 80–88 | NLEX 103–107 | ROS 111–112 |
Magnolia (MAG) | TNT 110–102 | PHX 107–92 | NP 112–74 | BGSM 93–91 | NLEX 99–72 | BWB 105–84 | SMB 94–90 | ROS 110–113 | TER 104–91 | CON 88–80 | MER 80–85 |
Meralco (MER) | ROS 107–102 | BWB 91–84 | SMB 83–93 | TNT 109–95 | NLEX 96–94 | NP 125–99 | CON 105–99 | BGSM 96–110 | MAG 85–80 | PHX 83–93 | TER 109–102 |
NLEX | PHX 101–113 | SMB 117–113* | TER 112–113 | NP 112–104 | MAG 72–99 | MER 94–96 | ROS 101–113 | TNT 97–113 | BWB 104–97 | CON 107–103 | BGSM 99–103 |
NorthPort (NP) | TER 108–103 | ROS 113–103 | MAG 74–112 | NLEX 104–112 | TNT 128–123* | CON 111–95 | SMB 115–101 | MER 99–125 | PHX 104–113 | BWB 106–89 | BGSM 93–103 |
Phoenix Super LPG (PHX) | NLEX 113–101 | MAG 92–107 | ROS 99–98 | BWB 111–106 | TER 103–84 | CON 99–98 | BGSM 82–77 | NP 113–104 | SMB 96–117 | MER 93–83 | TNT 96–116 |
Rain or Shine (ROS) | MER 102–107 | NP 103–113 | PHX 98–99 | BGSM 102–107 | SMB 110–115 | BWB 115–110 | NLEX 113–101 | MAG 113–110 | TER 116–105 | TNT 119–112 | CON 112–111 |
San Miguel (SMB) | NLEX 113–117* | MER 93–83 | CON 105–96 | ROS 115–110 | NP 101–115 | MAG 90–94 | BGSM 95–82 | TNT 98–93 | PHX 117–96 | TER 132–110 | BWB 125–117 |
Terrafirma (TER) | NP 103–108 | BWB 97–87 | NLEX 113–112 | TNT 93–133 | PHX 84–103 | BGSM 99–110 | CON 94–103* | MAG 91–104 | ROS 105–116 | SMB 110–132 | MER 102–109 |
TNT | MAG 102–110 | CON 101–98* | TER 133–93 | MER 95–109 | NP 123–128* | NLEX 113–97 | BWB 105–96 | SMB 93–98 | BGSM 78–86 | ROS 112–119 | PHX 116–96 |
Updated to match(es) played on unknown. Source: PBA.ph results
Legend: Blue = win; Red = loss; Matches with lighter background shading were decided after overtime. (*) Number of asterisks denotes number of overtime periods
Legend: Blue = win; Red = loss; Matches with lighter background shading were decided after overtime. (*) Number of asterisks denotes number of overtime periods
-- Module to build Sports games table
-- See documentation for details
require('strict')
local p = {}
-- Helper functions
local function get_team_label(team_abbr, team_name)
if team_name == nil then
team_name = team_abbr
end
local team_text = team_name
if team_text:match('^%[%[[^%|%[%]]*%|([^%|%[%]]*)%]%]') then
team_text = team_text:match('^%[%[[^%|%[%]]*%|([^%|%[%]]*)%]%]')
end
if team_text:match('^%[%[([^%|%[%]]*)%]%]') then
team_text = team_text:match('^%[%[([^%|%[%]]*)%]%]')
end
local team_label = team_name
if team_text ~= team_abbr then
team_label = team_label .. '<br>(' .. team_abbr .. ')'
end
return team_label
end
local function get_score_background(s, c)
local s1, s2
-- Define the colouring
local wc, lc, tc
if c == 'level2' then
wc, lc, tc = '#CCF9FF', '#FCC', '#FFC' -- blue2, red2, yellow2
elseif c == 'level3' then
wc, lc, tc = '#DDFCFF', '#FDD', '#FFD' -- blue3, red3, yellow3
elseif c == 'level4' then
wc, lc, tc = '#EEFFFF', '#FEE', '#FFE' -- blue4, red4, yellow4
else
wc, lc, tc = '#BBF3FF', '#FBB', '#FFB' -- blue1, red1, yellow1
end
-- check for override
if s:match('^%s*<span%s+style%s*=["\'%s]*background[%-colr]*%s*:([^\'";<>]*).-$') then
local c = mw.ustring.gsub(s,'^%s*<span%s+style%s*=["\'%s]*background[%-colr]*%s*:([^\'";<>]*).-$', '%1')
return c
end
-- delink if necessary
if s:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]') then
s = s:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]')
end
if s:match('^%s*%[[^%[%]%s]*%s([^%[%]]*)%]') then
s = s:match('^%s*%[[^%[%]%s]*%s([^%[%]]*)%]')
end
if s:match('<span[^<>]*>(.-)</span>') then
s = s:match('<span[^<>]*>(.-)</span>')
end
-- get the scores
s1 = tonumber(mw.ustring.gsub( s or '',
'^%s*([%d%.]+)%s*–%s*([%d%.]+).*', '%1' ) or '') or ''
s2 = tonumber(mw.ustring.gsub( s or '',
'^%s*([%d%.]+)%s*–%s*([%d%.]+).*', '%2' ) or '') or ''
-- return colouring if possible
if s1 ~= '' and s2 ~= '' then
return (s1 > s2) and wc or ((s2 > s1) and lc or tc)
else
return 'transparent'
end
end
local function format_score(s)
s = mw.ustring.gsub(s or '', '^%s*([%d%.]+)%s*[–−—%-]%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*([%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*%-%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*%-%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
return s
end
local function flip_score(s)
s = format_score(s)
s = mw.ustring.gsub(s, '([%d%.]+)–([%d%.]+)', '%2–%1')
return s
end
local function is_overtime(s)
if s:match('%d+–%d+[%s%]]*%*') then
return true
end
return false
end
-- Main function
function p.table(frame)
-- Get the args, stripping out blank values
local getArgs = require('Module:Arguments').getArgs
local Args = getArgs(frame, {parentFirst = true})
-- Exit early if we are using section transclusion for a different section
local tsection = frame:getParent().args['transcludesection'] or frame:getParent().args['section'] or ''
local bsection = frame.args['section'] or ''
if( tsection ~= '' and bsection ~= '' ) then
if( tsection ~= bsection ) then
return ''
end
end
if Args['team_order'] and Args['team_order'] ~= '' then
local tlist = mw.text.split(Args['team_order'], '%s*[;,]%s*')
for k, tname in ipairs(tlist) do
if tname ~= '' then
Args['team' .. k] = tname
end
end
end
-- Build team list
local team_list = {}
local other_team_table = {}
local k = 1
while Args['team' .. k] do
team_list[k] = Args['team' .. k]
other_team_table[Args['team' .. k]] = {}
k = k + 1
end
-- Store the results
local total_games = 0
for k,v in pairs(Args) do
if v and v ~= '' and k:match('^m%d+_[^_]+_[^_]+$') then
local g = k:match('^m(%d+)_[^_]+_[^_]+$')
local t1 = k:match('^m%d+_([^_]+)_[^_]+$')
local t2 = k:match('^m%d+_[^_]+_([^_]+)$')
if other_team_table[t1] then
other_team_table[t1][tonumber(g)] = t2
end
total_games = (tonumber(g) > total_games) and tonumber(g) or total_games
end
end
-- Start the div
local root = mw.html.create('div')
:css('overflow-x', 'auto')
:css('white-space', 'nowrap')
-- Start table
local t = root:tag('table')
:addClass('wikitable')
:addClass('plainrowheaders')
:css('text-align', 'center')
:css('font-size', Args['font_size'])
-- Table title
if Args['title'] and Args['title'] ~= '' then
t:tag('caption'):wikitext(Args['title'])
end
-- Header rows
local match_col_width = Args['match_col_width'] and (Args['match_col_width'] .. 'px') or nil
local row = t:tag('tr')
row:tag('th')
:attr('scope', 'col')
:attr('rowspan', 2)
:wikitext('Team')
row:tag('th')
:attr('scope', 'col')
:attr('colspan', total_games)
:wikitext('Game')
row = t:tag('tr')
for jj = 1,total_games do
row:tag('th')
:attr('scope', 'col')
:css('width', match_col_width)
:wikitext(jj)
end
-- Results rows
local ot_note = false
for ii=1,#team_list do
local team_abbr = team_list[ii]
local team_label = get_team_label(team_abbr, Args['name_' .. team_abbr])
row = t:tag('tr')
row:tag('th')
:attr('scope', 'row')
:css('background', 'inherit')
:wikitext(team_label)
for jj=1,total_games do
local other_team_abbr = other_team_table[team_abbr][jj] or ''
local result = ''
if other_team_abbr ~= '' then
result = Args['m' .. jj .. '_' .. team_abbr .. '_' .. other_team_abbr] or ''
if result == other_team_abbr or result == 'auto' then
for kk=1,total_games do
local other_result = Args['m' .. kk .. '_' .. other_team_abbr .. '_' .. team_abbr]
if other_result then
result = flip_score(other_result)
end
end
end
end
local ot_flag = is_overtime(result)
if (ot_flag) then
ot_note = true
end
local bg = get_score_background(result, ot_flag and 'level3' or 'level1')
if result ~= '' then
result = other_team_abbr .. '<br>' .. format_score(result)
end
row:tag('td')
:css('background', bg)
:wikitext(result)
end
end
-- footer
local t_footer = {}
local update = Args['update'] or 'unknown'
local start_date = Args['start_date'] or 'unknown'
local source = Args['source']
or frame:expandTemplate{ title = 'citation needed',
args = { reason='No source parameter defined', date=os.date('%B %Y') } }
-- Date updating
if string.lower(update)=='complete' then
-- Do nothing
elseif update=='' then
-- Empty parameter
table.insert(t_footer,'Updated to match(es) played on unknown. ')
elseif string.lower(update)=='future' then
-- Future start date
table.insert(t_footer,'First match(es) will be played: '..start_date..'. ')
else
table.insert(t_footer,'Updated to match(es) played on '..update..'. ')
end
table.insert(t_footer,'Source: '..source)
table.insert(t_footer, '<br />Legend: Blue = win; Red = loss')
if ot_note then
table.insert(t_footer, '; Matches with lighter background shading were decided after overtime.')
table.insert(t_footer, ' (*) Number of asterisks denotes number of overtime periods')
end
t_footer = mw.html.create('div')
:css('font-size', '90%')
:css('margin-bottom', '0.5em')
:wikitext(table.concat(t_footer))
return tostring(root) .. tostring(t_footer)
end
return p