Module:Sandbox/B2project/NHL Standings: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(321 intermediate revisions by the same user not shown)
Line 1:
-- This module copies content from Template:MLB_standings; see the history of that page
-- for attribution. 6/15/16
 
local me = { }
 
local mlbDatanhlData
 
-- if mw.loadData() not supported, use require() instead
if mw.loadData then
mlbDatanhlData = mw.loadData('Module:Sandbox/B2project/NHL Standings/data')
else
mlbDatanhlData = require('Module:Sandbox/B2project/NHL Standings/data')
end
 
Line 67:
local defaultOutputForInput = {
default = 'default',
overallWinLosscurrent = 'winLossOnlycurrent',
winsloss = 'winsloss',
WLT = 'WLT',
}
 
local readTeamInfo = {
default = function(args, currentIdx, returnData)
if (args[currentIdx] == nil or
args[currentIdx+1] == nil or
args[currentIdx+2] == nil or
Line 83 ⟶ 85:
end
teamInfo = {
name = mw.text.trim(args[currentIdx]),
wins = tonumber(mw.text.trim(args[currentIdx+1])),
losses = tonumber(mw.text.trim(args[currentIdx+2])),
ties = tonumber(mw.text.trim(args[currentIdx+3])),
OTlossesotlosses = tonumber(mw.text.trim(args[currentIdx+4])),
tiebrrow = tonumber(mw.text.trim(args[currentIdx+5])),
goalsforgf = tonumber(mw.text.trim(args[currentIdx+6])),
goalsagga = tonumber(mw.text.trim(args[currentIdx+7])),
winpoints = 2,
tiepoints = 1,
otlpoints = 1,
points = '',
gamesplayed = '',
}
returnData.cIndicesRead = 58
teamInfo.wins = teamInfo.wins
teamInfo.lossesgamesplayed = teamInfo.wins + teamInfo.losses + teamInfo.ties + teamInfo.otlosses
teamInfo.ties = teamInfo.ties
teamInfo.OTlossespoints = (teamInfo.OTlosseswinpoints*teamInfo.wins)+(teamInfo.tiepoints*teamInfo.ties)+(teamInfo.otlpoints*teamInfo.otlosses)
 
teamInfo.tiebr = teamInfo.tiebr
teamInfo.goalsfor = teamInfo.goalsfor
teamInfo.goalsag = teamInfo.goalsag
return teamInfo
end, -- function readTeamInfo.default()
current = function(args, currentIdx, returnData)
if (args[currentIdx] == nil or
args[currentIdx+1] == nil or
args[currentIdx+2] == nil or
args[currentIdx+3] == nil or
args[currentIdx+4] == nil or
args[currentIdx+5] == nil or
args[currentIdx+6] == nil ) then
return nil
end
teamInfo = {
name = mw.text.trim(args[currentIdx]),
wins = tonumber(mw.text.trim(args[currentIdx+1])),
losses = tonumber(mw.text.trim(args[currentIdx+2])),
otlosses = tonumber(mw.text.trim(args[currentIdx+3])),
row = tonumber(mw.text.trim(args[currentIdx+4])),
gf = tonumber(mw.text.trim(args[currentIdx+5])),
ga = tonumber(mw.text.trim(args[currentIdx+6])),
winpoints = 2,
otlpoints = 1,
points = '',
gamesplayed = '',
}
returnData.cIndicesRead = 7
teamInfo.gamesplayed = teamInfo.wins + teamInfo.losses + teamInfo.otlosses
teamInfo.points = (teamInfo.winpoints*teamInfo.wins)+(teamInfo.otlpoints*teamInfo.otlosses)
 
return teamInfo
overallWinLoss = function(args, currentIdx, returnData)
end, -- function readTeamInfo.default()
if (args[currentIdx] == nil or
winsloss = function(args, currentIdx, returnData)
if (args[currentIdx] == nil or
args[currentIdx+1] == nil or
args[currentIdx+2] == nil ) thenor
args[currentIdx+3] == nil or
args[currentIdx+4] == nil ) then
return nil
end
teamInfo = {
name = mw.text.trim(args[currentIdx]),
wins = tonumber(mw.text.trim(args[currentIdx+1])),
losses = tonumber(mw.text.trim(args[currentIdx+2])),
gf = tonumber(mw.text.trim(args[currentIdx+3])),
ga = tonumber(mw.text.trim(args[currentIdx+4])),
winpoints = 2,
points = '',
gamesplayed = '',
}
returnData.cIndicesRead = 35
teamInfo.gamesplayed = teamInfo.wins + teamInfo.losses
teamInfo.points = (teamInfo.winpoints*teamInfo.wins)
 
return teamInfo
end, -- function readTeamInfo.default()
WLT = function(args, currentIdx, returnData)
if (args[currentIdx] == nil or
args[currentIdx+1] == nil or
args[currentIdx+2] == nil or
args[currentIdx+3] == nil or
args[currentIdx+4] == nil or
args[currentIdx+5] == nil ) then
return nil
end
teamInfo = {
name = mw.text.trim(args[currentIdx]),
wins = tonumber(mw.text.trim(args[currentIdx+1])),
losses = tonumber(mw.text.trim(args[currentIdx+2])),
ties = tonumber(mw.text.trim(args[currentIdx+3])),
gf = tonumber(mw.text.trim(args[currentIdx+4])),
ga = tonumber(mw.text.trim(args[currentIdx+5])),
winpoints = 2,
tiepoints = 1,
points = '',
gamesplayed = '',
}
returnData.cIndicesRead = 6
teamInfo.gamesplayed = teamInfo.wins + teamInfo.losses + teamInfo.ties
teamInfo.points = (teamInfo.winpoints*teamInfo.wins) + (teamInfo.tiepoints*teamInfo.ties)
 
return teamInfo
end, -- function readTeamInfo.default()
Line 120 ⟶ 199:
} -- readTeamInfo object
 
local ppgenerateTableHeader = {}
default = function(tableHeaderInfo)
return
'{| class="wikitable sortable" width="" style="text-align:center;"\
|+ [[' .. tableHeaderInfo.divisionLink.. '|' .. tableHeaderInfo.division .. ']]' ..tableHeaderInfo.source.. '\
! width=32 | <abbr title="Position">Pos</abbr>\
! width=190 | Team ' .. tableHeaderInfo.navbarText .. '\
! width=32 | <abbr title="Games played">GP</abbr>\
! width=32 | <abbr title="Won">W</abbr>\
! width=32 | <abbr title="Lost">L</abbr>\
! width=32 | <abbr title="Ties">T</abbr>\
! width=32 | <abbr title="Lost in overtime">OTL</abbr>\
! width=32 | <abbr title="Regulation + Overtime wins">ROW</abbr>\
! width=32 | <abbr title="Goals for">GF</abbr>\
! width=32 | <abbr title="Goals for">GA</abbr>\
! width=32 | <abbr title="Goal difference">GD</abbr>\
! width=32 | <abbr title="Points">Pts</abbr>\
'
end, -- function generateTableHeader.default()
 
current = function(tableHeaderInfo)
function pp.header(t,Args,p_sub,pos_label,group_col,VTE_text,full_table,results_header_txt)
return
-- Load relevant modules
'{| class="wikitable sortable" width="" style="text-align:center;"\
local yesno = require('Module:Yesno')
|+ [[' .. tableHeaderInfo.divisionLink.. '|' .. tableHeaderInfo.division .. ']]\
! width=32 | <abbr title="Position">Pos</abbr>\
-- Create table header
! width=190 | Team ' .. tableHeaderInfo.navbarText .. '\
-- Pre stuff
! width=32 | <abbr title="Games played">GP</abbr>\
local team_width = Args['teamwidth'] or '190'
! width=32 | <abbr title="Won">W</abbr>\
local sort_text = ''
! width=32 | <abbr title="Lost">L</abbr>\
local sort_table_val = Args['sortable_table'] or 'no'
! width=32 | <abbr title="Lost in overtime">OTL</abbr>\
if yesno(sort_table_val) then sort_text = 'sortable' end
! width=32 | <abbr title="Regulation + Overtime wins">ROW</abbr>\
table.insert(t,'{|class="wikitable '..sort_text..'" style="text-align:center;"\n') -- Open table
! width=32 | <abbr title="Goals for">GF</abbr>\
! width=32 | <abbr title="Goals for">GA</abbr>\
! width=32 | <abbr title="Goal difference">GD</abbr>\
! width=32 | <abbr title="Points">Pts</abbr>\
'
end,
 
winsloss = function(tableHeaderInfo)
return
'{| class="wikitable sortable" width="" style="text-align:center;"\
|+ [[' .. tableHeaderInfo.divisionLink.. '|' .. tableHeaderInfo.division .. ']]\
! width=32 | <abbr title="Position">Pos</abbr>\
! width=190 | Team ' .. tableHeaderInfo.navbarText .. '\
! width=32 | <abbr title="Games played">GP</abbr>\
! width=32 | <abbr title="Won">W</abbr>\
! width=32 | <abbr title="Lost">L</abbr>\
! width=32 | <abbr title="Goals for">GF</abbr>\
! width=32 | <abbr title="Goals for">GA</abbr>\
! width=32 | <abbr title="Goal difference">GD</abbr>\
! width=32 | <abbr title="Points">Pts</abbr>\
'
end, -- function generateTableHeader.winloss()
 
WLT = function(tableHeaderInfo)
return
'{| class="wikitable sortable" width="" style="text-align:center;"\
|+ [[' .. tableHeaderInfo.divisionLink.. '|' .. tableHeaderInfo.division .. ']]\
! width=32 | <abbr title="Position">Pos</abbr>\
! width=190 | Team ' .. tableHeaderInfo.navbarText .. '\
! width=32 | <abbr title="Games played">GP</abbr>\
! width=32 | <abbr title="Won">W</abbr>\
! width=32 | <abbr title="Lost">L</abbr>\
! width=32 | <abbr title="Ties">T</abbr>\
! width=32 | <abbr title="Goals for">GF</abbr>\
! width=32 | <abbr title="Goals for">GA</abbr>\
! width=32 | <abbr title="Goal difference">GD</abbr>\
! width=32 | <abbr title="Points">Pts</abbr>\
'
end, -- function generateTableHeader.WLT()
} -- generateTableHeader object
-- Custom header options
-- Table header
local table_header = Args['table_header']
if table_header then
table.insert(t,'|+'..table_header..'\n')
end
--Column headers
local pld_head_text = Args['pld_header'] or '<abbr title="Played">Pld</abbr>'
local OTloss_head_text = Args['OTloss_header'] or '<abbr title="Lost in overtime">OTL</abbr>'
local tiebr_head_text = Args['tiebr_header'] or '<abbr title="Tiebreaker">TBR</abbr>'
local group_head_text = Args['group_header'] or '<abbr title="Group">Grp</abbr>'
-- Use points instead of goals for/against
local for_against_style = Args['for_against_style'] or 'goals'
local fa_letter, fa_word_sing, fa_word_plur
-- First convert to lower case if it is a string
for_against_style = string.lower(for_against_style)
if for_against_style=='g' or for_against_style=='goal' or for_against_style=='goals' then
fa_letter = 'G'
fa_word_sing = 'Goal'
fa_word_plur = 'Goals'
elseif for_against_style=='p' or for_against_style=='point' or for_against_style=='points' then
fa_letter = 'P'
fa_word_sing = 'Point'
fa_word_plur = 'Points'
else
fa_letter = 'G'
fa_word_sing = 'Goal'
fa_word_plur = 'Goals'
end
-- Whether to use goal ratio (goal average) instead
local use_ratio_val = Args['use_goal_ratio'] or 'no'
local do_ratio = false
-- True if exist, false otherwise
if yesno(use_ratio_val) then do_ratio = true end
-- Whether to use tiebreak
local use_tiebr_val = Args['use_tiebreak'] or 'yes'
local do_tiebr = false
if yesno(use_tiebr_val) then do_tiebr = true end
-- Ties and OTL
local use_tieOTL_val = Args['use_ties'] or 'no'
local do_ties = false
if yesno(use_tieOTL_val) then do_ties = true end
-- Initialize
local tt = {}
tt.count = 0 -- Up by one after every call
tt.tab_text = t -- Actual text
-- Actual headers
tt = p_sub.colhead(tt,32,pos_label) -- Position col
-- Add group header
if full_table and group_col then
tt = p_sub.colhead(tt,32,group_head_text) -- Group/division col
end
tt = p_sub.colhead(tt,team_width,'Team'..VTE_text) -- Team col
tt = p_sub.colhead(tt,32,pld_head_text) -- Matches played col
if full_table then
tt = p_sub.colhead(tt,32,'<abbr title="Won">W</abbr>') -- Win col
tt = p_sub.colhead(tt,32,'<abbr title="Lost">L</abbr>') -- Loss col
if do_ties then
tt = p_sub.colhead(tt,32,'<abbr title="Ties">T</abbr>') -- Ties
end
tt = p_sub.colhead(tt,32,OTloss_head_text)
if do_tiebr then
tt = p_sub.colhead(tt,32,tiebr_head_text)
end
tt = p_sub.colhead(tt,32,'<abbr title="'..fa_word_plur..' for">'..fa_letter..'F</abbr>') -- For col
tt = p_sub.colhead(tt,32,'<abbr title="'..fa_word_plur..' against">'..fa_letter..'A</abbr>') -- Against col
if not do_ratio then
tt = p_sub.colhead(tt,32,'<abbr title="'..fa_word_sing..' difference">'..fa_letter..'D</abbr>') -- Difference col
else
tt = p_sub.colhead(tt,36,'<abbr title="'..fa_word_sing..' ratio">'..fa_letter..'R</abbr>') -- Ratio col
end
end
tt = p_sub.colhead(tt,32,'<abbr title="Points">Pts</abbr>') -- Points col
if full_table then
tt.count = tt.count+1
table.insert(tt.tab_text,results_header_txt)
end
return tt
end
 
