Halo Esports Wiki
[checked revision][checked revision]
No edit summary
No edit summary
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
--local Role = require('Module:Role').role
 
--local Role = require('Module:Role').role
  +
local Sprite = require('Module:Sprite').sprite
   
 
local p = {}
 
local p = {}
  +
local s = {}
  +
  +
function s.LeagueSprite(id)
  +
return Sprite{
  +
id,
  +
type = 'League'
  +
}
  +
end
   
 
function p.playerResults( frame )
 
function p.playerResults( frame )
Line 20: Line 29:
 
local m_team = require('Module:Team')
 
local m_team = require('Module:Team')
 
local League = require('Module:League').league
 
local League = require('Module:League').league
local placement = require('Module:Placement')
+
local placement = mw.loadData('Module:Placementnames')
 
local Game = require('Module:Game').game
 
local Game = require('Module:Game').game
   
 
local tbl = mw.html.create('table')
 
local tbl = mw.html.create('table')
tbl:addClass("wikitable sortable"):css("font-size","90%")
+
tbl:addClass("wikitable sortable hoverable-rows"):css("font-size","90%")
 
:tag("tr")
 
:tag("tr")
:tag("th"):css({ background = "#E6E6E6", border = "1px solid black" }):attr("colspan","30")
+
:tag("th"):css({ background = "var(--tournament-results-bar)" }):attr("colspan","30")
 
:wikitext(player .. ' Tournament Results'):done()
 
:wikitext(player .. ' Tournament Results'):done()
 
:done()
 
:done()
Line 44: Line 53:
 
for _,row in ipairs(result) do
 
for _,row in ipairs(result) do
 
mw.log('result')
 
mw.log('result')
  +
place = placement[string.lower(row["Place"])] or { bgcolor = "", hiddensort = "", fontcolor = "red", display = "Invalid Placement Name[[Category:Pages With Invalid Placement Names]]" }
 
tr = tbl:tag("tr")
 
tr = tbl:tag("tr")
 
tr:tag('td'):wikitext(Game{row['Game']}):done()
 
tr:tag('td'):wikitext(Game{row['Game']}):done()
 
tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done() -- Need to format this right still
 
tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done() -- Need to format this right still
  +
:tag("td")
:node(placement.makeNode(row.Place))
 
  +
:css({ ["background-color"] = "#" .. place["bgcolor"], color = place["fontcolor"], ["text-align"] = "center" })
  +
:wikitext('<span style="display:none;">' .. place.hiddensort .. "</span>'''" .. place.display .. "'''")
  +
:done()
 
:tag("td"):wikitext(row["PrizeMarkup"]):done()
 
