Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

To edit the documentation or categories for this module, click here. This module has an i18n file. Click here to edit it.


local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_esports = require('Module:EsportsUtil')
local util_form = require("Module:FormUtil")
local util_html = require('Module:HtmlUtil')
local util_map = require('Module:MapUtil')
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_time = require('Module:TimeUtil')
local util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local COLUMNS = { 'Date', 'Event', 'Round', 'Team1', 'Team2', 'Score', 'Vods', 'PBP', 'Color' }
local LIMIT = 10
local MAX_GAMES_PER_SERIES = 5

local h = {}

local p = {}
function p.main(frame)
	local args = util_args.merge()
	i18n.init('CastingHistory')
	h.castArgs(args)
	h.setLimit(args)
	local caster = h.getAndSetCaster(args)
	local data = h.makeAndRunQuery(caster, args)
	util_map.rowsInPlace(data, h.processRow)
	return h.makeIntro(args), h.makeTable(data, caster, args)
end

function h.castArgs(args)
	args.limit = args.limit and tonumber(args.limit)
end

function h.setLimit(args)
	LIMIT = args.limit or LIMIT
end

function h.getAndSetCaster(args)
	args[1] = args[1] or mw.title.getCurrentTitle().baseText
	return args[1] or mw.title.getCurrentTitle().baseText
end

function h.makeAndRunQuery(caster, args)
	return util_cargo.queryAndCast(h.getQuery(caster, args))
end

function h.getQuery(caster, args)
	local ret = {
		tables = {
			'MatchSchedule=MS',
			'PlayerRedirects=PR',
			'MatchScheduleGame=MSG',
			'Tournaments=T'
		},
		join = {
			'MS.Casters HOLDS PR.AllName',
			'MS.MatchId=MSG.MatchId',
			'MS.OverviewPage=T.OverviewPage'
		},
		fields = {
			'MS.CastersPBP=PBP',
			'MS.CastersColor=Color',
			'MS.DateTime_UTC=Date',
			'MS.Team1 [team]',
			'MS.Team2 [team]',
			'MS.Winner [number]',
			'MS.OverviewPage',
			'T.StandardName',
			'COALESCE(MS.Round, MS.Tab)=Round',
			'MS.Team1Score',
			'MS.Team2Score',
			'PR.AllName=ThisName',
			'MS.MatchId', -- one-to-many groupBy field
		},
		where = h.getWhere(caster, args),
		orderBy = 'MS.DateTime_UTC DESC',
		limit = LIMIT,
		rawlimit = LIMIT * MAX_GAMES_PER_SERIES,
		offset = args.offset,
		groupBy = 'MS.MatchId',
		oneToMany = {
			groupBy = {
				'MatchId',
			},
			fields = {
				Vods = {
					'COALESCE(MSG.VodPB, MSG.VodGameStart, MSG.Vod)=Vod',
				}
			}
		},
	}
	return ret
end

function h.getWhere(caster, args)
	local tbl = {
		('PR._pageName="%s"'):format(caster),
		('MSG.MatchId IS NOT NULL'),
	}
	return util_cargo.concatWhere(tbl)
end

function h.processRow(matchRow)
	matchRow.Vods = util_table.concat(matchRow.Vods, '', h.makeVodLink)
	matchRow.Team1 = matchRow.Team1:flair{len='short'}
	matchRow.Team2 = matchRow.Team2:flair{len='short'}
	matchRow.Event = util_text.intLink(matchRow.OverviewPage, matchRow.StandardName)
	matchRow.PBP = util_map.splitAndConcat(matchRow.PBP, nil, util_esports.playerLinkedOrBold, ', ', matchRow.ThisName)
	matchRow.Color = util_map.splitAndConcat(matchRow.Color, nil, util_esports.playerLinkedOrBold, ', ', matchRow.ThisName)
	matchRow.Score = h.makeScore(matchRow)
end

function h.makeVodLink(row)
	return util_text.extLink(row.Vod, row.index) or ''
end

function h.makeScore(row)
	if not row.Team1Score then return 'TBD' end
	return ('%s - %s'):format(row.Team1Score, row.Team2Score)
end

-- output
function h.makeIntro(args)
	local formLink = util_form.fullURL({ form = 'CastingHistory', template = 'CH' }, args)
	return i18n.print('intro', LIMIT, formLink)
end

function h.makeTable(data, caster, args)
	local output = mw.html.create()
	local tbl = output:tag('table')
		:addClass('wikitable')
	h.printHeading(tbl, caster)
	util_html.printRowsByList(tbl, data, COLUMNS)
	return output
end

function h.printHeading(tbl, caster)
	util_html.printColspanHeader(tbl, i18n.print('heading', util_esports.playerLinked(caster)), #COLUMNS)
	util_html.printHeaderFromI18n(tbl, COLUMNS)
end

return p
Advertisement