Module:TeamResultsSolo

local lang = mw.getLanguage('en') local placement = require('Module:Placement') local Team = require('Module:Team').team local League = require('Module:League').league local Role = require('Module:Role').role

local toggles = { showEuros = "_tog_object _toggler_show-Euros _toggler_hide-USD _toggler_hide-Original", showUSD = "_tog_object _toggler_show-USD _toggler_hide-Euros _toggler_hide-Original", showOriginal = "_tog_object _toggler_show-Original _toggler_hide-USD _toggler_hide-Euros", Euros = "_tog_object _toggle Euros", USD = "_tog_object _toggle USD", Original = "_tog_object _toggle Original", initOriginal = "_tog_object _toggle_initshow", initOther = "_tog_object _toggle_inithide" }

local p = {}

function p.makeHeader local Team = require('Module:Team').team local tbl = mw.html.create :tag("tr") :tag("th"):attr("colspan","30") :css({ background = "#E6E6E6", border = "1px solid black" }) :wikitext(Team{team,"teamname"} .. ' Tournament Results - Show Prize as (')			-- toggles to show USD & Euro			:tag('span')				:addClass(toggles.initOriginal):addClass(toggles.Original)				:wikitext('Local')				:wikitext(' &#8226; ')				:tag('span')					:addClass(toggles.showUSD)					:wikitext('USD')				:done				:wikitext(' &#8226; ')				:tag('span')					:addClass(toggles.showEuros)					:wikitext('Euros')				:done			:done			-- toggles to show original & euro			:tag('span')				:addClass(toggles.initOther):addClass(toggles.USD)				:tag('span')					:addClass(toggles.showOriginal)					:wikitext('Local')				:done				:wikitext(' &#8226; ')				:wikitext('USD')				:wikitext(' &#8226; ')				:tag('span')					:addClass(toggles.showEuros)					:wikitext('Euros')				:done			:done			-- toggles to show original & usd			:tag('span')				:addClass(toggles.initOther):addClass(toggles.Euros)				:tag('span') :addClass(toggles.showOriginal) :wikitext('Local') :done :wikitext(' &#8226; ') :tag('span') :addClass(toggles.showUSD) :wikitext('USD') :done :wikitext(' &#8226; ') :wikitext('Euros') :done :wikitext(')')		:done	:done	return tbl end

function p.currencyDisplay(prize, prizeUSD, prizeEuro, prizeMarkup) local tbl = mw.html.create local currencydisplay = {} if prize ~= '' then if prizeUSD ~= '' then currencydisplay.USD = '$ ' .. lang:formatNum(tonumber(prizeUSD)) else currencydisplay.USD = ' ' .. prizeMarkup .. ' '		end if prizeEuro ~= '' then currencydisplay.Euro = '€ ' .. lang:formatNum(tonumber(prizeEuro)) else currencydisplay.Euro = ' ' .. prizeMarkup .. ' '		end end tr:tag("td") :tag('span') :addClass(toggles.Original) :addClass(toggles.initOriginal) :wikitext(prizeMarkup) :done :tag("span") :addClass(toggles.USD) :addClass(toggles.initOther) :wikitext(currencydisplay.USD) :done :tag("span") :addClass(toggles.Euros) :addClass(toggles.initOther) :wikitext(currencydisplay.Euro) :done :done return tbl end

