-- CFB schedule table conversion
-- {{subst:#invoke:CFB schedule/convert|table|...}}
local p = {}
local functionmath_module splitargs= require(s"Module:Math")
s = '♣MARK♣' .. s
local function rnd(num, digits)
i = 0
-- This function implements {{rnd}}
while mw.ustring.find(s, '♣MARK♣') and (i < 100) do
return math_module._precision_format(tostring(num), digits)
i = i + 1
s=mw.ustring.gsub(s,'(♣MARK♣)%s*%|%s*([^%|{}%[%]=%s]*)%s*=%s*', '♦♦%2 = %1')
s=mw.ustring.gsub(s,'(♣MARK♣)([^%|{}%[%]=]*)', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%{%{[^%{%}]*%}%})', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%[%[[^%[%]]*%]%])', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%[[^%[%]]*%])', '%2%1')
s=mw.ustring.gsub(s,'♣MARK♣$', '')
end
local res = {}
for t in mw.text.gsplit(s, '%s*♦♦%s*') do
local k = mw.ustring.gsub(t, '^([^=]-)%s*=%s*(.-)%s*$', '%1')
local v = mw.ustring.gsub(t, '^([^=]-)%s*=%s*(.-)%s*$', '%2')
if k ~= t then
res[k] = v
end
end
return res
end
function p.ifexists(frame)
local headers = {
page = frame.args[1]
time = true,
if not page then return (frame.args['no'] or '') end
rank = true,
if mw.title.new(page).exists then return (frame.args['yes'] or 'yes') end
ranklink = true,
return (frame.args['no'] or '')
tv = true,
end
attend = false
}
function p.lists(frame)
local footers = {
local s = '\n' .. (frame.args[1] or '') .. '\n'
otherevent = nil,
s = mw.ustring.gsub(s, '([\r\n])%*([^\r\n]*)', '%1<ul><li>%2</li></ul>')
poll = nil,
s = mw.ustring.gsub(s, '([\r\n])#([^\r\n]*)', '%1<ol><li>%2</li></ol>')
timezone = nil
s = mw.ustring.gsub(s, '</ol>%s*([\r\n]*)<ol>', '%1')
}
s = mw.ustring.gsub(s, '</ul>%s*([\r\n]*)<ul>', '%1')
s = mw.ustring.gsub(s, '^[\r\n](.*)[\r\n]$', '%1')
local function parseHeader(s)
return s
local args = splitargs(s)
if args['time'] and args['time'] == 'no' then
headers['time'] = false
end
if args['rank'] and args['rank'] == 'no' then
headers['rank'] = false
end
if args['ranklink'] and args['ranklink'] == 'no' then
headers['ranklink'] = false
end
if args['tv'] and args['tv'] == 'no' then
headers['tv'] = false
end
if args['attend'] and args['attend'] == 'yes' then
headers['attend'] = true
end
end
local function parseFooterp.precision(sframe)
return math_module._precision(frame.args[1])
local args = splitargs(s)
end
if args['other-event'] and args['other-event'] ~= '' then
footers['otherevent'] = args['other-event']
function p.wpct(frame)
end
local w = tonumber(frame.args[1]) or 0
if args['poll'] and args['poll'] ~= '' then
local l = tonumber(frame.args[2]) or 0
footers['poll'] = args['poll']
local pct = '–'
end
if args['timezone'](w and+ args['timezone']l) ~=> ''0 then
pct = rnd(w / (w + l), 3):gsub('^0', '')
footers['timezone'] = args['timezone']
if mw.ustring.find(footers['timezone'], 'Eastern') then
footers['timezone'] = 'Eastern'
end
if mw.ustring.find(footers['timezone'], 'Central') then
footers['timezone'] = 'Central'
end
if mw.ustring.find(footers['timezone'], 'Mountain') then
footers['timezone'] = 'Mountain'
end
if mw.ustring.find(footers['timezone'], 'Pacific') then
footers['timezone'] = 'Pacific'
end
end
return pct
end
local function parseEntryp.extractcolor(sframe)
local argsstr = splitargs(s)frame.args[1] or ''
local color = mw.ustring.match(';' .. str .. ';', '.*;%s*([Cc][Oo][Ll][Oo][Rr]%s*:%s*.-)%s*;')
local res = ''
return color or 'NO MATCH'
res = res .. '| ' .. (args['date'] or '')
end
if args['time'] and args['time'] == 'no' then
else
local function getBestStatement(item_id, property_id)
res = res .. '| ' .. (args['time'] or '')
if not(item_id) or not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
end
return false
res = res .. '| '
if args['away'] and args['away'] ~= '' then
res = res .. 'at '
end
if args['neutral'] and args['neutral'] ~= '' then
res = res .. 'vs '
end
res = res .. '|'
if args['opprank'] and args['opprank'] ~= '' then
res = res .. '#' .. args['opprank']
end
res = res .. ' ' .. (args['opponent'] or '')
if args['nonconf'] and args['nonconf'] == 'yes' then
res = res .. '<ncg>'
end
if args['homecoming'] and args['homecoming'] == 'yes' then
res = res .. '<hc>'
end
res = res .. (args['ref'] or '')
if args['rank'] and args['rank'] == 'no' then
else
res = res .. '| ' .. (args['rank'] or '')
end
res = res .. '| ' .. (args['site_stadium'] or '')
if args['site_cityst'] and args['site_cityst'] ~= '' then
else
if args['gamename'] and args['gamename'] ~= '' then
res = res .. ' (' .. args['gamename'] .. ')'
end
end
res = res .. '| ' .. (args['site_cityst'] or '')
if args['site_cityst'] and args['site_cityst'] ~= '' then
if args['gamename'] and args['gamename'] ~= '' then
res = res .. ' (' .. args['gamename'] .. ')'
end
end
if args['tv'] and args['tv'] == 'no' then
else
res = res .. '| ' .. (args['tv'] or '')
end
local statements = mw.wikibase.getBestStatements(item_id, property_id)
res = res .. '|' .. (args['w/l'] or '') .. ' ' .. (args['score'] or '')
if not statements or #statements == 0 then
if args['overtime'] and args['overtime'] ~= '' then
return false
res = res .. '<sup>' .. args['overtime'] .. '</sup>'
end
local hasNoValue = ( statements[1].mainsnak and statements[1].mainsnak.snaktype == 'novalue' )
if args['attend'] then
if hasNoValue then
res = res .. '| ' .. args['attend']
return false
end
return res .. '\n'statements[1]
end
function p.tablehasOSM(frame)
return getBestStatement(mw.wikibase.getEntityIdForCurrentPage(), 'P402') and 'yes' or 'no'
local res = ''
end
for t in mw.text.gsplit(frame.args[1] or '', '{{[_%s]*CFB[_%s]*Schedule[_%s]*') do
local s = t:match( '^%s*(.-)%s*$' )
function p.chart(frame)
if mw.ustring.sub(s,-2) == '}}' then
local chart = require('Module:Chart')['bar-chart']
s = mw.ustring.sub(s,1,-3)
if mw.ustring.sub(s,1,5) == 'Entry' then
return chart(frame)
res = res .. parseEntry(frame,mw.ustring.sub(s,6))
end
elseif mw.ustring.sub(s,1,5) == 'Start' then
parseHeader(mw.ustring.sub(s,6))
function p.main(frame)
elseif mw.ustring.sub(s,1,3) == 'End' then
local getArgs = require('Module:Arguments').getArgs
parseFooter(mw.ustring.sub(s,4))
local args = getArgs(frame, {parentFirst = true,
valueFunc = function (key, val)
if key == 'text_IPS' then
return nil
end
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
if val == '' then
return nil
else
resreturn = res .. tval
end
else
return val
res = res .. t
end
end
})
local head = '{{CFB schedule\n'
local team_list = {}
if headers['time'] == true then
local ii = 1
head = head .. '| time = y\n'
while args['team'..ii] ~= nil do
team_list[args['team'..ii]] = ii
ii = ii + 1
end
local max_team = ii - 1
head = head .. '| atvs = y\n'
if headers['rank'] == true then
local first_team, last_team = 1, max_team
head = head .. '| rank = y\n'
if args['showteam'] and team_list[args['showteam']] then
first_team = team_list[args['showteam']] - 2
last_team = first_team + 4
if first_team < 1 then
first_team = 1
last_team = first_team + 4
end
if last_team > max_team then
last_team = max_team
first_team = max_team - 4
end
if first_team < 1 then first_team = 1 end
end
if headers['ranklink'] == true then
local hasnotes = false
head = head .. '| ranklink = y\n'
local ii = first_team
local res = '{| class="wikitable"\n'
res = res .. '! Pos. !! Team !! Result\n'
while args['team'..ii] ~= nil and (ii <= last_team) do
res = res .. '|-\n'
res = res .. '| ' .. ii .. '\n'
res = res .. '| ' .. (args['name_'..args['team' .. ii]] or '') .. '\n'
local text_result = args['result'..ii] and args['text_'..args['result'..ii]] or ''
local style_text = ''
if text_result:match('fbmulticompefn') then
hasnotes = true
style_text = style_text .. 'padding:0;'
end
style_text = style_text .. (args['result'..ii] and ('background:' .. args['col_'..args['result'..ii]]) or '')
res = res .. '| style="' .. style_text .. '" | ' .. text_result .. '\n'
ii = ii + 1
end
res = res .. '|}'
if headers['tv'] == true then
head = head .. '| tv = y\n'
if hasnotes == true then
res = res .. '<b>Table notes:</b>' .. frame:expandTemplate{ title = 'notelist'}
end
if headers['attend'] == true then
-- Generate tracking
head = head .. '| attend = y\n'
if not args['notracking'] then
-- Step 1: Generate a team and result list
for k,v in pairs(args) do
-- nothing
end
end
if footers['poll'] then
return res
head = head .. '| poll = ' .. footers['poll'] .. '\n'
end
if footers['otherevent'] then
head = head .. '| other-event = ' .. footers['otherevent'] .. '\n'
end
if footers['timezone'] then
head = head .. '| timezone = ' .. footers['timezone'] .. '\n'
end
return head .. res .. '}}'
end
return p
|