Module:TournamentUtil

local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil')

local p = {}

function p.getGroups(page, fields) if not fields then fields = { 'Team', 'GroupName', 'GroupDisplay', 'GroupN' } end local query = { tables = 'TournamentGroups', fields = fields, where = ('OverviewPage="%s"'):format(page), orderBy = 'GroupN ASC, Team ASC', types = { GroupN = 'number' } }	return util_cargo.queryAndCast(query) end

function p.getGroupTeamList(page, group) local result = p.getGroups(page) local grouplist = {} for _, row in ipairs(result) do		if row.GroupName == group then grouplist[#grouplist+1] = row.Team end end return grouplist end

function p.isInternational -- this variable is set by Infobox Tournament based on the region that's input there return util_vars.getVar('Event Region') == 'International' end

SORTING STANDINGS BY CRITERIA -- function p.getSortMethod(sortmethod) if sortmethod == 'points' then return p.sortByPoints elseif sortmethod == 'bo2points' then return p.sortByPointsBO2 elseif sortmethod == 'record' then return p.sortByRecord elseif sortmethod == 'recordwithpoints' then return p.sortByRecordWithPoints elseif sortmethod == 'recordgames' or sortmethod == 'bo2nopoints' then return p.sortByRecordGames elseif sortmethod == 'recordwithgames' then return p.sortByRecordThenGames elseif sortmethod == 'recordwithgamesnotb' then return p.sortByRecordThenGamesDontBreakTies else error('Invalid or missing sort method') end end

function p.sortByPoints(row) row.sort = row.p end

function p.sortByPointsBO2(row) row.sort = row.p - row.l / 10000 end

function p.sortByRecord(row) row.sort = util_esports.winrateRanked(row.w, row.l) end

function p.sortByRecordThenGames(row) row.sort = util_esports.winrateRanked(row.w, row.l) + util_esports.winrateRanked(row.wg, row.lg) / 10000 end

function p.sortByRecordWithPoints(row) row.sort = util_esports.winrateRanked(row.w, row.l) + row.tb / 10000 end

function p.sortByRecordGames(row) row.sort = util_esports.winrateRanked(row.wg, row.lg) end

function p.sortByRecordThenGamesDontBreakTies(row) row.sortdisplay = util_esports.winrateRanked(row.w, row.l)	row.sort = row.sortdisplay + util_esports.winrateRanked(row.wg, row.lg) / 10000 end

return p