function p.teamResultsSolo( frame ) if frame == mw.getCurrentFrame then args = require( 'Module:ProcessArgs').norm else frame = mw.getCurrentFrame end local team = args[1] or tostring(mw.title.getCurrentTitle) local tbl = mw.html.create('table') local teamlink = Team{team,"teamlinkname"} local earnings = {} local fieldstable = { "TournamentResultsSolos.TeamLink=TeamLink", "TournamentResultsSolos.Prize_Markup=PrizeMarkup", "TournamentResultsSolos.PrizeOther=PrizeOther", "TournamentResultsSolos.Prize=Prize", "TournamentResultsSolos.PrizeUnit=PrizeUnit", "TournamentResultsSolos.Prize_USD=Prize_USD", "TournamentResultsSolos.Prize_Euro=Prize_Euro", "TournamentResultsSolos.Date=Date", "TournamentResultsSolos.Place=Place", "TournamentResultsSolos.Event=Event", "TournamentResultsSolos.Phase=Phase", "CONCAT(TournamentResultsSolos._pageName)=EventLink", "TournamentRostersSolos.RosterLinks__full=RosterLinks", "TournamentRostersSolos.Roster=RosterNames", "TournamentRostersSolos.Roles=Roles", "TournamentResultsSolos.LastResult=LastResult", "TournamentResultsSolos.LastOpponent_Markup=LastOpponent", "Tournaments.League=League", }	local cargotables = "TournamentRostersSolos, TournamentResultsSolos, Tournaments" local cargojoin = "TournamentResultsSolos.RosterPage = TournamentRostersSolos._pageName, TournamentResultsSolos._pageName=Tournaments._pageName" local cargofields = table.concat(fieldstable,",") local cargowhere = 'TournamentResultsSolos.TeamLink="' .. teamlink .. '" AND TournamentRostersSolos.UniqueLine = TournamentResultsSolos.UniqueLine' local cargogroupBy = "TournamentResultsSolos.UniqueLine" local cargoorderBy = "TournamentResultsSolos.Date desc" local cargoquery = { where = cargowhere, join = cargojoin, groupBy = cargogroupBy, orderBy = cargoorderBy } cargoquery.limit = p.getLimit(args.show) local result = mw.ext.cargo.query(cargotables, cargofields, cargoquery) tbl:addClass("wikitable sortable"):css({ ["font-size"] = "90%", ['table-layout'] = 'fixed' }) :node(p.makeHeader) :tag("tr"):css({ visibility = 'collapse' }) :tag('th'):css({ width = '60px' }):done :tag('th'):css({ width = '70px' }):done :tag('th'):css({ width = '100px' }):done :tag('th'):css({ width = '370px' }):done :tag('th'):done :done :tag("tr") :tag("th"):wikitext("Date"):done :tag("th"):wikitext("Place"):done :tag("th"):wikitext("Prize"):done :tag("th"):wikitext("Event"):done :tag("th"):wikitext("Roster"):done :done local totalprizeUSD = 0 local totalprizeEuro = 0 for _,row in ipairs(result) do		tr = tbl:tag("tr") tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done :node(placement.makeNode(row.Place)) :node(p.currencyDisplay(row.Prize,row.Prize_USD,row.Prize_Euro,row.PrizeMarkup)) tdEvent = tr:tag("td"):wikitext(League{row["League"],"onlyimage"} .. " " .. row["Event"])		if row["Phase"] ~= "" then			tdEvent:wikitext(" - " .. row["Phase"])		end 		tdEvent:wikitext(""):done teammates = {} teammatenames = mw.text.split(row["RosterNames"],",") teammatelinks = mw.text.split(row["RosterLinks"],",") roles = mw.text.split(row["Roles"],"%s*;;%s*") if teammatelinks[1] ~= "" then for index,teammatelink in ipairs(teammatelinks) do				thisroles = {} thisrole = table.concat(thisroles,"") teammates[#teammates+1] = thisrole .. " " .. teammatenames[index] .. "" end end tr:tag("td"):wikitext(table.concat(teammates, ", ")) if row["Prize"] ~= "" then earnings[row["PrizeUnit"]] = (earnings[row["PrizeUnit"]] or 0) + tonumber(row["Prize"],10) end tr:done end 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 .. " " .. lang:formatNum(amount) end td:wikitext(table.concat(earningstable," &#8226; ")):done local text = {} text[#text+1] = p.intro(args.show) text[#text+1] = tostring(tbl) local output = table.concat(text,'') return output end

function p.getLimit(show) if show == 'overviewpage' then return 10 elseif show == 'everything' then return 500 end return nil end

function p.intro(show) if show == 'overviewpage' then return string.format(":This table shows up to the 10 most recent results. For complete results, click here.",mw.title.getCurrentTitle.rootText) end return '' end

function p.intro(show) if notitletext == 'yes' then return nil end return '' end

return p