Module:GroupTableLeague/dota2

--Differences from main branch (as of July 19 2020) (function p.get) --Team and alias names are set with 'resolve_redirect'

local p = {} -- p stands for package

function p.formatDate(date, format) local month,day,year,time=date:match('^(%a+)%s(%d+),?%s?(%d*)%s?-?%s?(.-)$') if time and time ~= '' then local hour,min,timezone=time:match('^(%d+):(%d+)%D-([+-]?%d+:%d+)') return mw.language.getContentLanguage:formatDate( format or 'r', month .. '-' .. day .. ', ' .. year .. ' ' .. hour .. ':' .. min .. (timezone or '')) elseif year and year ~= '' then return mw.language.getContentLanguage:formatDate( format or 'r', month .. '-' .. day .. ', ' .. year ) else return mw.language.getContentLanguage:formatDate( format or 'r', date) or date end end

function p.get_lpdb_results(args, tournaments) local lpdb_conditions = '('  	if tournaments then		for key, item in ipairs(tournaments) do			if (key > 1) then				lpdb_conditions = lpdb_conditions .. ' OR '			end			lpdb_conditions = lpdb_conditions .. 'pagename::' .. item .. 		end	else   		lpdb_conditions = lpdb_conditions .. 'pagename::' .. args.tournament ..   	end        lpdb_conditions = lpdb_conditions .. ') ' local date_condition = '' if (args.sdate) and args.sdate ~= '' then date_condition = date_condition .. 'AND (date::>' .. p.formatDate(args.sdate) .. ' OR date::' .. p.formatDate(args.sdate) .. ')' end if (args.edate) and args.edate ~= '' then date_condition = date_condition .. 'AND (date::<' .. p.formatDate(args.edate) .. ' OR date::' .. p.formatDate(args.edate) .. ')' end local output = mw.ext.LiquipediaDB.lpdb('match', {		limit = 1000,		offset = 0,		order = 'date asc',		conditions = lpdb_conditions .. date_condition	})

return output, lpdb_conditions end

function p.get_smw_results(frame, tournaments)

local smw_conditions = '[[-has subobject::'

if tournaments then for key, item in ipairs(tournaments) do			if (key > 1) then smw_conditions = smw_conditions .. '||'			end smw_conditions = smw_conditions .. item end else smw_conditions = smw_conditions .. frame.args.tournament end

smw_conditions = smw_conditions .. ']] has team left crosstable::+ has team right crosstable::+' if (frame.args.sdate) and frame.args.sdate ~= '' then smw_conditions = smw_conditions .. ' has map date::>' .. p.formatDate(frame.args.sdate) .. '' end if (frame.args.edate) and frame.args.edate ~= '' then smw_conditions = smw_conditions .. ' has map date::<' .. p.formatDate(frame.args.edate) .. '' end smw_conditions = smw_conditions .. '|?has team left crosstable=opponent1|?has team right crosstable=opponent2|?has team left score=opponent1score|?has team right score=opponent2score|?is finished=finished|?has walkover winner=walkover|?has winner=winner|mainlabel=page|limit=1000' local queryResult = mw.smw.getQueryResult( smw_conditions ) local output = {} if type( queryResult ) == "table" then for key,item in pairs( queryResult.results ) do	 		table.insert(output, {		  		opponent1 = item.printouts.opponent1[1],		  		opponent2 = item.printouts.opponent2[1],		  		opponent1score = item.printouts.opponent1score[1],		  		opponent2score = item.printouts.opponent2score[1],		  		finished = item.printouts.finished[1],		  		winner = item.printouts.winner[1],		  		walkover = item.printouts.walkover[1]		  	}) end end return output end

function p.resolve_ties(args, teamlist, results, lpdb_conditions, date)

function get_disqualified(team) return team.disqualified and 0 or 1 end