:tag("td"):wikitext(row["PrizeMarkup"]):done()
tdEvent = tr:tag("td"):wikitext(League{row["League"],"onlyimage"} .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
+
tdEvent = tr:tag("td"):wikitext(s.LeagueSprite(row.League) .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
 
if row["Phase"] ~= "" then
 
if row["Phase"] ~= "" then
 
tdEvent:wikitext(" - " .. row["Phase"])
 
tdEvent:wikitext(" - " .. row["Phase"])
Line 107: Line 120:
 
local m_team = require('Module:Team')
 
local m_team = require('Module:Team')
 
local League = require('Module:League').league
 
local League = require('Module:League').league
local placement = require('Module:Placement')
+
local placement = mw.loadData('Module:Placementnames')
 
local Game = require('Module:Game').game
 
local Game = require('Module:Game').game
 
 
Line 113: Line 126:
 
 
 
local tbl = mw.html.create('table')
 
local tbl = mw.html.create('table')
tbl:addClass("wikitable sortable"):css("font-size","90%")
+
tbl:addClass("wikitable sortable hoverable-rows"):css("font-size","90%")
 
:tag("tr")
 
:tag("tr")
:tag("th"):css({ background = "#E6E6E6", border = "1px solid black" }):attr("colspan","30")
+
:tag("th"):css({ background = "var(--tournament-results-bar)" }):attr("colspan","30")
 
:wikitext('Recent Tournament Results [[' .. player .. '/Tournament Results|(View All)]]'):done()
 
:wikitext('Recent Tournament Results [[' .. player .. '/Tournament Results|(View All)]]'):done()
 
:done()
 
:done()
Line 133: Line 146:
 
for _,row in ipairs(result) do
 
for _,row in ipairs(result) do
 
mw.log('result')
 
mw.log('result')
  +
place = placement[string.lower(row["Place"])] or { bgcolor = "", hiddensort = "", fontcolor = "red", display = "Invalid Placement Name[[Category:Pages With Invalid Placement Names]]" }
 
tr = tbl:tag("tr")
 
tr = tbl:tag("tr")
 
tr:tag('td'):wikitext(Game{row['Game']}):done()
 
tr:tag('td'):wikitext(Game{row['Game']}):done()
 
tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done() -- Need to format this right still
 
tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done() -- Need to format this right still
  +
:tag("td")
:node(placement.makeNode(row.Place))
 
  +
:css({ ["background-color"] = "#" .. place["bgcolor"], color = place["fontcolor"], ["text-align"] = "center" })
  +
:wikitext('<span style="display:none;">' .. place.hiddensort .. "</span>'''" .. place.display .. "'''")
  +
:done()
 
:tag("td"):wikitext(row["PrizeMarkup"]):done()
 
:tag("td"):wikitext(row["PrizeMarkup"]):done()
tdEvent = tr:tag("td"):wikitext(League{row["League"],"onlyimage"} .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
+
tdEvent = tr:tag("td"):wikitext(s.LeagueSprite(row.League) .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
 
if row["Phase"] ~= "" then
 
if row["Phase"] ~= "" then
 
tdEvent:wikitext(" - " .. row["Phase"])
 
tdEvent:wikitext(" - " .. row["Phase"])
Line 194: Line 211:
 
local cargojoin = 'TournamentRosters._pageName = TournamentResults.RosterPage, TournamentResults._pageName=Tournaments._pageName, TournamentRosters.RosterLinks HOLDS PlayerRedirects.AllName'
 
local cargojoin = 'TournamentRosters._pageName = TournamentResults.RosterPage, TournamentResults._pageName=Tournaments._pageName, TournamentRosters.RosterLinks HOLDS PlayerRedirects.AllName'
 
local cargofields = table.concat(fieldstable,",")
 
local cargofields = table.concat(fieldstable,",")
local cargowhere = 'PlayerRedirects._pageName="' .. player .. '" AND TournamentRosters.UniqueLine = TournamentResults.UniqueLine'
+
local cargowhere = 'PlayerRedirects._pageName="' .. player .. '" AND TournamentRosters.TeamLink = TournamentResults.TeamLink'
 
local cargogroupBy = "TournamentResults.UniqueLine"
 
local cargogroupBy = "TournamentResults.UniqueLine"
 
local cargoorderBy = "TournamentResults.Date desc"
 
local cargoorderBy = "TournamentResults.Date desc"
   
 
if tournamentType and tournamentType ~= '' then
 
if tournamentType and tournamentType ~= '' then
cargowhere = cargowhere .. ' AND Tournaments.Type = "' .. tournamentType .. '" '
+
cargowhere = cargowhere .. ' AND Tournaments.EventType = "' .. tournamentType .. '" '
 
end
 
end
 
if not limit then
 
if not limit then

Revision as of 21:43, 26 June 2020

To edit the documentation or categories for this module, click here.


--local Role = require('Module:Role').role
local Sprite = require('Module:Sprite').sprite

local p = {}
local s = {}

function s.LeagueSprite(id)
	return Sprite{
		id,
		type = 'League'
	}
end

function p.playerResults( frame )
	if frame == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs').norm()
	else
		frame = mw.getCurrentFrame()
	end
	
	local player = args[1] or tostring(mw.title.getCurrentTitle())
	local tournamentType = args.type or ''
	local limit = args[3] or ((args.show == 'everything') and 5000 or 10)
	
	local result = p.load(player, tournamentType, limit)
	
	mw.log(result)
	
	local m_team = require('Module:Team')
	local League = require('Module:League').league
	local placement = mw.loadData('Module:Placementnames')
	local Game = require('Module:Game').game

	local tbl = mw.html.create('table')
	tbl:addClass("wikitable sortable hoverable-rows"):css("font-size","90%")
		:tag("tr")
			:tag("th"):css({ background = "var(--tournament-results-bar)" }):attr("colspan","30")
			:wikitext(player .. ' Tournament Results'):done()
		:done()
		:tag("tr")
			:tag("th"):css("width","60"):wikitext("Game"):done()
			:tag("th"):css("width","60"):wikitext("Date"):done()
			:tag("th"):css("width","60"):wikitext("Place"):done()
			:tag("th"):css("width","80"):wikitext('<abbr title="This prize was won by the team and does not necessarily reflect money earned by the player">Prize</abbr>'):done()
			:tag("th"):css("width","250"):wikitext("Event"):done()
			--:tag("th"):css("width","150"):wikitext("Last Result"):done()
			:tag("th"):css("width","250"):wikitext("Team"):done()
			:tag("th"):wikitext("Roster"):done()
		:done()
	
	local earnings = {}
	
	for _,row in ipairs(result) do
		mw.log('result')
		place = placement[string.lower(row["Place"])] or { bgcolor = "", hiddensort = "", fontcolor = "red", display = "Invalid Placement Name[[Category:Pages With Invalid Placement Names]]" }
		tr = tbl:tag("tr")
		tr:tag('td'):wikitext(Game{row['Game']}):done()
		tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done() -- Need to format this right still
			:tag("td")
				:css({ ["background-color"] = "#" .. place["bgcolor"], color = place["fontcolor"], ["text-align"] = "center" })
				:wikitext('<span style="display:none;">' .. place.hiddensort .. "</span>'''" .. place.display .. "'''")
			:done()
			:tag("td"):wikitext(row["PrizeMarkup"]):done()
		tdEvent = tr:tag("td"):wikitext(s.LeagueSprite(row.League) .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
		if row["Phase"] ~= "" then
			tdEvent:wikitext(" - " .. row["Phase"])
		end 
		tdEvent:wikitext("]]"):done()
		
		tr:tag("td"):wikitext(m_team.rightmediumlinked(row.TeamLink))
		
		teammates = {}
		teammatenames = mw.text.split(row["RosterNames"],",",true)
		teammatelinks = mw.text.split(row["RosterLinks"],",",true)
		roles = mw.text.split(row["Roles"],",",true)
		
		for index,teammatelink in ipairs(teammatelinks) do
			if mw.ustring.lower(teammatelink) == mw.ustring.lower(player--[[row["ThisName"]]) then -- TODO
				teammates[#teammates+1] = (roles[index] or '') .. "&nbsp;'''" .. teammatenames[index] .. "'''"
			else
				teammates[#teammates+1] = (roles[index] or '') .. "&nbsp;[[" .. teammatelink .. "|" .. teammatenames[index] .. "]]"
			end
		end
		tr:tag("td"):wikitext(table.concat(teammates, " &#8226; "))
		
		if row["Prize"] ~= "" then
			earnings[row["PrizeUnit"]] = (earnings[row["PrizeUnit"]] or 0) + tonumber(row["Prize"],10)
		end
		
	end
	
	local td = tbl:tag("tr")
		:tag("th"):attr("colspan","30"):wikitext("Total Prize: ")
	
	local earningstable = {}
	
	for currency, amount in pairs(earnings) do
		earningstable[#earningstable+1] = currency .. " " .. mw.getLanguage('en'):formatNum(amount)
	end
	
	td:wikitext(table.concat(earningstable," &#8226; ")):done()
	
	text = tostring(tbl)
	
	frame:callParserFunction{name="#vardefine:hasnewresults",args={"yes"}}
	
	return text
	
end

function p.shortList(frame) 
	if frame == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs').norm()
	else
		frame = mw.getCurrentFrame()
	end
	
	local player = args[1] or tostring(mw.title.getCurrentTitle())
	
	local m_team = require('Module:Team')
	local League = require('Module:League').league
	local placement = mw.loadData('Module:Placementnames')
	local Game = require('Module:Game').game
	
	local result = p.load(player, 'offline', 5)
	
	local tbl = mw.html.create('table')
	tbl:addClass("wikitable sortable hoverable-rows"):css("font-size","90%")
		:tag("tr")
			:tag("th"):css({ background = "var(--tournament-results-bar)" }):attr("colspan","30")
			:wikitext('Recent Tournament Results [[' .. player .. '/Tournament Results|(View All)]]'):done()
		:done()
		:tag("tr")
			:tag("th"):css("width","60"):wikitext("Game"):done()
			:tag("th"):css("width","60"):wikitext("Date"):done()
			:tag("th"):css("width","60"):wikitext("Place"):done()
			:tag("th"):css("width","80"):wikitext('<abbr title="This prize was won by the team and does not necessarily reflect money earned by the player">Prize</abbr>'):done()
			:tag("th"):css("width","250"):wikitext("Event"):done()
			--:tag("th"):css("width","150"):wikitext("Last Result"):done()
			:tag("th"):css("width","250"):wikitext("Team"):done()
			--:tag("th"):wikitext("Roster"):done()
		:done()
	
	local earnings = {}

	for _,row in ipairs(result) do
		mw.log('result')
		place = placement[string.lower(row["Place"])] or { bgcolor = "", hiddensort = "", fontcolor = "red", display = "Invalid Placement Name[[Category:Pages With Invalid Placement Names]]" }
		tr = tbl:tag("tr")
		tr:tag('td'):wikitext(Game{row['Game']}):done()
		tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done() -- Need to format this right still
			:tag("td")
				:css({ ["background-color"] = "#" .. place["bgcolor"], color = place["fontcolor"], ["text-align"] = "center" })
				:wikitext('<span style="display:none;">' .. place.hiddensort .. "</span>'''" .. place.display .. "'''")
			:done()
			:tag("td"):wikitext(row["PrizeMarkup"]):done()
		tdEvent = tr:tag("td"):wikitext(s.LeagueSprite(row.League) .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
		if row["Phase"] ~= "" then
			tdEvent:wikitext(" - " .. row["Phase"])
		end 
		tdEvent:wikitext("]]"):done()
			
		tr:tag("td"):wikitext(m_team.rightshortlinked(row.TeamLink))
		
		if row["Prize"] ~= "" then
			earnings[row["PrizeUnit"]] = (earnings[row["PrizeUnit"]] or 0) + tonumber(row["Prize"],10)
		end
		
	end
	
	local td = tbl:tag("tr")
		--:tag("th"):attr("colspan","30"):wikitext("Total Prize: ")
	
	local earningstable = {}
	
	td:wikitext(table.concat(earningstable," &#8226; ")):done()
	
	text = tostring(tbl)
	
	frame:callParserFunction{name="#vardefine:hasnewresults",args={"yes"}}
	
	return text
		
end

function p.load(player, tournamentType, limit) 
	local fieldstable = {
		"TournamentResults.TeamLink=TeamLink",
		"TournamentResults.Prize_Markup=PrizeMarkup",
		"TournamentResults.PrizeOther=PrizeOther",
		"TournamentResults.Prize=Prize",
		"TournamentResults.PrizeUnit=PrizeUnit",
		"TournamentResults.Date=Date",
		"TournamentResults.Place=Place",
		"TournamentResults.Event=Event",
		"TournamentResults.Phase=Phase",
		"CONCAT(TournamentResults._pageName)=EventLink",
		"TournamentRosters.RosterLinks__full=RosterLinks",
		"TournamentRosters.Roster=RosterNames",
		'TournamentRosters.Roster_Linked=Roster',
		"TournamentRosters.Roles=Role",
		"TournamentRosters.Roles_Markup=Roles",
		--"TournamentResults.LastResult=LastResult",
		--"TournamentResults.LastOpponent_Markup=LastOpponent",
		"Tournaments.League=League",
		'Tournaments.Game=Game',
		"CONCAT(PlayerRedirects.AllName)=ThisName",
	}
	
	local cargotables = "TournamentRosters, TournamentResults, Tournaments, PlayerRedirects"
	local cargojoin = 'TournamentRosters._pageName = TournamentResults.RosterPage, TournamentResults._pageName=Tournaments._pageName, TournamentRosters.RosterLinks HOLDS PlayerRedirects.AllName'
	local cargofields = table.concat(fieldstable,",")
	local cargowhere = 'PlayerRedirects._pageName="' .. player .. '" AND TournamentRosters.TeamLink = TournamentResults.TeamLink'
	local cargogroupBy = "TournamentResults.UniqueLine"
	local cargoorderBy = "TournamentResults.Date desc"

	if tournamentType and tournamentType ~= '' then 
		cargowhere = cargowhere .. ' AND Tournaments.EventType = "' .. tournamentType .. '" '
	end 
	if not limit then
		limit = 5000
	end 
	
	local cargoquery = { where = cargowhere, join = cargojoin, orderBy = cargoorderBy, groupBy=cargogroupBy, limit=limit }
	local result = mw.ext.cargo.query(cargotables, cargofields, cargoquery)
	mw.log('return result')
	mw.log(result)
	
	return result
end

return p