Content deleted Content added
No edit summary |
No edit summary |
||
(290 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
-- if mw.loadData() not supported, use require() instead
if mw.loadData then
else
end
Line 67:
local defaultOutputForInput = {
default = 'default',
winsloss = 'winsloss',
WLT = 'WLT',
}
local readTeamInfo = {
default = function(args, currentIdx, returnData)
args[currentIdx+1] == nil or
args[currentIdx+2] == nil or
Line 83 ⟶ 85:
end
teamInfo = {
losses = tonumber(mw.text.trim(args[currentIdx+2])),
ties
tiepoints = 1,
otlpoints = 1,
points = '',
gamesplayed = '',
}
returnData.cIndicesRead =
teamInfo.
teamInfo.
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
end, -- function readTeamInfo.default()
winsloss = function(args, currentIdx, returnData)
if (args[currentIdx] == nil or
args[currentIdx+1] == nil or
args[currentIdx+2] == nil
args[currentIdx+3] == nil or
args[currentIdx+4] == nil ) then
return nil
end
teamInfo = {
losses = tonumber(mw.text.trim(args[currentIdx+2])),
winpoints = 2,
}
returnData.cIndicesRead =
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 136 ⟶ 202:
default = function(tableHeaderInfo)
return
'{| class="wikitable sortable" width="
|+ [[' .. tableHeaderInfo.divisionLink.. '
! width=32 | <abbr title="Position">Pos</abbr>\
! width=190 | Team ' .. tableHeaderInfo.navbarText .. '\
! width=32 | <abbr title="Games played">GP</abbr>\
! width=32 | <abbr title="
! width=32 | <abbr title="
! width=32 | <abbr title="
! width=32 | <abbr title="
! width=32 | <abbr title="
! width=32 | <abbr title="
! width=32 | <abbr title="Goals for">
! width=32 | <abbr title="
! width=32 | <abbr title="
'
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 161 ⟶ 277:
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.position ..'\
| style="text-align:left;" | ' .. teamRowInfo.
|| ' ..
|| ' .. teamInfo.wins .. '
|| ' .. teamInfo.losses .. ' || ' .. teamInfo.ties .. || ' .. teamInfo. || ' .. teamInfo. || ' .. teamInfo. || ' .. teamInfo. || ' .. | style="font-weight:bold;" return
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.
| style="text-align:left;" | ' ..
|| ' ..
|| ' .. teamInfo.wins .. '\
|| ' .. teamInfo.losses .. '\
|| ' .. teamInfo.otlosses ..'\
|| ' .. teamInfo.row ..'\
|| ' .. teamInfo.gf .. '\
|| ' .. teamInfo.ga .. '\
|| ' .. teamRowInfo.goaldiff ..'\
| style="font-weight:bold;" | ' .. teamInfo.points ..'\n'
end,
winsloss = function(teamRowInfo, teamInfo)
return
'|-' .. teamRowInfo.rowStyle .. '\
|| ' .. teamRowInfo.
| style="text-align:left;" | ' ..
|| ' ..
|| ' ..
|| ' .. teamInfo.losses .. '\
|| ' .. 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
local
if (#
return
end
for idx,
local
if (#
local
local team = mw.text.trim(
end
end
end -- function
local function parseHighlightArg(highlightArg, teamsToHighlight)
Line 234 ⟶ 390:
if (frame.args.input ~= nil) then
local inputArg = mw.text.trim(frame.args.input)
if (inputArg == '
inputFormat = '
end
if (inputArg == 'winsloss') then
inputFormat = 'winsloss'
end
if (inputArg == 'WLT') then
inputFormat = 'WLT'
end
end
Line 246 ⟶ 408:
local outputFormat = defaultOutputForInput[inputFormat]
local fDisplayNavbar = true
local
if (frame.args.output ~= nil) then
local outputArg = mw.text.trim(frame.args.output)
if (outputArg == '
outputFormat = '
end
if (outputArg == '
outputFormat = '
end
if (outputArg == 'WLT') then
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
if (frame.args.
end
Line 300 ⟶ 467:
local outputBuffer = { }
local t_footer = { }
local tableHeaderInfo = {
division = division,
divisionLink = divisionLink,
source = source,
}
if (fDisplayNavbar) then
local divisionForNavbox = division
if (
divisionForNavbox =
end
local standingsPage
if (templateName ~= nil) then
standingsPage = templateName
else
standingsPage = year .. '
end
tableHeaderInfo.navbarText =
Line 322 ⟶ 491:
standingsPage,
mini = 1,
style = 'float:right;',
})
end
Line 331 ⟶ 501:
local leadingHalfGames = nil;
for idx, teamInfo in ipairs(listOfTeams) do
local teamRowInfo = {
teamSeasonPage = year .. ' ' .. teamInfo.teamLink .. ' season',
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">−'..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 360 ⟶ 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')
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()
|