Module PlayerAutoPointsTable

This Module creates a table that shows the points of players in a point system tournament (using subobjects defined in prizepool templates), this was mainly created for the Astronauts Star Circuit.

Revision 1.0

Player Names are case sensitive

There are 2 different naming conventions used; for arguments provided by the Module invoker, variable with names of multiple words are separated by a dash, for instance 'header-height'; Everything else within this module uses camelCase.

The HTML Library was used to create the html code produced by this Module: https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#HTML_library

Functions

p.main (frame) Entry point.
MandatoryInputArgsExist (args) Checks for mandatory inputs and throws an error if any of them isn't provided.
setUnprovidedArgsToDefault (args) Sets the unprovided arguments to default value.
setGlobalConfig (args) Sets the global configuration variables.
sortData (a, b) Custom sorting function.
fetchTournamentData (args) Fetches the tournament arguments provided.
fetchPlayerData (args, numberOfTournaments) Fetches the players' data.
expandSubTemplates (args) Expands the sub-templates' args.
attachStylingDataToMainData (args, data, players) Attaches styling data.
attachPositionBackgroundColorsToCells (args, data, players) Attaches the position background colors to the main data table.
split (s, delim) Splits string a by a delim.
makeDefaultTableHeaders (frame, tournaments, deductions) Creates the html code required to make the table header.
getTournamentHeaderTitle (tournament) Gets the string that goes in the tournament header cell.
appendDivToLastThreeHeaderCells (headerArgs, columnIndex, columnCount, divWidth) Applies additional special styling for the last three header cell.
makeHeaderCell (frame, headerArgs) Expands the header cell template.
addDeductionArgs (headerArgs, title) Modifies the header arguments for a deduction header cell.
getPlayerPointsData (player, tournaments, deductions) Fetches the points of a player for the given tournaments.
queryPlayerResultsFromSMW (player, tournaments) Performs the required SMW Queries to get the player prize points for all tournaments provided.
linkToName (playerPage) Fetches the player name from the player page string.
getIndexByName (tournaments, tournamentName) Fetches a tournament index from a tournaments table using tournament fullName.
getTournamentPointsString (tournament) Uses default values for tournaments which a player didn't get any points in.
makePointsTable (frame, args, data, tournaments, deductions) Creates the points table in html code.
createTableWrapper (columnCount) Creates the wrapper div which wraps the table node for mobile responsiveness.
createTableTag (tableWrapper) Creates the main table node.
addTableHeader (frame, htmlTable, customHeader, tournaments, deductions) Adds the table header to the points table.
renderTableBody (frame, htmlTable, data) Creates the table body and attaches it to the points table.
styleItem (item, args, c) Styles the background, foreground and font-weight of an element.
renderRow (frame, rowArgs) Renders an html row from row arguments.
makePositionCell (row, rowArgs) Creates the cell which shows the position of the player.
makePlayerCell (frame, row, rowArgs) Creates the cell which shows the flag/name of the player.
makeTotalPointsCell (row, rowArgs) Creates the cell which shows the total number of points of the player.
makeTournamentPointsCell (row, rowArgs, cell, c) Creates the cell which shows the number of points of the player for a single tournament.
makeDeductionPointsCell (frame, row, rowArgs, cell, c) Creates the cell which shows the number of points deducted from a player for a single column.
countEntries (t) Counts the entries in a table.
protectedExpansion (frame, title, args) Safely expands a template.
expandTemplate (frame, title, args) Expands a template.

Tables

tournament a tournament table that represents a single tournament.
playerData a player table contains a single player's information.
prettyResult a table that contains a player's result for a single tournament
playerPoints a table that contains the player data for a single tournament.
cellPlayerData same as playerPoints in addition to cssData.
cssData a table that contains cssData to style the table.


Functions

p.main (frame)
Entry point. This is the entry point of the Module.

Parameters:

  • frame frame

Returns:

    mw.html div tableWrapper
MandatoryInputArgsExist (args)
Checks for mandatory inputs and throws an error if any of them isn't provided.

Parameters:

  • args table the main template arguments

Returns:

    nil
setUnprovidedArgsToDefault (args)
Sets the unprovided arguments to default value.

Parameters:

  • args table the main template arguments

Returns:

    nil
setGlobalConfig (args)
Sets the global configuration variables.

