Module:ColPollTable: Difference between revisions

Content deleted Content added
No edit summary
m Protected "Module:ColPollTable": High-risk Lua module: requested at WP:RFPP ([Edit=Require autoconfirmed or confirmed access] (indefinite) [Move=Require autoconfirmed or confirmed access] (indefinite))
 
(18 intermediate revisions by 2 users not shown)
Line 23:
default = { ['background-color'] = 'white' }
}
function p.doc(frame)
local desc = {
{'r', 'red'},
{'d', 'down'},
{'g', 'green'},
{'u', 'up'},
{'y', 'yellow'},
{'npr', 'not previously ranked'},
{'tg', 'tie green'},
{'tu', 'tie up'},
{'tr', 'tie red'},
{'td', 'tie down'},
{'ty', 'tie yellow'},
{'tnpr', 'tie not previously ranked'},
{'tw', 'tie white'},
{'-', 'default'}
}
local ret = mw.html.create('table'):addClass('wikitable')
ret:tag('tr')
:tag('th'):wikitext('Code'):done()
:tag('th'):wikitext('Abbreviation for'):done()
:tag('th'):wikitext('Result'):done()
for i=1,#desc do
local d = desc[i]
local c = string.lower(d[1])
local s = CC_backgrounds[c] or CC_backgrounds.default
ret:tag('tr')
:tag('td'):wikitext(c):done()
:tag('td'):wikitext(d[2]):done()
:tag('td'):css(s):done()
end
return ret
end
 
function p.main(frame)
Line 32 ⟶ 65:
-- get highest number looked at
-- Template_talk:ColPollTableTemplate doc says "Week#" is a required field, so we'll use that as an indicator
local max_week = 0
for i=1,3050 do
if not args['Week'..i] then
break
end
max_week = i
end
local max_sub_week = 0
-- get the highest subweek to look at
-- Week1-Y should suffice, assuming all parameters require definition
for i=1,50 do
if not args['Week1-'..i] then
break
end
max_sub_week = i
end
local tbl_args = {
max = max_week,
max_sub = max_sub_week,
weeks = {}
}
Line 48 ⟶ 92:
-- looks for parameter "name", otherwise returns "{{{name}}}"
local function argOrCall(name)
return mw.text.trim(args[name] or '') or string.format('{{{%s}}}',name)
end
for i=1,max_week do
local week_tbl = {}
week_tbl.name = 'Week ' .. argOrCall('Week'..i)
week_tbl.date = argOrCall('Week'..i..'Date')
week_tbl.cells = {}
 
for j=1,25max_sub_week do
local wkdt = string.format('Week%s-%s',i,j)
local wkcolor = string.format('Week%s-%s -Color',i,j)
wkdt = argOrCall(wkdt)
wkcolor = string.lower(argOrCall(wkcolor))
wkcolor = CC_backgrounds[wkcolor] or CC_backgroundCC_backgrounds.default
 
table.insert(week_tbl.cells, { res = wkdt, style = wkcolor })
end
local dropped = args['Week'..i..'Dropped']
if not dropped or not droppedstring.find(dropped or '','%S') then
dropped = nil
end
Line 76 ⟶ 120:
 
-- week 1 is 0 --> "Preseason"
if tbl_args.weeks[1] and tbl_args.weeks[1].name == 'Week 0' then
tbl_args.weeks[1].name = 'Preseason'
end
-- weeklast 20week is f or final --> "Final"
if tbl_args.weeks[20max_week] then
local week_20_nameweek_f_name = tbl_args.weeks[20max_week].name
week_20_nameweek_f_name = string.lower(week_20_nameweek_f_name)
if week_20_nameweek_f_name == 'week f' or week_20_nameweek_f_name == 'week final' then
tbl_args.weeks[20max_week].name = 'Final'
end
end
Line 94 ⟶ 138:
 
function p._main(args)
local ret = mw.html.create('div'):css('overflow', 'auto')
-- return table
local retroot = mw.html.createret:tag('table')
:addClass('wikitable')
:css({ ['font-size'] = '90%',
Line 102 ⟶ 147:
-- header
local header_row = retroot:tag('tr'):tag('th'):done()
for _, v in ipairs(args.weeks) do
header_row:tag('th'):wikitext(v.name)
:tag('br', { selfClosing = true }):done()
:wikitext(v.date):done()
end
header_row:tag('th'):done():done()
for i=1,25args.max_sub do
local cur_row = retroot:tag('tr')
cur_row:tag('th'):wikitext(i..'.'):done()
for _, v in ipairs(args.weeks) do
Line 122 ⟶ 169:
-- footer
local footer_row = retroot:tag('tr'):tag('th'):done()
for _, v in ipairs(args.weeks) do
footer_row:tag('tdth'):wikitext(v.name)
:tag('br', { selfClosing = true }):done()
:wikitext(v.date):done()
end
Line 131 ⟶ 180:
-- drop outs
local dropped_row = retroot:tag('tr')
dropped_row:tag('td'):attr('colspan','2'):css({ background = 'transparent', ['border-bottom-style'] = 'hidden', ['border-left-style:'] = 'hidden' }):done()
for _i, v in ipairs(args.weeks) do
if v.dropped and i > 1 then
dropped_row:tag('td'):css({ ['vertical-align'] = 'top', ['background-color'] = '#FFE6E6' })
:tag('b'):wikitext('Dropped:'):done()
:tag('br', { selfClosing = true }):done()
:wikitext(v.dropped)
:done()
elseif i > 1 then
else
dropped_row:tag('td'):css({ ['vertical-align'] = 'top', ['background-color'] = '#FFFFFF' })
:tag('i'):wikitext('None'):done()
Line 146 ⟶ 196:
end
end
dropped_row:tag('td'):css({ background = 'transparent', ['border-bottom-style'] = 'hidden', ['border-right-style:'] = 'hidden' }):done()
 
return ret