function get_points(team) return team.tiebreaker*30 + team.points end function get_diff(team) return team.tiebreaker*30 + team.diff end function get_series(team) return team.tiebreaker*30 + team.series.won - 0.1 * team.series.loss end function get_series_percentage(team) if team.series.won + team.series.loss + team.series.tied == 0 then return team.tiebreaker*30 + 0.5 else return team.tiebreaker*30 + team.series.won / (team.series.won + team.series.loss + team.series.tied) end end function get_series_diff(team) return team.tiebreaker*30 + team.series.won - team.series.loss end function get_games_won(team) return team.tiebreaker*30 + team.games.won end function get_games_loss(team) return team.tiebreaker*30 - 0.1 * team.games.loss end function get_h2h_series(results, start_index, end_index, lpdb_conditions) for i = start_index, end_index do	 		results[i].tiebreaker = results[i].tiebreaker*30 end for team1_index = start_index, end_index-1 do	 		for team2_index = team1_index+1, end_index do				-- team1 vs team2 local match = mw.ext.LiquipediaDB.lpdb('match', {					limit = 1000,					offset = 0,					order = 'date asc',					conditions = lpdb_conditions .. ' AND opponent1::' .. results[team1_index].team .. ' AND opponent2::' .. results[team2_index].team .. ''				}) for key, item in ipairs(match) do		 			if item.winner == '1' or item.walkover == '1' then results[team1_index].tiebreaker = results[team1_index].tiebreaker + tonumber(item.opponent1score) - 0.01 * tonumber(item.opponent2score) elseif item.winner == '2' or item.walkover == '2' then results[team2_index].tiebreaker = results[team2_index].tiebreaker + tonumber(item.opponent2score) - 0.01 * tonumber(item.opponent1score) end end -- team2 vs team1 local match = mw.ext.LiquipediaDB.lpdb('match', {					limit = 1000,					offset = 0,					order = 'date asc',					conditions = lpdb_conditions .. ' AND opponent1::' .. results[team2_index].team .. ' AND opponent2::' .. results[team1_index].team .. ''				}) for key, item in ipairs(match) do		 			if item.winner == '2' or item.walkover == '2' then results[team1_index].tiebreaker = results[team1_index].tiebreaker + tonumber(item.opponent2score) - 0.01 * tonumber(item.opponent1score) elseif item.winner == '1' or item.walkover == '1' then results[team2_index].tiebreaker = results[team2_index].tiebreaker + tonumber(item.opponent1score) - 0.01 * tonumber(item.opponent2score) end end end end end function get_h2h_games(results, start_index, end_index, lpdb_conditions) for i = start_index, end_index do	 		results[i].tiebreaker = results[i].tiebreaker*30 end for team1_index = start_index, end_index-1 do	 		for team2_index = team1_index+1, end_index do				-- team1 vs team2 local match = mw.ext.LiquipediaDB.lpdb('match', {					limit = 1000,					offset = 0,					order = 'date asc',					conditions = lpdb_conditions .. ' AND opponent1::' .. results[team1_index].team .. ' AND opponent2::' .. results[team2_index].team .. ''				}) for key, item in ipairs(match) do					results[team1_index].tiebreaker = results[team1_index].tiebreaker + tonumber(item.opponent1score) - 0.01 * tonumber(item.opponent2score) results[team2_index].tiebreaker = results[team2_index].tiebreaker + tonumber(item.opponent2score) - 0.01 * tonumber(item.opponent1score) end -- team2 vs team1 local match = mw.ext.LiquipediaDB.lpdb('match', {					limit = 1000,					offset = 0,					order = 'date asc',					conditions = lpdb_conditions .. ' AND opponent1::' .. results[team2_index].team .. ' AND opponent2::' .. results[team1_index].team .. ''				}) for key, item in ipairs(match) do					results[team1_index].tiebreaker = results[team1_index].tiebreaker + tonumber(item.opponent2score) - 0.01 * tonumber(item.opponent1score) results[team2_index].tiebreaker = results[team2_index].tiebreaker + tonumber(item.opponent1score) - 0.01 * tonumber(item.opponent2score) end end end end function get_temp_ties(team) return team.tiebreaker*30 + (team.temp.tiebreaker or 0) end local tiebreakers = {} for i = 1,10 do local key = args['tiebreaker' .. tostring(i)] or '' if key == 'points' or key == 'pts' then table.insert(tiebreakers, get_points) elseif key == 'series' then table.insert(tiebreakers, get_series) elseif key == 'series percentage' or key == 'series%' or key == 'series-percentage' then table.insert(tiebreakers, get_series_percentage) elseif key == 'series diff' then table.insert(tiebreakers, get_series_diff) elseif key == 'diff' then table.insert(tiebreakers, get_diff) elseif key == 'games won' then table.insert(tiebreakers, get_games_won) elseif key == 'games loss' then table.insert(tiebreakers, get_games_loss) elseif key == 'h2h series' or key == 'head-to-head series' or key == 'head to head series' then table.insert(tiebreakers, get_h2h_series) elseif key == 'h2h games' or key == 'head-to-head games' or key == 'head to head games' then table.insert(tiebreakers, get_h2h_games) end end if not next(tiebreakers) then if args.show_p == 'true' then tiebreakers = { get_points, get_series, get_diff, get_h2h_series, get_h2h_games, get_games_won, get_games_loss }	 	else tiebreakers = { get_series, get_diff, get_h2h_series, get_h2h_games, get_games_won, get_games_loss }	 	end end table.insert(tiebreakers, 1, get_disqualified) table.insert(tiebreakers, get_temp_ties) local ties_resolved = false local tiebreaker_index = 1 local lpdb_conditions = lpdb_conditions .. ' AND (date::<' .. date .. ' OR date::' .. date .. ')'

