Jump to content

Module:NLL game log

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 09:08, 17 September 2015 (add some more, fix dot/colon typos). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module implements [[Template:NLLGameLog]].

local yesno = require('Module:Yesno')

--[==[
	{{#if: {{{game3_opp|}}}{{{game3_opp_link|}}} |
		<tr align="center" {{#ifexpr: {{{game3_team_score|0}}}+{{{game3_opp_score|0}}} > 0 | {{#ifexpr: {{{game3_team_score|0}}} > {{{game3_opp_score|0}}}| bgcolor="CCFFCC" | bgcolor="FFBBBB" }} }}>
			<td>{{{game3_num|3}}}</td>
			<td>{{date | {{{game3_date}}} | mdy }}</td>
			<td>{{#ifeq: {{{game3_road_game}}} | 1 | @ }} {{#if: {{{game3_opp|}}} | {{#if: {{{game3_opp_link|}}} | [[{{{game3_opp_link}}}|{{{game3_opp}}}]] | {{{game3_opp}}} }} | {{#if: {{{game3_opp_link|}}} | [[{{{game3_opp_link}}}]] }} }}</td>
			<td>{{#ifeq: {{{game3_road_game}}} | 1 | {{#if: {{{game3_loc|}}} | {{#if: {{{game3_loc_link|}}} | [[{{{game3_loc_link}}}|{{{game3_loc}}}]] | {{{game3_loc}}} }} | {{#if: {{{game3_loc_link|}}} | [[{{{game3_loc_link}}}]] }} }} | {{#if: {{{arena|}}} | {{#if: {{{arena_link|}}} | [[{{{arena_link}}}|{{{arena}}}]] | {{{arena}}} }} | {{#if: {{{arena_link|}}} | [[{{{arena_link}}}]] }} }} }}</td>
			{{#ifexpr: {{{game3_team_score|0}}}+{{{game3_opp_score|0}}} <= 0 | <td></td><td></td><td></td><td></td> |
				<td>{{#ifexpr: {{{game3_team_score}}} > {{{game3_opp_score}}}| W | L }} {{{game3_team_score}}}&ndash;{{{game3_opp_score}}}</td>
				<td>{{#ifexpr: {{{game3_ot|0}}} > 0 | {{#ifexpr: {{{game3_ot|0}}} > 1 | {{{game3_ot|0}}} }}OT }}</td>
				<td>{{formatnum: {{{game3_attendance|0}}} }}</td>
				<td>{{#expr: {{#ifexpr: {{{game1_team_score|0}}} > {{{game1_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game2_team_score|0}}} > {{{game2_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game3_team_score|0}}} > {{{game3_opp_score|0}}} | 1 | 0 }} }}&ndash;{{#expr: {{#ifexpr: {{{game1_team_score|0}}} < {{{game1_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game2_team_score|0}}} < {{{game2_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game3_team_score|0}}} < {{{game3_opp_score|0}}} | 1 | 0 }} }}</td>
			}}
		</tr>
	}}
--]==]

--------------------------------------------------------------------------------
-- Game class
--------------------------------------------------------------------------------

local Game = {}
Game.__index = Game

Game.keys = {
	'opp',
	'opp_link',
	'team_score',
	'opp_score',
	'num',
	'date',
	'road_game',
	'loc',
	'loc_link',
	'ot',
	'attendance',
}

function Game.new(data)
	local self = setmetatable({}, Game)

	-- Set properties from arguments
	self.id = data.id
	do
		local prefix = 'game' .. self.id .. '_'
		for i, key in ipairs(Game.keys) do
			self[key] = args[prefix .. key]
		end
	end

	-- Set other properties
	self.arena = data.arena
	self.arena_link = data.arena_link

	-- Abort if we don't have required fields
	if not self.opp and not self.opp_link then
		return nil
	end

	-- Do some simple data preprocessing
	self.road_game = yesno(self.road_game)

	return self
end

function Game:get_number()
	return self.num or self.id
end

function Game:get_team_score()
	return self.team_score or 0
end

function Game:get_opposition_score()
	return self.opp_score or 0
end

function Game:get_goal_difference()
	return self:get_team_score() - self:get_opposition_score()
end

function Game:is_win()
	-- Only record win/loss, as there are no draws in box lacrosse
	return self:get_goal_difference() > 0
end

function Game:get_row_color()
	return self:is_win() and '#ccffcc' or '#ffbbbb'
end

function Game:get_date()
	-- TODO: Convert [[Template:Date]] to Lua and call the module from here.
	local date = self.date or string.format('{{{game%d_date}}}', self.id)
	local frame = mw.getCurrentFrame()
	return frame:expandTemplate{title = 'Date', args = {date, 'mdy'}}
end

function Game:make_link(page, display)
	if display and page then
		return string.format('[[%s|%s]]', page, display)
	elseif display then
		return display
	elseif page then
		return string.format('[[%s]]', page)
	else
		error(
			'no page or display parameters specified in Game:get_date for id ' ..
			tostring(self.id)
		)
	end
end

function Game:make_opponent_link()
	local ret = ''
	if self.road_game then
		ret = ret .. '@ '
	end
	ret = ret .. self:make_link(self.opp_link, self.opp)
	return ret
end

function Game:make_location_link()
	if self.road_game then
		return self:make_link(self.loc_link, self.loc)
	else
		return self:make_link(self.arena_link, self.arena)
	end
end

--------------------------------------------------------------------------------
-- GameLog class
--------------------------------------------------------------------------------

local GameLog = {}
GameLog.__index = GameLog

function GameLog.new(args)
	local self = setmetatable({}, GameLog)
	return self
end

--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------

local p = {}

function p._main(args)
end

function p.main(frame)
end

return p