Module:Placement

local p = {}

local ordinalSuffix = { ['1'] = 'st', ['2'] = 'nd', ['3'] = 'rd', ['4'] = 'th', ['5'] = 'th', ['6'] = 'th', ['7'] = 'th', ['8'] = 'th', ['9'] = 'th', ['0'] = 'th', ['11'] = 'th', ['12'] = 'th', ['13'] = 'th' } local placeColor = { ['1'] = '#FFD739', ['2'] = '#BEBEBE', ['3'] = '#BB8644', ['4'] = '#F8996B', ['5'] = '#007F99', ['6'] = '#007F99', ['7'] = '#007F99', ['8'] = '#007F99', ['9'] = '#166F82', ['10'] = '#166F82', ['11'] = '#166F82', ['12'] = '#166F82', ['13'] = '#166F82', ['14'] = '#166F82', ['15'] = '#166F82', ['16'] = '#166F82', ['17'] = '#2D606B', ['w'] = '#009E60', ['d'] = '#D2B48C', ['l'] = '#DDDDDD', ['dq'] = '#DDDDDD', ['q'] = '#009E60', ['div'] = '#445154' }

function getSort(num) local prefix = '' if num > 468 then prefix = 'ZZ' num = num - 468 elseif num > 234 then prefix = 'Z'		num = num - 234 end local sortLarge = math.floor((num-1)/9) local sortSmall = num - (sortLarge * 9) local sortIndex = prefix .. string.upper(string.char(string.byte("a") + sortLarge)) .. sortSmall return sortIndex end

function p.generate(placement) local placement = mw.text.split(placement, '-', true) local output = {}

local background if placement[1] == '3' and placement[2] then background = '#D2B48C' else background = placeColor[string.lower(placement[1])] or '#2D606B' end output.background = background local sort if not tonumber(placement[1]) then sort = 'ZZZZ' elseif placement[2] and placement[2] ~= '' then sort = getSort(tonumber(placement[1])) .. getSort(tonumber(placement[2])) else sort = getSort(tonumber(placement[1])) end output.sort = ' ' .. sort .. ' '	local placementDisplay, placementSpaceless if placement[2] then local suffix1 = ordinalSuffix[string.sub(placement[1], -2)] or ordinalSuffix[string.sub(placement[1], -1)] or '' local suffix2 = ordinalSuffix[string.sub(placement[2], -2)] or ordinalSuffix[string.sub(placement[2], -1)] or '' placementDisplay = placement[1] .. suffix1 .. ' - ' .. placement[2] .. suffix2 placementSpaceless = placement[1] .. suffix1 .. '-' .. placement[2] .. suffix2 else local suffix = ordinalSuffix[string.lower(string.sub(placement[1], -2))] or ordinalSuffix[string.lower(string.sub(placement[1], -1))] or '' placementDisplay = string.upper(placement[1]) .. suffix end output.display = '' .. placementDisplay .. '' output.prizepool = '' .. (placementSpaceless or placementDisplay) .. '' return output end

function p.get(frame) local args = require('Module:Arguments').getArgs(frame) local returned = p.generate(args[1]) return 'class="placement-text" style="background:' .. returned.background .. '"' .. '|' .. returned.sort .. returned.display end

function p.getCustom(frame) local args = require('Module:Arguments').getArgs(frame) local returned = p.generate(args[1]) return 'class="placement-text" style="background:' .. returned.background .. '"' .. '|' .. returned.sort .. '' .. args[2] .. '' end

return p