repeat local start_index, end_index = 1, 1 repeat while (end_index < #teamlist and results[end_index].tiebreaker == results[end_index+1].tiebreaker) do	 			end_index = end_index + 1 end -- calculate tiebreaker value for each tied team local tied_rankings = {} if end_index - start_index > 0 then if tiebreakers[tiebreaker_index] == get_h2h_series or tiebreakers[tiebreaker_index] == get_h2h_games then if (end_index - start_index <= 2) then tiebreakers[tiebreaker_index](results, start_index, end_index, lpdb_conditions) end for i = start_index, end_index do						table.insert(tied_rankings, results[i]) end else for i = start_index, end_index do						results[i].tiebreaker = tiebreakers[tiebreaker_index](results[i]) table.insert(tied_rankings, results[i]) end end table.sort(tied_rankings, function(item1, item2) return 					item1.tiebreaker > item2.tiebreaker or (item1.tiebreaker == item2.tiebreaker and string.lower(item1.team) < string.lower(item2.team)) end) for i = start_index, end_index do					results[i] = tied_rankings[ i - start_index + 1 ] end end end_index = end_index + 1 start_index = end_index until (end_index > #teamlist) tiebreaker_index = tiebreaker_index + 1 if (tiebreaker_index > 2 and start_index == 1 and end_index == #teamlist) then ties_resolved = true end until (tiebreaker_index > #tiebreakers or ties_resolved == true) -- update teamlist to match results for key, item in ipairs(results) do		teamlist[item.team] = key end end

function p.get(frame, args, data) local divWrapper local lpdb_conditions local teamlist, aliaslist = {}, {} local results = {} local tournaments = {} local custom_points = {} local rounds = {} local round_no = 1 if not getArgs then getArgs = require('Module:Arguments').getArgs end args = getArgs(frame) -- parse parameters tournamentX and teamX and X-X_p for key, item in pairs(args) do		if item == '' or item == '\n' then args[key] = nil end if type(key) == 'string' and item ~= '' then -- tournamentX if key:match('^tournament(%d*)$') then table.insert(tournaments, (mw.ext.TeamLiquidIntegration.resolve_redirect(item):gsub('%s','_')) ) end -- paramX associated with teamX if key:match('^r?o?u?n?d?%d-([^%d]*%d*)$') then local round_index, param, team_index = key:match('^r?o?u?n?d?(%d-)([^%d]*)(%d*)$') if round_index == '' then round_index = 0 end round_index, team_index = tonumber(round_index), tonumber(team_index) if not rounds[round_index] then rounds[round_index] = { date = today_date, temp = { series = { won = {}, tied = {}, loss = {}, },						 	games = { won = {}, loss = {}, },						 	points = {}, tiebreaker = {}, diff = {} },						params = { disqualified = {}, bg = {} }		 			}				end -- teamX if param == 'team' then local team_name, has_no_page = safeExpand(frame, 'TeamPage', {item:lower}) if has_no_page then mw.log('No for: ', item) team_name = safeExpand(frame, 'TeamName', { item:lower }) end if string.lower(team_name) ~= 'tbd' then team_name = mw.ext.TeamLiquidIntegration.resolve_redirect(team_name) end teamlist[team_index] = {team = team_name, team_arg = item} teamlist[team_name] = team_index for alias in mw.text.gsplit(args['team' .. team_index .. 'alias'] or , ",") do						if alias ~=  then local alias_name, has_no_page = safeExpand(frame, 'TeamPage', {alias:lower}) if has_no_page then mw.log('No for alias: ', alias) alias_name = safeExpand(frame, 'TeamName', { alias:lower }) end if alias_name ~= '' then alias_name = mw.ext.TeamLiquidIntegration.resolve_redirect(alias_name) mw.log('Alias team', team_index, alias_name) aliaslist[alias_name] = team_name end end end -- rNdateX elseif param == 'edate' or param == 'date' then rounds[round_index].date = tonumber(p.formatDate(item, 'U')) -- rNbgX elseif param == 'bg' then rounds[round_index].params.bg[team_index] = item -- temp_pX elseif param == 'temp_p' and team_index then rounds[round_index].temp.points[team_index] = item

-- temp_tieX elseif param == 'temp_tie' and team_index then rounds[round_index].temp.tiebreaker[team_index] = item

-- temp_diffX elseif param == 'temp_diff' and team_index then rounds[round_index].temp.diff[team_index] = item

-- temp_win_mX elseif param == 'temp_win_m' and team_index then rounds[round_index].temp.series.won[team_index] = item elseif param == 'temp_tie_m' and team_index then rounds[round_index].temp.series.tied[team_index] = item elseif param == 'temp_lose_m' and team_index then rounds[round_index].temp.series.loss[team_index] = item elseif param == 'temp_win_g' and team_index then rounds[round_index].temp.games.won[team_index] = item elseif param == 'temp_lose_g' and team_index then rounds[round_index].temp.games.loss[team_index] = item

-- dqX elseif (param == 'dq' or param == 'q') and team_index and item == 'true' then -- TODO: param == 'q' is a temporary fix, resolve it correctly rounds[round_index].params.disqualified[team_index] = true end -- X-Y_p elseif key:match('^(%d+-%d+)_p$') then table.insert(custom_points, {score1 = key:match('^(%d+)-%d+_p'), score2 = key:match('^%d+-(%d+)_p'), points = item}) end end end mw.log('Manual round inputs: ', #rounds) -- parse parameters args.win_p = tonumber(args.win_p) or 3 args.tie_p = tonumber(args.tie_p) or 1 args.lose_p = tonumber(args.lose_p) or 0 args.walkover_win = tonumber(args.walkover_win) or 0 args.ties = args.ties or 'false' args.show_p = args.show_p or 'false' args.diff = args.diff or 'true' args.show_g = args.show_g or 'true' args.exclusive = args.exclusive or 'true' args.roundtitle = args.roundtitle or 'Round' args.roundwidth = tonumber(args.roundwidth) or 90

if not next(tournaments) then tournaments[1] = string.gsub(mw.title.getCurrentTitle.text,'%s','_') end --=  	if not data then data, lpdb_conditions = p.get_lpdb_results(args, tournaments) end if type(data) == 'table' then -- final date table.sort(rounds, function(item1, item2) return item1.date < item2.date end) local is_mid_tournament = false local today_date = tonumber(os.date("%s")) local last_date = args.edate and tonumber(p.formatDate(args.edate, 'U')) or today_date if next(data) then for key, item in ipairs(rounds) do				if item.date > today_date then if is_mid_tournament == true then rounds[key] = nil else is_mid_tournament = true end elseif item.date > last_date then rounds[key] = nil end end end if last_date > today_date then is_mid_tournament = true mw.log('is_mid_tournament: ', is_mid_tournament) end if not(rounds[1]) or (rounds[#rounds].date < last_date) then if rounds[0] then rounds[0].date = args.edate and tonumber(p.formatDate(args.edate, 'U')) or today_date rounds[(#rounds or 0)+1] = rounds[0] else rounds[(#rounds or 0)+1] = { date = today_date, temp = { series = { won = {}, tied = {}, loss = {}, },						games = { won = {}, loss = {}, },						points = {}, tiebreaker = {}, diff = {} },					params = { disqualified = {}, bg = {} }				}		 	end end -- create table local class = 'wikitable wikitable-bordered grouptable' if (args.hide == 'true') then class = class .. 'collapsible collapsed' elseif (args.hide == 'false') then class = class .. 'collapsible' elseif (args.hide) then class = class .. args.hide end divWrapper = mw.html.create('div') :addClass('table-responsive toggle-area toggle-area-' .. tostring(#rounds)) :attr('data-toggle-area',tostring(#rounds)) :css('padding-bottom', tostring(#rounds * 27) .. 'px') :css('margin-bottom', -tostring(#rounds * 27) .. 'px') output = divWrapper:tag('table') :addClass(class) :css('width', args.width or '300px') :css('margin','0px') local dropdownWrapper = mw.html.create('div') :addClass('dropdown-box-wrapper') :css('float','left') dropdownWrapper:tag('span') :addClass('dropdown-box-button btn btn-primary') :css('width',args.roundwidth .. 'px') :css('padding-top', '2px') :css('padding-bottom', '2px') :wikitext((is_mid_tournament == true and 'Current' or args.roundtitle .. ' ' .. tostring(#rounds)) .. ' ') if #rounds <= 1 then dropdownWrapper:css('display','none') end local dropdownButton = dropdownWrapper:tag('div') :addClass('dropdown-box') :css('padding','0px') for i=1,#rounds do	 		if (i == #rounds) and (is_mid_tournament == true) then buttonText = 'Current' else buttonText = args.roundtitle .. ' ' .. tostring(i) end mw.log(buttonText) dropdownButton:tag('div') :addClass('toggle-area-button btn btn-primary') :attr('data-toggle-area-btn',tostring(i)) :css('width',args.roundwidth .. 'px') :css('padding-top', '2px') :css('padding-bottom', '2px') :wikitext( buttonText) end local title = mw.html.create('span') :wikitext(args.title or mw.title.getCurrentTitle.text) if #rounds > 1 then title:css('margin-left', '-70px') :css('vertical-align','middle') end local header = output:tag('tr') header:tag('th') :attr('colspan', args.colspan or '7') :wikitext(tostring(title) .. tostring(dropdownWrapper)) -- get list of unique teams if no set teams if not next(teamlist) then for key, item in ipairs(data) do				if not teamlist[item.opponent1] then table.insert(teamlist,{team = item.opponent1, team_arg = item.opponent2:lower}) teamlist[item.opponent1] = #teamlist end if not teamlist[item.opponent2] then table.insert(teamlist,{team = item.opponent2, team_arg = item.opponent2:lower}) teamlist[item.opponent2] = #teamlist end end end -- additional team 'discard' for discarded results teamlist[0] = '' -- initialise templates for each team for key = 0,#teamlist do	 		results[key] = { index = key, team = teamlist[key].team or teamlist[key], -- item.team for teamX, item for teams from SMW/LPDB team_arg = teamlist[key].team_arg or teamlist[key], -- item.team_arg for teamX, item for teams from SMW/LPDB team_template = safeExpand(frame,'team', {string.lower(teamlist[key].team_arg or '')}), ranking = 0, ranking_change = 0, tiebreaker = 0, -- score used to determine ranking between players points = 0, custom_points = 0, diff = 0, series = { won = 0, tied = 0, loss = 0, },				games = { won = 0, loss = 0, },		 		temp = { tiebreaker = 0, points = 0, diff = 0 }			}	 	end -- calculations if not next(data) then p.resolve_ties(args, teamlist, results, lpdb_conditions, today_date) p.printResults(args, header, results, rounds, round_no) end for key, item in ipairs(data) do	 		if aliaslist[item.opponent1] then index1 = teamlist[ aliaslist[item.opponent1] ] else index1 = teamlist[ item.opponent1 ] end if aliaslist[item.opponent2] then index2 = teamlist[ aliaslist[item.opponent2] ] else index2 = teamlist[ item.opponent2 ] end local update = false if (args.exclusive ~= 'false' and index1 and index2) then update = true elseif (args.exclusive == 'false' and (index1 or index2)) then update = true if not index1 then index1 = 0 --discard results elseif not index2 then index2 = 0 --discard results end end if (update == true) then if ((item.finished == '1' or item.finished == 't') and (tonumber(item.opponent1score)>0 or tonumber(item.opponent2score)>0 or item.winner ~=  or item.walkover ~= ) ) then -- add game win/loss if (item.walkover == '1') then results[index1].games.won = results[index1].games.won + args.walkover_win results[index2].games.loss = results[index2].games.loss + args.walkover_win else results[index1].games.won = results[index1].games.won + tonumber(item.opponent1score) results[index1].games.loss = results[index1].games.loss + tonumber(item.opponent2score) end

if (item.walkover == '2') then results[index2].games.won = results[index2].games.won + args.walkover_win results[index1].games.loss = results[index1].games.loss + args.walkover_win else results[index2].games.won = results[index2].games.won + tonumber(item.opponent2score) results[index2].games.loss = results[index2].games.loss + tonumber(item.opponent1score) end -- add series win/loss if (item.winner == '1' or item.walkover == '1') then results[index1].series.won = results[index1].series.won + 1 results[index2].series.loss = results[index2].series.loss + 1 elseif (item.winner == '2' or item.walkover == '2') then results[index1].series.loss = results[index1].series.loss + 1 results[index2].series.won = results[index2].series.won + 1 elseif (item.opponent1score == item.opponent2score) then results[index1].series.tied = results[index1].series.tied + 1 results[index2].series.tied = results[index2].series.tied + 1 args.ties = 'true' end -- add points based on series score for key_p, item_p in pairs(custom_points) do						if (item.opponent1score == item_p.score1 and item.opponent2score == item_p.score2) then results[index1].custom_points = results[index1].custom_points + tonumber(item_p.points) end if (item.opponent2score == item_p.score1 and item.opponent1score == item_p.score2) then results[index2].custom_points = results[index2].custom_points + tonumber(item_p.points) end end end end if key == #data or tonumber(p.formatDate(data[key+1].date, 'U')) > rounds[round_no].date then for i=1,#teamlist do					team_index = results[i].index results[i].series.won = results[i].series.won + (rounds[round_no].temp.series.won[team_index] or 0) results[i].series.tied = results[i].series.tied + (rounds[round_no].temp.series.tied[team_index] or 0) results[i].series.loss = results[i].series.loss + (rounds[round_no].temp.series.loss[team_index] or 0) results[i].games.won = results[i].games.won + (rounds[round_no].temp.games.won[team_index] or 0) results[i].games.loss = results[i].games.loss + (rounds[round_no].temp.games.loss[team_index] or 0) results[i].temp.points = results[i].temp.points + (rounds[round_no].temp.points[team_index] or 0) results[i].points = results[i].temp.points + results[i].custom_points + args.win_p * results[i].series.won + args.tie_p * results[i].series.tied + args.lose_p * results[i].series.loss results[i].temp.diff = results[i].temp.diff + (rounds[round_no].temp.diff[team_index] or 0) results[i].diff = results[i].temp.diff + results[i].games.won - results[i].games.loss results[i].temp.tiebreaker = results[i].temp.tiebreaker + (rounds[round_no].temp.tiebreaker[team_index] or 0) if rounds[round_no].params.bg[team_index] then results[i].bg = rounds[round_no].params.bg[team_index] end if rounds[round_no].params.disqualified[team_index] then results[i].disqualified = rounds[round_no].params.disqualified[team_index] end end -- tiebreakers p.resolve_ties(args, teamlist, results, lpdb_conditions, rounds[round_no].date) -- update rankings local rank = 1 for key, item in ipairs(results) do					if item.ranking ~= 0 and item.ranking ~= rank and type(item.ranking) == 'number' then item.ranking_change = item.ranking - rank else item.ranking_change = 0 end if (item.disqualified == true) then item.ranking = 'DQ' elseif (item.series.won + item.series.tied + item.series.loss ~= 0) then -- if they've played any matches, show a ranking item.ranking = rank end if (key == #results or results[key+1].tiebreaker ~= results[key].tiebreaker) then rank = key + 1 end item.tiebreaker = 0 end if round_no == #rounds then p.printResults(args, output, results, rounds, round_no, is_mid_tournament) else p.printResults(args, output, results, rounds, round_no) end round_no = round_no + 1 if round_no > #rounds then break; end end end else error(data) end return divWrapper end

function p.printResults(args, output, results, rounds, round_no, is_mid_tournament) for key, item in ipairs(results) do		local row = output:tag('tr') :attr('data-toggle-area-content',round_no) -- Replace with Template:Color on wikis where it exists local bgcolors = { first 		= 'rgb(255,215,57)', second 		= 'rgb(190,190,190)', third		= 'rgb(187,134,68)', fourth		= 'rgb(248,153,107)', byeup 		= 'rgb(232,221,239)', seedup 		= 'rgb(219,237,237)', proceed		= 'rgb(221,244,221)', up 		= 'rgb(221,244,221)', stayup 		= 'rgb(229,244,198)', stay 		= 'rgb(249,240,199)', staydown 	= 'rgb(249,222,199)', drop		= 'rgb(251,223,223)', down 		= 'rgb(251,223,223)', dq		= 'rgb(196,197,211)' }		--		local pbgcolors = {			proceed		= 'rgb(204,255,204)',			up			= 'rgb(204,255,204)',			stayup		= 'rgb(238,255,170)',			stay 		= 'rgb(255,255,153)',			staydown 	= 'rgb(255,221,170)',			drop		= 'rgb(255,204,204)',			down 		= 'rgb(255,204,204)',		 }		--

--local team_index = item.index --local bgcolor = bgcolors[ rounds[round_no].params.bg[team_index] ] or '' local bgcolor = bgcolors[ item.bg ] row:tag('th') :css('width', '28px') --:css('background-color', frame:expandTemplate{ title = 'Color', args = args['pbg' .. key] or args['bg' .. key] }) :css('background-color', bgcolors[args['pbg' .. key]] or bgcolor) :wikitext(item.ranking ~= 0 and (item.ranking .. '.') or '')

local team_colspan = 3 if (args.show_g == 'false') then team_colspan = team_colspan + 1 end if (args.diff == 'false') then team_colspan = team_colspan + 1 end if (args.show_p == 'true') then team_colspan = team_colspan - 1 end

local teamtext = item.team_template if (item.disqualified == true) then teamtext = ' ' .. teamtext .. ' '		end local ranking_change = '' ranking_change = item.ranking_change if ranking_change == 0 then ranking_change = '' elseif ranking_change > 0 then ranking_change = ' &#x25B2;' .. ranking_change .. ' '		else ranking_change = ' &#x25BC;' .. -ranking_change .. ' '		end row:tag('td') :addClass('grouptableslot') :attr('colspan', team_colspan) :attr('align', 'left') --:css('background-color', frame:expandTemplate{ title = 'Color', args['bg' .. key] }) :css('background-color', bgcolor) :wikitext( teamtext .. ranking_change )

local series_score if (args.ties == 'true') then series_score = item.series.won .. '-' .. item.series.tied .. '-' .. item.series.loss else series_score = item.series.won .. '-' .. item.series.loss end row:tag('td') :attr('width', '35px') :attr('align', 'center') :css('white-space', 'pre') :css('background-color', bgcolor) :wikitext('\'\'\ .. series_score .. '\'\'\)

if (args.show_g ~= 'false') then row:tag('td') :attr('width', '35px') :attr('align', 'center') :css('white-space', 'pre') :css('background-color', bgcolor) :wikitext(item.games.won .. '-' .. item.games.loss) end

if (args.diff ~= 'false') then if (item.diff > 0) then item.diff = '+' .. item.diff end if item.has_temp_diff then item.diff = item.diff .. '*'			end row:tag('td') :attr('width', '35px') :attr('align', 'center') :css('white-space', 'pre') :css('background-color', bgcolor) :wikitext('\'\ .. item.diff .. '\'\) end

if (args.show_p == 'true') then row:tag('td') :attr('width', '32px') :attr('align', 'center') :css('white-space', 'pre') :css('background-color', bgcolor) :wikitext('\'\'\ .. item.points .. 'p\'\'\) end end end

function safeExpand(frame, templateTitle, templateArgs) local result, value = pcall(frame.expandTemplate, frame, {title = templateTitle, args = templateArgs}) if result then return value else return  .. templateTitle .. , true end end

return p