Parameters:

  • args table the main template arguments

Returns:

    nil
sortData (a, b)
Custom sorting function. Sorts the players by their total points then names in-case of a tie.

Parameters:

fetchTournamentData (args)
Fetches the tournament arguments provided. through tournamentX and deductionsX then returns the result in 2 separate tables one for the tournaments and one for the deductions.

Parameters:

  • args table the main template arguments

Returns:

  1. {tournament,...} a table of tournaments
  2. {tournament,...} a table of deductions
fetchPlayerData (args, numberOfTournaments)
Fetches the players' data. Fetches the table of players provided by the main arguments to the template that invokes this module - case sensitive.

Parameters:

  • args table the main template arguments
  • numberOfTournaments number the number of tournaments to check aliases for

Returns:

    table players a table that contains data about players; their name, aliases and point deductions in any of the tournaments
expandSubTemplates (args)
Expands the sub-templates' args. Expands the args provided to any of the sub-templates to the args of the main template changing the keys accordingly.

Parameters:

  • args table the main template arguments

Returns:

    table the arguments after adding the expanded arguments
attachStylingDataToMainData (args, data, players)
Attaches styling data. Attaches the styling data to the main data, uses the players' names to get the corresponding styling data from the main arguments if they exist, then attaches this data to the given data table.

Parameters:

  • args table the main template arguments
  • data playerPoints the data table to which the css data is to be attached
  • players table the table that contains the players data

Returns:

    nil
attachPositionBackgroundColorsToCells (args, data, players)
Attaches the position background colors to the main data table. Attaches the position background colors to the main data table.

Parameters:

Returns:

    nil
split (s, delim)
Splits string a by a delim. Splits string a by a delimiter and returns a table of all resulting words.

Parameters:

Returns:

    {string,...} words a table containing the split up words
makeDefaultTableHeaders (frame, tournaments, deductions)
Creates the html code required to make the table header. This function creates the html code required to make the table header, actually expands another template that contains hard-coded html with some variables, as the headers hardly change.

Parameters:

Returns:

    node row the expanded mw.html table row for the headers
getTournamentHeaderTitle (tournament)
Gets the string that goes in the tournament header cell.

Parameters:

Returns:

    string title
appendDivToLastThreeHeaderCells (headerArgs, columnIndex, columnCount, divWidth)
Applies additional special styling for the last three header cell. This function modifies the original provided header arguments, use with caution.

Parameters:

  • headerArgs table
  • columnIndex number
  • columnCount number
  • divWidth number

Returns:

    table headerArgs the header arguments after modification according to the given index
makeHeaderCell (frame, headerArgs)
Expands the header cell template. Expands the header cell template using the provided arguments.

Parameters:

  • frame frame
  • headerArgs table

Returns:

    string the expanded template
addDeductionArgs (headerArgs, title)
Modifies the header arguments for a deduction header cell. Modifies the header arguments for a deduction header cell, this function modifies the original provided headerArgs, use with caution

Parameters:

  • headerArgs table the original header arguments
  • title string the title to use in the cell header

Returns:

    table headerArgs the header arguments after modification
getPlayerPointsData (player, tournaments, deductions)
Fetches the points of a player for the given tournaments.

Parameters:

Returns:

    playerPoints
queryPlayerResultsFromSMW (player, tournaments)
Performs the required SMW Queries to get the player prize points for all tournaments provided.

Parameters:

Returns:

    nil or {prettyResult,...} prettyResults
linkToName (playerPage)
Fetches the player name from the player page string.

Parameters:

Returns:

    string playerName
getIndexByName (tournaments, tournamentName)
Fetches a tournament index from a tournaments table using tournament fullName.

Parameters:

Returns:

    nil or number tournamentIndex
getTournamentPointsString (tournament)
Uses default values for tournaments which a player didn't get any points in.

Parameters:

Returns:

    string tournamentPointsString
makePointsTable (frame, args, data, tournaments, deductions)
Creates the points table in html code.

Parameters:

  • frame frame
  • args table the main template arguments
  • data {{cellPlayerData,...},...} the data table that contains the player's data
  • tournaments tournament a table that contains the tournaments data
  • deductions tournament a table that contains the deduction columns' data

Returns:

    node tableWrapper the node of the parent div which wraps the table node, this node contains all the html that renders the table
