Module:MLB standings: Difference between revisions

Content deleted Content added
add support to display ½ in "Games behind" column
add support for displaying seeds
Line 25:
end
end
 
if (mw.text.gsplit == nil) then
mw.text.gsplit = function( text, pattern, plain )
local s, l = 1, mw.ustring.len( text )
return function ()
if s then
local e, n = mw.ustring.find( text, pattern, s, plain )
local ret
if not e then
ret = mw.ustring.sub( text, s )
s = nil
elseif n < e then
-- Empty separator!
ret = mw.ustring.sub( text, s, e )
if e < l then
s = e + 1
else
s = nil
end
else
ret = e > s and mw.ustring.sub( text, s, e - 1 ) or ''
s = n + 1
end
return ret
end
end, nil, nil
end
end
 
if (mw.text.split == nil) then
mw.text.split = function ( text, pattern, plain )
local ret = {}
for m in mw.text.gsplit( text, pattern, plain ) do
ret[#ret+1] = m
end
return ret
end
end
 
 
local function readTeamInfo(args, currentIdx)
Line 47 ⟶ 86:
end -- function readTeamInfo()
 
local function parseSeeds(seedsArg, seeds)
local seedList = mw.text.split(seedsArg, '%s*,%s*')
for idx, seed in ipairs(seedList) do
local seedData = mw.text.split(seed, '%s*:%s*')
local seedNumber = tonumber(mw.text.trim(seedData[1]))
local team = mw.text.trim(seedData[2])
seeds[seedNumber] = team
seeds[team] = seedNumber
end
end -- function parseSeeds()
 
function me.generateStandingsTable(frame)
Line 55 ⟶ 104:
if (mlbData.abbreviationForDivision[division] ~= nil) then
divisionForNavbox = mlbData.abbreviationForDivision[division]
end
 
local seedInfo = {}
if (frame.args.seeds ~= nil) then
parseSeeds(frame.args.seeds, seedInfo)
end
 
Line 110 ⟶ 164:
end
 
end
 
local seedText = ''
local seedStyle = ''
if (seedInfo[teamInfo.name] ~= nil) then
seedText = '<sup>(' .. seedInfo[teamInfo.name] .. ')</sup> '
seedStyle = '| style="background:#CCFFCC"'
end
 
table.insert(outputSeq,
'|-' .. seedStyle .. '\
'|-\
| ' .. seedText .. '[[' .. year .. ' ' .. teamInfo.name .. ' season|' .. teamInfo.name .. ']]\
|| ' .. teamInfo.wins .. ' || ' .. teamInfo.losses .. '\
|| ' .. string.format('%.3f', teamInfo.wins / ( teamInfo.wins + teamInfo.losses )) .. '\