Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
[checked revision][checked revision]
(Created page with "local util_args = require('Module:ArgsUtil') local util_cargo = require("Module:CargoUtil") local util_map = require("Module:MapUtil") local util_sort = require("Module:SortUt...")
 
m (Syncing content across wikis from Call of Duty Esports Wiki, if something seems broken as a result let me know)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
local util_args = require('Module:ArgsUtil')
 
local util_args = require('Module:ArgsUtil')
 
local util_cargo = require("Module:CargoUtil")
 
local util_cargo = require("Module:CargoUtil")
 
local util_esports = require("Module:EsportsUtil")
 
local util_map = require("Module:MapUtil")
 
local util_map = require("Module:MapUtil")
 
local util_sort = require("Module:SortUtil")
 
local util_sort = require("Module:SortUtil")
  +
local util_text = require("Module:TextUtil")
 
local m_role = require('Module:Role')
 
   
 
local h = {}
 
local h = {}
   
 
local p = {}
 
local p = {}
function p.main(team)
+
function p.main(team, settings)
 
if h.hasAutoTeams(team) then
 
if h.hasAutoTeams(team) then
return h.getTeamMembers(team)
+
return h.getTeamMembers(team, settings)
 
end
 
end
return h.getListplayerCurrent(team)
+
return h.getListplayerCurrent(team, settings)
 
end
 
end
   
 
function h.hasAutoTeams(teamlink)
 
function h.hasAutoTeams(teamlink)
 
local query = {
 
local query = {
tables = 'Teams',
+
tables = 'TeamsWithAutoRosters',
fields = 'HasAutoTeamMembers',
+
fields = 'OverviewPage',
where = string.format('_pageName="%s"',teamlink),
+
where = string.format('OverviewPage="%s"',teamlink),
types = { HasAutoTeamMembers = 'boolean' },
 
 
}
 
}
 
return util_cargo.getOneResult(query)
 
return util_cargo.getOneResult(query)
 
end
 
end
   
function h.getTeamMembers(team)
+
function h.getTeamMembers(team, settings)
  +
if not settings then settings = {} end
 
local query = {
 
local query = {
  +
tables = {
tables = { 'Tenures=Ten', 'Players=P', 'RosterChanges=RCJ' },
 
  +
'Tenures=Ten',
join = { 'Ten.Player=P._pageName', 'Ten.RosterChangeIdJoin=RCJ.RosterChangeId' },
 
  +
'PlayerRedirects=PR',
  +
'Players=P',
  +
'RosterChanges=RCJ',
  +
'Alphabets=A',
  +
},
  +
join = {
  +
'Ten.Player=PR.AllName',
  +
'PR.OverviewPage=P._pageName',
 
'Ten.RosterChangeIdJoin=RCJ.RosterChangeId',
  +
'P.NameAlphabet=A.Alphabet',
  +
},
 
fields = {
 
fields = {
'P._pageName=Link',
+
'P._pageName=PlayerPage', -- for debugging
 
'P.Player=Link',
 
'P.ID',
 
'P.ID',
 
'P.Name',
 
'P.Name',
  +
'CONCAT(CASE WHEN A.IsTransliterated="1" THEN P.NameFull ELSE P.Name END)=NameFull',
'COALESCE(P.NationalityPrimary, P.Country)=Country',
+
'COALESCE(P.NationalityPrimary, P.Country)=Country [country]',
'P.Residency',
 
'RCJ.Role',
+
'P.Residency [region]',
  +
'RCJ.Roles',
 
'RCJ.RoleModifier',
 
'RCJ.RoleModifier',
  +
},
  +
complexTypes = {
  +
RoleList = {
  +
type = 'RoleList',
  +
args = {
  +
'Roles',
  +
modifier = 'RoleModifier',
  +
}
  +
}
 
},
 
},
 
where = {
 
where = {
 
'Ten.IsCurrent="1"',
 
'Ten.IsCurrent="1"',
 
('Ten.Team="%s"'):format(team),
 
('Ten.Team="%s"'):format(team),
  +
settings.hideTrainees and 'RCJ.RoleModifier IS NULL OR RCJ.RoleModifier != "Trainee"',
 
},
 
},
 
}
 
}
  +
-- util_cargo.logQuery(query)
 
local result = util_cargo.queryAndCast(query)
 
local result = util_cargo.queryAndCast(query)
 
 
 
-- should replace this with having a pre-store is_ingame check
 
-- should replace this with having a pre-store is_ingame check
 
for i = #result, 1, -1 do
 
for i = #result, 1, -1 do
if not m_role.isplayer(result[i].Role) then
+
if not result[i].RoleList:hasIngame() then
 
table.remove(result, i)
 
table.remove(result, i)
 
end
 
end
Line 54: Line 78:
 
 
 
util_map.rowsInPlace(result, h.formatOneTeamMemberRow)
 
util_map.rowsInPlace(result, h.formatOneTeamMemberRow)
util_sort.tablesByKeys(result, 'SortKeyRole', true)
+
util_sort.tablesByKeys(result, { 'SortKeyRole', 'SortKeyName' }, { true, true })
 
 
 
return result
 
return result
Line 60: Line 84:
   
 
function h.formatOneTeamMemberRow(row)
 
function h.formatOneTeamMemberRow(row)
row.SortKeyRole = m_role.sortnumber(row.Role, { sub = row.RoleModifier == 'Sub', trainee = row.RoleModifier == 'Trainee' })
+
row.SortKeyRole = row.RoleList:sortnumber()
  +
if row.Link then
  +
row.SortKeyName = mw.ustring.lower(row.Link)
  +
end
 
end
 
end
   
function h.getListplayerCurrent(team)
+
function h.getListplayerCurrent(team, settings)
  +
if not settings then settings = {} end
 
local query = {
 
local query = {
tables = 'ListplayerCurrent',
+
tables = { 'ListplayerCurrent=LPC', '_pageData=_pD' },
  +
join = 'LPC.Link=_pD._pageName',
 
fields = {
 
fields = {
  +
'_pD._pageName=Exists [boolean]',
'Link',
 
'ID',
+
'LPC.Link',
'Name',
+
'LPC.ID',
'Country',
+
'LPC.Name',
'Residency',
+
'LPC.Country [country]',
'Role',
+
'LPC.Residency [region]',
'IsSubstitute'
+
'LPC.Role',
 
'LPC.IsSubstitute [boolean]',
  +
'LPC.IsTrainee [boolean]',
 
},
 
},
  +
where = h.getLpcWhere(team, settings),
where = ('_pageName="%s" AND ID IS NOT NULL'):format(team),
 
groupBy = 'Link',
+
groupBy = 'LPC.Link',
orderBy = 'N',
+
orderBy = 'LPC.N',
  +
complexTypes = {
types = { IsSubstitute = 'boolean' },
 
  +
RoleList = {
  +
type = 'RoleList',
  +
args = {
  +
'Role',
  +
  +
-- these were previously cast as boolean
  +
sub = 'IsSubstitute',
  +
trainee = 'IsTrainee',
  +
}
  +
}
  +
}
 
}
 
}
 
local result = util_cargo.queryAndCast(query)
 
local result = util_cargo.queryAndCast(query)
  +
util_map.rowsInPlace(result, h.formatOneRowLPC)
  +
util_sort.tablesByKeys(result, { 'SortKeyRole', 'SortKeyName' }, { true, true })
 
return result
 
return result
  +
end
  +
  +
function h.getLpcWhere(team, settings)
  +
local where = {
 
('LPC._pageName="%s" AND ID IS NOT NULL'):format(team),
  +
}
  +
return where
  +
end
  +
  +
function h.formatOneRowLPC(row)
  +
row.ID = util_esports.playerDisplay(row.ID)
  +
row.NameFull = row.Name
  +
h.formatOneTeamMemberRow(row)
 
end
 
end
   

Latest revision as of 16:39, 31 August 2021

Documentation for this module may be created at Module:QueryTeamMembers/doc

local util_args = require('Module:ArgsUtil')
local util_cargo = require("Module:CargoUtil")
local util_esports = require("Module:EsportsUtil")
local util_map = require("Module:MapUtil")
local util_sort = require("Module:SortUtil")
local util_text = require("Module:TextUtil")

local h = {}

local p = {}
function p.main(team, settings)
	if h.hasAutoTeams(team) then
		return h.getTeamMembers(team, settings)
	end
	return h.getListplayerCurrent(team, settings)
end

function h.hasAutoTeams(teamlink)
	local query = {
		tables = 'TeamsWithAutoRosters',
		fields = 'OverviewPage',
		where = string.format('OverviewPage="%s"',teamlink),
	}
	return util_cargo.getOneResult(query)
end

function h.getTeamMembers(team, settings)
	if not settings then settings = {} end
	local query = {
		tables = {
			'Tenures=Ten',
			'PlayerRedirects=PR',
			'Players=P',
			'RosterChanges=RCJ',
			'Alphabets=A',
		},
		join = {
			'Ten.Player=PR.AllName',
			'PR.OverviewPage=P._pageName',
			'Ten.RosterChangeIdJoin=RCJ.RosterChangeId',
			'P.NameAlphabet=A.Alphabet',
		},
		fields = {
			'P._pageName=PlayerPage', -- for debugging
			'P.Player=Link',
			'P.ID',
			'P.Name',
			'CONCAT(CASE WHEN A.IsTransliterated="1" THEN P.NameFull ELSE P.Name END)=NameFull',
			'COALESCE(P.NationalityPrimary, P.Country)=Country [country]',
			'P.Residency [region]',
			'RCJ.Roles',
			'RCJ.RoleModifier',
		},
		complexTypes = {
			RoleList = {
				type = 'RoleList',
				args = {
					'Roles',
					modifier = 'RoleModifier',
				}
			}
		},
		where = {
			'Ten.IsCurrent="1"',
			('Ten.Team="%s"'):format(team),
			settings.hideTrainees and 'RCJ.RoleModifier IS NULL OR RCJ.RoleModifier != "Trainee"',
		},
	}
	-- util_cargo.logQuery(query)
	local result = util_cargo.queryAndCast(query)
	
	-- should replace this with having a pre-store is_ingame check
	for i = #result, 1, -1 do
		if not result[i].RoleList:hasIngame() then
			table.remove(result, i)
		end
	end
	
	util_map.rowsInPlace(result, h.formatOneTeamMemberRow)
	util_sort.tablesByKeys(result, { 'SortKeyRole', 'SortKeyName' }, { true, true })
	
	return result
end

function h.formatOneTeamMemberRow(row)
	row.SortKeyRole = row.RoleList:sortnumber()
	if row.Link then
		row.SortKeyName = mw.ustring.lower(row.Link)
	end
end

function h.getListplayerCurrent(team, settings)
	if not settings then settings = {} end
	local query = {
		tables = { 'ListplayerCurrent=LPC', '_pageData=_pD' },
		join = 'LPC.Link=_pD._pageName',
		fields = {
			'_pD._pageName=Exists [boolean]',
			'LPC.Link',
			'LPC.ID',
			'LPC.Name',
			'LPC.Country [country]',
			'LPC.Residency [region]',
			'LPC.Role',
			'LPC.IsSubstitute [boolean]',
			'LPC.IsTrainee [boolean]',
		},
		where = h.getLpcWhere(team, settings),
		groupBy = 'LPC.Link',
		orderBy = 'LPC.N',
		complexTypes = {
			RoleList = {
				type = 'RoleList',
				args = {
					'Role',
					
					-- these were previously cast as boolean
					sub = 'IsSubstitute',
					trainee = 'IsTrainee',
				}
			}
		}
	}
	local result = util_cargo.queryAndCast(query)
	util_map.rowsInPlace(result, h.formatOneRowLPC)
	util_sort.tablesByKeys(result, { 'SortKeyRole', 'SortKeyName' }, { true, true })
	return result
end

function h.getLpcWhere(team, settings)
	local where = {
		('LPC._pageName="%s" AND ID IS NOT NULL'):format(team),
	}
	return where
end

function h.formatOneRowLPC(row)
	row.ID = util_esports.playerDisplay(row.ID)
	row.NameFull = row.Name
	h.formatOneTeamMemberRow(row)
end

return p