createTableWrapper (columnCount)
Creates the wrapper div which wraps the table node for mobile responsiveness.

Parameters:

  • columnCount number - the number of tournament columns

Returns:

    node div - the secondary wrapper which wraps the table and is wrapped inside the primary wrapper, the primary wrapper is the wrapper which should be returned by the main fucntion
createTableTag (tableWrapper)
Creates the main table node.

Parameters:

  • tableWrapper node - the node which wraps this table node

Returns:

    node htmlTable
addTableHeader (frame, htmlTable, customHeader, tournaments, deductions)
Adds the table header to the points table.

Parameters:

Returns:

    nil
renderTableBody (frame, htmlTable, data)
Creates the table body and attaches it to the points table.

Parameters:

  • frame frame
  • htmlTable node
  • data table

Returns:

    nil
styleItem (item, args, c)
Styles the background, foreground and font-weight of an element.

Parameters:

  • item node mw.html object
  • args cssData css styling arguments
  • c number the column number

Returns:

    node item the item after applying the styling rules
renderRow (frame, rowArgs)
Renders an html row from row arguments.

Parameters:

Returns:

    mw.html tr - table row represented by an mw.html object
makePositionCell (row, rowArgs)
Creates the cell which shows the position of the player.

Parameters:

Returns:

    nil
makePlayerCell (frame, row, rowArgs)
Creates the cell which shows the flag/name of the player.

Parameters:

Returns:

    nil
makeTotalPointsCell (row, rowArgs)
Creates the cell which shows the total number of points of the player.

Parameters:

Returns:

    nil
makeTournamentPointsCell (row, rowArgs, cell, c)
Creates the cell which shows the number of points of the player for a single tournament.

Parameters:

Returns:

    nil
makeDeductionPointsCell (frame, row, rowArgs, cell, c)
Creates the cell which shows the number of points deducted from a player for a single column.

Parameters:

  • frame frame
  • row node the mw.html row node to add the cell to
  • rowArgs {cellPlayerData,...}
  • cell cellPlayerData
  • c number the index of the column counting from the position cell as 1

Returns:

    nil
countEntries (t)
Counts the entries in a table.

Parameters:

Returns:

    number count - the number of keys in the table
protectedExpansion (frame, title, args)
Safely expands a template. Expands a template while making sure a missing template doesn't stop the code execution.

Parameters:

Returns:

    string the expansion if exists, else error message
expandTemplate (frame, title, args)
Expands a template. Expands a template using a frame and returns the result of the expansion.

Parameters:

Returns:

    string the expanded template

Tables

tournament
a tournament table that represents a single tournament.

Fields:

  • index number the index of the tournament as provided in main template arguments
  • fullName string the full name of the tournament as mentioned in the infobox
  • shortName string the tourname name which shows up in the table header
  • link string the link to the tournament page
  • type string the type of the tournament - 'tournament' or 'deduction'
  • finished boolean
playerData
a player table contains a single player's information.

Fields:

  • name string the name of the player - case sensitive
  • aliasX string the alias of the player for tournament X - case sensitive
  • deductionX number the deduction points for this player in tournament X
  • displayTemplate string the name of the template to use when rendering the player cell
prettyResult
a table that contains a player's result for a single tournament

Fields:

  • tournamentName string
  • playerName string the name of the player during this tournament - accounts for aliases
  • prizepoints number
  • placement string
playerPoints
a table that contains the player data for a single tournament.

Fields:

  • tournament table - a reference to the table (the tournament/deduction) which is represented by this data entry
  • player table - a reference to an player
  • points number - the points of the player in this entry
  • total table - a table containing the total points of this player
cellPlayerData
same as playerPoints in addition to cssData.

Fields:

  • tournament table - a reference to the table (the tournament/deduction) which is represented by this data entry
  • player table - a reference to an player
  • points number - the points of the player in this entry
  • total table - a table containing the total points of this player
  • cssArgs cssData
cssData
a table that contains cssData to style the table.

Fields:

  • bg string backgroud color for the whole row
  • fg string foreground color for the whole row
  • bold string for the whole row
  • bgX string background color for column X
  • fgX string foreground color for column X
  • boldX string bold for column X
generated by LDoc 1.4.6 Last updated 2020-07-19 07:49:31