local generateTeamRow = {
Line 222 ⟶ 276:
return
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.seedTextposition .. '[[' .. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.name .. ']]\
| style="text-align:left;" | ' .. teamRowInfo.statusText .. '[[' .. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.name .. ']]\
|| ' .. (teamInfo.wins+teamInfo.losses+teamInfo.ties+teamInfo.OTlosses) ..'\
|| ' .. teamInfo.winsgamesplayed .. ' \
|| ' .. teamInfo.losseswins .. '\n'
|| ' .. teamInfo.losses .. '\
|| ' .. teamInfo.ties ..'\
|| ' .. teamInfo.otlosses ..'\
|| ' .. teamInfo.row ..'\
|| ' .. teamInfo.gf .. '\
|| ' .. teamInfo.ga .. '\
|| ' .. teamRowInfo.goaldiff ..'\
| style="font-weight:bold;" | ' .. teamInfo.points ..'\n'
 
end, -- function generateTeamRow.default()
 
winLossOnlycurrent = function(teamRowInfo, teamInfo)
return
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.seedTextposition .. '[[' .. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.name .. ']]\
| style="text-align:left;" | ' .. teamInfoteamRowInfo.winsstatusText .. '[[' ||.. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.lossesname .. ']]\
|| ' .. teamRowInfoteamInfo.winningPercentagegamesplayed .. '\n'
|| ' .. teamInfo.wins .. '\
end, -- function generateTeamRow.winLossOnly
|| ' .. teamInfo.losses .. '\
|| ' .. teamInfo.otlosses ..'\
|| ' .. teamInfo.row ..'\
|| ' .. teamInfo.gf .. '\
|| ' .. teamInfo.ga .. '\
|| ' .. teamRowInfo.goaldiff ..'\
| style="font-weight:bold;" | ' .. teamInfo.points ..'\n'
 
end,
wildCard2012 = function(teamRowInfo, teamInfo)
 
winsloss = function(teamRowInfo, teamInfo)
return
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.seedTextposition .. '[[' .. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.name .. ']]\
| style="text-align:left;" | ' .. teamInfoteamRowInfo.winsstatusText .. '[[' ||.. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.lossesname .. ']]\
|| ' .. teamRowInfoteamInfo.winningPercentagegamesplayed .. '\
|| ' .. teamRowInfoteamInfo.gamesBehindwins .. '\n'
|| ' .. teamInfo.losses .. '\
end, -- function generateTeamRow.wildCard2012
|| ' .. teamInfo.gf .. '\
|| ' .. teamInfo.ga .. '\
|| ' .. teamRowInfo.goaldiff ..'\
| style="font-weight:bold;" | ' .. teamInfo.points ..'\n'
 
end, -- function generateTeamRow.default()
 
WLT = function(teamRowInfo, teamInfo)
return
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.position ..'\
| style="text-align:left;" | ' .. teamRowInfo.statusText .. '[[' .. teamRowInfo.teamSeasonPage .. '|' .. teamInfo.name .. ']]\
|| ' .. teamInfo.gamesplayed .. '\
|| ' .. teamInfo.wins .. '\
|| ' .. teamInfo.losses .. '\
|| ' .. teamInfo.ties .. '\
|| ' .. teamInfo.gf .. '\
|| ' .. teamInfo.ga .. '\
|| ' .. teamRowInfo.goaldiff ..'\
| style="font-weight:bold;" | ' .. teamInfo.points ..'\n'
 
end, -- function generateTeamRow.default()
 
} -- generateTeamRow object
 
