Module:Ru Paul's Drag Race tables: Difference between revisions
Appearance
Content deleted Content added
close table |
implement pallette from Wikipedia:Manual of Style/Accessibility/Colors; modify to use triplets so that users can specify text |
||
Line 139: | Line 139: | ||
return ret .. "|}" |
return ret .. "|}" |
||
end |
end |
||
------------------------------- |
|||
⚫ | |||
------------------------------- |
|||
p.colorMap = { -- See [[Wikipedia:Manual of Style/Accessibility/Colors]] |
|||
["red"] = "#FF7B7B", |
|||
['orange'] = "#FFA7AF", |
|||
["yellow"] = "#FAFA00", |
|||
["chartreuse"] = "#A8FF4F", |
|||
["green"] = "#7BFF7B", |
|||
["spring"] = "#4FFFA8", |
|||
["cyan"] = "#00FAFA", |
|||
["dodger"] = "#4FA8FF", |
|||
["blue"] = "#8888FF", |
|||
["indigo"] = "#BB76FF", |
|||
["magenta"] = "#FF29FF", |
|||
["pink"] = "#FF52A9", |
|||
["brown"] = "#E97500", |
|||
["grey"] = "#808080", |
|||
["gray"] = "#808080" |
|||
} |
|||
⚫ | |||
function p.progressTable( frame ) |
function p.progressTable( frame ) |
||
local templateFrame = frame:getParent() |
local templateFrame = frame:getParent() |
||
local contestantData = {} |
local contestantData = {} |
||
ret = "" |
ret = "" |
||
for i=1, |
for i=1,50 do |
||
arg = templateFrame.args[i] |
arg = templateFrame.args[i] |
||
if arg == nil then |
if arg == nil then |
||
break |
break |
||
elseif i % |
elseif i % 3 == 1 then -- First in triplet is contestant name |
||
contestantData[arg] = {} |
contestantData[arg] = {} |
||
elseif i % 3 == 2 then -- Second in triple is color codes |
|||
else |
|||
contestantData[templateFrame.args[i-1]] = arg |
contestantData[templateFrame.args[i-1]][1] = arg |
||
else -- Third in triplet is text |
|||
contestantData[templateFrame.args[i-2]][2] = arg |
|||
end |
end |
||
end |
end |
||
Line 181: | Line 203: | ||
local high = 0 |
local high = 0 |
||
for k,v in pairs(contestantData) do |
for k,v in pairs(contestantData) do |
||
data[k] = mw.text.split(contestantData[k],',%s') |
data[k][1] = mw.text.split(contestantData[k][1],',%s*') |
||
data[k][2] = mw.text.split(contestantData[k][2],',%s*') |
|||
if #data[k] > high then |
if #data[k][1] > high then |
||
high = #data[k] |
high = #data[k] |
||
end |
end |
||
Line 189: | Line 212: | ||
end |
end |
||
function p._makeRow( contestant, |
function p._makeRow( contestant, data, width ) |
||
row = "|-\n! scope='row'| " .. contestant |
row = "|-\n! scope='row'| " .. contestant |
||
colors = data[1] |
|||
labels = data[2] |
|||
final = 0 |
final = 0 |
||
for i=1,20 do |
for i=1,20 do |
||
-- If we've reached the end of the list... |
|||
if placements[i] == nil then |
if placements[i] == nil then |
||
final = i |
final = i |
||
-- ...and the entries span the entire width of the table, then finish |
|||
if i > width then |
if i > width then |
||
break |
break |
||
end |
end |
||
-- ...otherwise, fill the rest of the columns with darkgray |
|||
row = row .. "| colspan='" .. width + 1 - i .. "' bgcolor='darkgray' |\n" |
row = row .. "| colspan='" .. width + 1 - i .. "' bgcolor='darkgray' |\n" |
||
break |
break |
||
Line 205: | Line 233: | ||
colorKey = string.gsub(placements[i],"%s+","") |
colorKey = string.gsub(placements[i],"%s+","") |
||
end |
end |
||
text = |
text = labels[i] |
||
row = row .. "| style='background:" .. p. |
row = row .. "| style='background:" .. p.colorMap[colors[i]] .. ";' |" .. text .. "\n" |
||
end |
end |
||
retRow = { |
retRow = { |
||
Line 213: | Line 241: | ||
} |
} |
||
return retRow |
return retRow |
||
end |
|||
function p._getColor( key ) |
|||
if key == "WIN" then |
|||
return "royalblue" -- The contestant won the challenge and won the Lip Sync against the Lip Sync Assassin. |
|||
elseif key == "WINTIE" then |
|||
return "darkblue" -- The contestant won the challenge and tied in the Lip Sync against the Lip Sync Assassin. |
|||
elseif key == "WINLOSE" then |
|||
return "yellow" -- The contestant won the challenge, but lost the Lip Sync against the Lip Sync Assassin. |
|||
elseif key == "HIGH" then |
|||
return "lightblue" -- The contestant received positive critiques and was ultimately declared safe. |
|||
elseif key == "SAFE" then |
|||
return "#F8F9FA" -- Safe |
|||
elseif key == "SAFECRIT" then |
|||
return "cornsilk" -- The contestant received critiques but was ultimately declared safe. |
|||
elseif key == "LOW" then |
|||
return "lightpink" -- The contestant received negative critiques but was ultimately declared safe. |
|||
elseif key == "BTM" then |
|||
return "tomato" -- The contestant was up for elimination. |
|||
elseif key == "ELIM" then |
|||
return "red" -- The contestant was eliminated. |
|||
else |
|||
return "black" |
|||
end |
|||
end |
|||
function p._getProgressText( key ) |
|||
key = string.gsub(key,"%s+","") |
|||
if key == "ELIM" then |
|||
return "'''ELIM'''" |
|||
elseif string.find(key, "WIN") ~= nil then |
|||
if key == "WIN" or key == "WINTIE" then |
|||
return "<span style='color:white; font-weight: bold;'>WIN</span>" |
|||
end |
|||
return "WIN" |
|||
elseif #key < 5 then |
|||
return key |
|||
elseif string.find(key, "SAFE") ~= nil then |
|||
return "SAFE" |
|||
end |
|||
end |
end |
||
Revision as of 20:38, 11 July 2020
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module implements {{Drag Race contestant table}} and {{Drag Race progress table}}. See the code for more details.
local p = {} --p stands for package
function p._getContestant( k )
return string.match( k, "contestant%-(%d+)" )
end
function p._getField( k )
return string.match( k, "contestant%-%d+%-(.*)")
end
function p._inTable( t, k )
return (t[k] ~= nil)
end
function p._getContestantData( frame )
local contestantData = {}
for k, v in pairs( frame.args ) do
-- Read inputs and organize them by contestant
if not p._inTable(contestantData, p._getContestant(k)) then
contestantData[p._getContestant(k)] = {}
end
if p._getField(k) ~= nil then
contestantData[p._getContestant(k)][p._getField(k)] = v
else
contestantData[p._getContestant(k)]["name"] = v
end
end
for k, v in pairs( contestantData ) do
-- Final cleanup of the input before rendering table
if not p._inTable(contestantData[k],"nrows") then
contestantData[k]["nrows"] = 1
end
if not p._inTable(contestantData[k],"place-sort") then
if #tostring(contestantData[k]['place']) > 2 then
place = string.match(contestantData[k]['place'],'(%d+)%D%D')
else
place = contestantData[k]['place']
end
contestantData[k]["place-sort"] = p._makePlaceSort(place)
end
if #tostring(contestantData[k]['place']) < 3 then
contestantData[k]['place'] = p._makePlace(contestantData[k]['place'])
end
end
return contestantData
end
function p.makeRow( contestant )
local rowTemplate = [=[
|-
! scope="row" rowspan="${NROWS}"|[[${NAME}]]
|rowspan="${NROWS}"|${AGE}
|rowspan="${NROWS}"|${HOMETOWN}
]=]
if string.find(contestant['season'], 'All Stars') ~= nil then
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race All Stars (season ${SEASON-NUM})|''All Stars'' ${SEASON-NUM}]]\n"
contestant['season-num'] = string.match(contestant['season'], 'All Stars (%d+)')
contestant['season'] = nil
else
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]]\n"
end
rowTemplate = rowTemplate .. [=[
|<span data-sort-value="${PLACE-SORT}">${PLACE}</span>
]=]
if contestant['outcome'] ~= nil then
rowTemplate = rowTemplate .. '|rowspan="${NROWS}"|${OUTCOME}\n'
if #tostring(contestant['outcome']) < 3 then
contestant['outcome'] = p._makePlace(contestant['outcome'])
end
else
rowTemplate = rowTemplate .. '|rowspan="${NROWS}" style="background: #DDF; color: #2C2C2C; vertical-align: middle; text-align: center;" class="no table-no2"|TBA\n'
end
if tonumber(contestant['nrows']) > 1 then
rowTemplate = rowTemplate .. "|-\n"
if string.find(contestant['season2'], 'All Stars') ~= nil then
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race All Stars (season ${SEASON2-NUM})|''All Stars'' ${SEASON2-NUM}]]\n"
contestant['season2-num'] = tostring(string.match(contestant['season2'], '%d+'))
contestant['season2'] = nil
else
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race (season ${SEASON2})|Season ${SEASON2}]]\n"
end
rowTemplate = rowTemplate .. '|<span data-sort-value="${PLACE2-SORT}">${PLACE2}</span>\n'
if contestant['place2-sort'] == nil then
contestant['place2-sort'] = p._makePlaceSort(contestant['place2'])
end
local place
if #tostring(contestant['place2']) > 2 then
place = string.match(contestant['place2'],'(%d+)%D%D')
else
place = contestant['place2']
end
contestant['place2'] = p._makePlace(place)
end
for k, v in pairs( contestant ) do
mw.log(k:upper())
rowTemplate = string.gsub(rowTemplate,"${"..k:upper():gsub('%-','%%-').."}",contestant[k])
end
return rowTemplate
end
function p._makePlaceSort( place )
if #tostring(place) < 2 then
return '0'..place
else
return place
end
end
function p._makePlace( place )
place = tonumber(place)
if place == 1 then
return '1st Place'
elseif place == 2 then
return '2nd Place'
elseif place == 3 then
return'3rd Place'
else
return place .. 'th Place'
end
end
function p.main( frame )
local templateFrame = frame:getParent()
local contestantData = p._getContestantData( templateFrame )
ret = [=[
{| class="wikitable sortable" border="2" style="text-align:center;"
|+ Contestants of ''All Stars 5'' and their backgrounds
! scope="col"| Contestant
! scope="col"| Age
! scope="col"| Hometown
! scope="col"| Original season(s)
! scope="col"| Original placement(s)
! scope="col"| Outcome
]=]
for k, v in pairs( contestantData ) do
ret = ret .. p.makeRow(contestantData[k])
end
return ret .. "|}"
end
-------------------------------
-- Contestant progress table --
-------------------------------
p.colorMap = { -- See [[Wikipedia:Manual of Style/Accessibility/Colors]]
["red"] = "#FF7B7B",
['orange'] = "#FFA7AF",
["yellow"] = "#FAFA00",
["chartreuse"] = "#A8FF4F",
["green"] = "#7BFF7B",
["spring"] = "#4FFFA8",
["cyan"] = "#00FAFA",
["dodger"] = "#4FA8FF",
["blue"] = "#8888FF",
["indigo"] = "#BB76FF",
["magenta"] = "#FF29FF",
["pink"] = "#FF52A9",
["brown"] = "#E97500",
["grey"] = "#808080",
["gray"] = "#808080"
}
function p.progressTable( frame )
local templateFrame = frame:getParent()
local contestantData = {}
ret = ""
for i=1,50 do
arg = templateFrame.args[i]
if arg == nil then
break
elseif i % 3 == 1 then -- First in triplet is contestant name
contestantData[arg] = {}
elseif i % 3 == 2 then -- Second in triple is color codes
contestantData[templateFrame.args[i-1]][1] = arg
else -- Third in triplet is text
contestantData[templateFrame.args[i-2]][2] = arg
end
end
contestantData, width = p._parseRanks( contestantData )
ret = ret .. [=[{| class="wikitable" style="text-align:center;"
|+Progress of contests including rank/position in each episode
! scope="col"| Contestant
]=]
for i=1,width do
ret = ret .. "! scope='col'| " .. i .."\n"
end
rowList = {}
for k,v in pairs(contestantData) do
table.insert(rowList,p._makeRow(k,v,width))
end
table.sort(rowList,p._sortRows)
for i=1,20 do
if rowList[i] == nil then
break
end
ret = ret .. rowList[i][2]
end
return ret .. "|}"
end
function p._parseRanks( contestantData )
local data = {}
local high = 0
for k,v in pairs(contestantData) do
data[k][1] = mw.text.split(contestantData[k][1],',%s*')
data[k][2] = mw.text.split(contestantData[k][2],',%s*')
if #data[k][1] > high then
high = #data[k]
end
end
return data, high
end
function p._makeRow( contestant, data, width )
row = "|-\n! scope='row'| " .. contestant
colors = data[1]
labels = data[2]
final = 0
for i=1,20 do
-- If we've reached the end of the list...
if placements[i] == nil then
final = i
-- ...and the entries span the entire width of the table, then finish
if i > width then
break
end
-- ...otherwise, fill the rest of the columns with darkgray
row = row .. "| colspan='" .. width + 1 - i .. "' bgcolor='darkgray' |\n"
break
elseif string.find(placements[i],"BTM") ~= nil then
colorKey = "BTM"
else
colorKey = string.gsub(placements[i],"%s+","")
end
text = labels[i]
row = row .. "| style='background:" .. p.colorMap[colors[i]] .. ";' |" .. text .. "\n"
end
retRow = {
final,
row
}
return retRow
end
function p._sortRows(a,b)
return a[1] > b[1]
end
return p