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

Content deleted Content added
No edit summary
No edit summary
 
(306 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 = {
pos name = ''mw.text.trim(args[currentIdx]),
name wins = tonumber(mw.text.trim(args[currentIdx+1])),
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 = {
position name = mw.text.trim(args[currentIdx]),
name wins = tonumber(mw.text.trim(args[currentIdx+1])),
wins = tonumber(mw.text.trim(args[currentIdx+1])),
losses = tonumber(mw.text.trim(args[currentIdx+2])),
ties 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 126 ⟶ 202:
default = function(tableHeaderInfo)
return
'{| class="wikitable sortable" width="515em" style="text-align:center;"\
|+ [[' .. tableHeaderInfo.divisionLink.. '[[|' .. tableHeaderInfo.divisionLinkdivision .. ']]' ..tableHeaderInfo.source.. '\
! width=32 | <abbr title="Position">Pos</abbr>\
.. '|' .. tableHeaderInfo.division .. ']]\
! width=190 | Team ' .. tableHeaderInfo.navbarText .. '\
! <abbr title="Position">Pos</abbr>\
! width=32 | <abbr title="Games played">GP</abbr>\
! Team ' ..tableHeaderInfo.navbarText.. '\
! width="9%"32 | [[Winning<abbr percentage|Pct.]]title="Won">W</abbr>\
! width="7%"32 | [[Games<abbr behind|GB]]title="Lost">L</abbr>\
! width="10%"32 | [[Home<abbr (sports)|Home]]title="Ties">T</abbr>\
! width="10%"32 | [[Road<abbr (sports)|Road]]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)
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="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,
 
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
 
Line 144 ⟶ 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 217 ⟶ 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 229 ⟶ 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 283 ⟶ 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 305 ⟶ 491:
standingsPage,
mini = 1,
style = 'float:right;width:0;',
})
end
 
Line 314 ⟶ 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 = {
position = '1',
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 343 ⟶ 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()