local function parseSeedsparsestatus_list(seedsArgstatus_listArg, seedsstatus_list)
local seedListstatusList = mw.text.split(seedsArgstatus_listArg, '%s*,%s*')
if (#seedListstatusList == 0) then
return
end
 
for idx, seedstatus in ipairs(seedListstatusList) do
local seedDatastatusData = mw.text.split(seedstatus, '%s*:%s*')
if (#seedDatastatusData >= 2) then
local seedNumberstatusNumber = tonumber(mw.text.trim(seedDatastatusData[1]))
local team = mw.text.trim(seedDatastatusData[2])
seedsstatus_list[seedNumberstatusNumber] = team
seedsstatus_list[team] = seedNumberstatusNumber
end
end
end -- function parseSeedsparsestatus_list()
 
local function parseHighlightArg(highlightArg, teamsToHighlight)
Line 295 ⟶ 390:
if (frame.args.input ~= nil) then
local inputArg = mw.text.trim(frame.args.input)
if (inputArg == 'overallWinLosscurrent') then
inputFormat = 'overallWinLosscurrent'
end
if (inputArg == 'winsloss') then
inputFormat = 'winsloss'
end
if (inputArg == 'WLT') then
inputFormat = 'WLT'
end
end
 
Line 307 ⟶ 408:
local outputFormat = defaultOutputForInput[inputFormat]
local fDisplayNavbar = true
local fDisplayGamesBehindfDisplayTies = true
if (frame.args.output ~= nil) then
local outputArg = mw.text.trim(frame.args.output)
if (outputArg == 'winLossOnlycurrent') then
outputFormat = 'winLossOnlycurrent'
fDisplayGamesBehindfDisplayTies = false
end
if (outputArg == 'wildCard2012winsloss') then
outputFormat = 'wildCard2012winsloss'
end
if (outputArg == 'WLT') then
end
outputFormat = 'WLT'
 
end
end
local year = mw.text.trim(frame.args.year or '')
local division = mw.text.trim(frame.args.division or '')
local divisionLink = mw.text.trim(frame.args.division_link or division)
local source = mw.text.trim(frame.args.source or '')
 
local seedInfostatusInfo = {}
if (frame.args.seedsstatus_list ~= nil) then
parseSeedsparsestatus_list(frame.args.seedsstatus_list, seedInfostatusInfo)
end
 
Line 361 ⟶ 467:
 
local outputBuffer = { }
local t_footer = { }
 
local tableHeaderInfo = {
division = division,
divisionLink = divisionLink,
source = source,
}
 
if (fDisplayNavbar) then
local divisionForNavbox = division
if (mlbDatanhlData.abbreviationForDivision[division] ~= nil) then
divisionForNavbox = mlbDatanhlData.abbreviationForDivision[division]
end
 
local standingsPage
if (templateName ~= nil) then
standingsPage = templateName
else
standingsPage = year .. ' NHL ' .. divisionForNavbox .. ' standings'
end
tableHeaderInfo.navbarText =
Line 383 ⟶ 491:
standingsPage,
mini = 1,
style = 'float:left;width:0right;',
})
end
 
Line 392 ⟶ 501:
 
local leadingHalfGames = nil;
if (fDisplayGamesBehind) then
local standingsLeaderIdx = 1;
if (outputFormat == 'wildCard2012' and #listOfTeams > 1) then
standingsLeaderIdx = 2;
end
local teamInfo = listOfTeams[standingsLeaderIdx]
leadingHalfGames = (teamInfo.wins - teamInfo.losses)
end
 
for idx, teamInfo in ipairs(listOfTeams) do
local teamRowInfo = {
teamSeasonPage = year .. ' ' .. teamInfo.teamLink .. ' season',
winningPercentagestatusText = string.format('',
'%.3f', teamInfo.wins / ( teamInfo.wins + teamInfo.losses )
),
gamesBehind = '',
seedText = '',
rowStyle = '',
position = idx,
goaldiff = '',
winpoints = 2,
tiepoints = 1,
otlpoints = 1,
}
 
teamRowInfo.goaldiff = teamInfo.gf - teamInfo.ga
if teamRowInfo.goaldiff>0 then
teamRowInfo.goaldiff='<span style="color:green">+'..teamRowInfo.goaldiff..'</span>'
elseif teamRowInfo.goaldiff<0 then
teamRowInfo.goaldiff=teamRowInfo.goaldiff*-1
teamRowInfo.goaldiff='<span style="color:red">&minus;'..teamRowInfo.goaldiff..'</span>'
end
if (statusInfo[teamInfo.name] ~= nil) then
teamRowInfo.statusText = '<span style="font-weight:bold">' .. string.lower(statusInfo[teamInfo.name]) .. ' –</span> '
--teamRowInfo.rowStyle = ' style="background:#CCFFCC"'
end
 
if (teamsToHighlight[teamInfo.name]) then
teamRowInfo.rowStyle = ' style="background:#CCFFCC;font-weight:bold;"'
end
 
Line 420 ⟶ 534:
generateTeamRow[outputFormat](teamRowInfo, teamInfo)
)
 
end -- end of looping over listOfTeams
 
table.insert(outputBuffer, '|}\n')
 
local update = mw.text.trim(frame.args.update or 'unknown')
return table.concat(outputBuffer)
local start_date = mw.text.trim(frame.args.start_date or 'unknown')
--local source = mw.text.trim(frame.args.source or '')
if (source ~= nil) then
source = source
else
source = ''
end
local matches_text = mw.text.trim(frame.args.matches_text or 'games')
if string.lower(update)=='complete' then
table.insert(t_footer,'Final standings.'..tableHeaderInfo.source..'')
elseif update=='' then
-- Empty
table.insert(t_footer,'Source'..tableHeaderInfo.source..'')
elseif update=='future' then
-- Future start date
table.insert(t_footer,'First '..matches_text..' will be played on '..start_date..'. ')
else
table.insert(t_footer,'Updated to '..matches_text..' played on '..update..'.'..tableHeaderInfo.source..'')
end
return table.concat(outputBuffer), table.concat(t_footer)
 
end -- function me.generateStandingsTable()