Scoreboard HTML Configuration - pc2ccs/pc2v9 GitHub Wiki

Overview

As described at Scoreboard Viewing, PC² supports generation of two sets of HTML scoreboard pages: a public set which shows the current standings taking into account any configured "scoreboard freeze period", and a private set which show the current, actual standings ignoring any scoreboard freeze period.

PC² initially generates standings in the form of a hierarchical XML document string, and then uses XSL Transformations (XSLT) to map those standings into various HTML documents. The XSL Transformations which PC² uses to control the mapping from XML standings to formatted HTML are contained in the folder data/xsl under the PC² installation directory. There is one .xsl file in the folder for each of the types of HTML files which PC² generates (actually, more correctly, it is the presence of an XSL file in the data/xsl directory which causes a corresponding HTML file to be generated[1]).

The standard PC² distribution includes .xsl files for the following pages (and hence by default the corresponding .html files will be generated):

  • full, which contains the full standings including rank, team name, number of problems solved, and penalty time, listed in team rank order.
  • fullnums, same as full but also includes the team number in the "name" column.
  • summary, which in addition to the data shown in full also shows per-problem details of attempts and solutions by team.
  • sumatt, a summary of problem attempts and whether or not the problem was solved, ordered by team name (instead of by rank).
  • sumtime, a summary like sumatt but also showing (for solved problems) the time of solution.
  • index, a file containing the same data as summary, but augmented with a contest title, scoreboard status message indicating whether it is a "live" or "frozen" scoreboard, and formatted using embedded CSS stylesheet data.

These files can be replaced by the user with XSLT files specifying any alternative desired transformations. The user can also add additional .xsl files to the data/xsl directory to cause automatic generation of additional HTML files. Each generated HTML file has a name corresponding to a .xsl file in the data/xsl directory, with .html appended as a suffix (replacing the .xsl suffix).

In addition to the .xsl files contained in the data/xsl folder in the standard PC² distribution, there are also various sample .xsl files in the samps/web/xsl folder. These files show additional ways in which XSL Transformations can be used to generate different types of standings output formats.

XML Standings Format

Modifying the XSL Transformations used to generate the output HTML, or adding new XSL Transformation files, requires an understanding of the format of the XML standings string which acts as input to the XSL Transformations. The standings string is a hierarchical XML document tree based on the PC² class XMLMemento, an instance of which is created by class DefaultScoringAlgorithm (which is the class used to generate current standings).

The root of the standings XML document tree is an element named contestStandings. Beneath this root element lies a single child element named standingsHeader, along with multiple child elements, each named teamStanding -- one for each team in the contest (or more correctly, for each team with the displayOnScoreboard property).

The standingsHeader element contains a variety of attributes such as title, scoreboardMessage, systemName, systemVersion, etc.; each of these is initialized to the corresponding appropriate value.

For example, the title field is initialized to the contest title as given in the contest configuration (or to the string "title" if no contest title has been defined); the scoreboardMessage field is initialized to the string "Live (unfrozen) Scoreboard" if the DefaultScoringAlgorithm has been configured to ignore any "scoreboard freeze" period, whereas if DefaultScoringAlgorithm has been told to respect the configured scoreboard freeze period then the scoreboardMessage is initialized to a message like "Scoreboard will be frozen with XXX minutes remaining" or "Scoreboard was frozen with XXX minutes remaining", depending on whether the start of the scoreboard freeze period has been reached.

The attributes and element values in the XML standings string can be accessed by name in XSL transformations. For example the title field in the standingsHeader component of contestStandings can be referenced in XSL using the XSL value-of operator using xsl:value-of select="/contestStandings/standingsHeader/@title"/.

Both standingsHeader element and each teamStanding element contain their own child elements giving additional standings information. See Scoreboard Standings Data Fields for a complete list of all the scoring data fields which can be referenced in an XSL Transformation file.

XSL Transformation Example

The following listings show portions of the default XSL Transformation which maps an XML standings string into the full.html page.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:decimal-format decimal-separator="." grouping-separator="," />

The above specifies that the file contains an XSL stylesheet (xsl:stylesheet) whose form is based on the XML Namespace (xmlns:xsl=...) defined at the specified URL, that the output is to be HTML with indentation and using "period" as the decimal/fractional separator and "comma" as the decimal group separator.

<xsl:template match="contestStandings">
    <HTML>
        <HEAD>
<TITLE>
Full Info - <xsl:value-of select="/contestStandings/standingsHeader/@title"/>
</TITLE>
<META HTTP-EQUIV="EXPIRES" CONTENT="0"/>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"/>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"/>
        </HEAD>

The above specifies the beginning of the HTML document, defining a <HEAD> section containing a <TITLE> line and several HTML <META HTTP> tags. The value for the title is set to be the string "Full Info -" followed by the value of the attribute @title pulled from the contestStandings/standingsHeader element in the contest standings XML string.

        <BODY>
            <TABLE border="0">
                <tr><th><strong><u>Rank</u></strong></th><th><strong><u>Name</u></strong></th><th><strong><u>Solved</u></strong></th><th><strong><u>Time</u></strong></th></tr>
                <xsl:call-template name="teamStanding"/>
            </TABLE>

The above defines the body of the HTML document to be a table with a single table-header row followed by a series table rows each of whose contents is defined by an XSL template named teamStanding (see below).

Created by <A HREF="http://pc2.ecs.csus.edu/">CSUS PC^2 <xsl:value-of select="/contestStandings/standingsHeader/@systemVersion"/></A><br/>
<A HREF="http://pc2.ecs.csus.edu/">http://pc2.ecs.csus.edu/</A><br/>
Last updated
<xsl:value-of select="/contestStandings/standingsHeader/@currentDate"/>
</p>
        </BODY>
    </HTML>

The above completes the HTML document body (and the HTML document) by adding a footer consisting of various data elements pulled from the contestStandings/standingsHeader XML node, including the version of PC² which was used to generate the standings as well as the current date.

</xsl:template>
        <xsl:template name="teamStanding">
            <xsl:for-each select="teamStanding">
                <tr>
                  <td><xsl:value-of select="@rank"/></td>
                  <td><xsl:value-of select="@teamName"/></td>
                  <td align="center"><xsl:value-of select="@solved"/></td>
                  <td align="right"><xsl:value-of select="@points"/></td>
                </tr>
            </xsl:for-each>
        </xsl:template>
</xsl:stylesheet>

The above defines the template for each table data row showing the standings for a single team. The template selects each teamStanding element from the XML tree and displays the value of that team's rank, teamName, solved (total number of problems solved), and points (penalty points) in a table data item in the current row..

Using formatting similar to the above, the user can arrange to have the HTML output generated by PC² to have any desired appearance, simply by replacing the corresponding XSL file in the data/xsl folder with the desired XSL transformation file.



[1] While specification of .xsl files and generation of corresponding HTML pages is the most common usage, PC² will also accept certain other types of XSL Transformation files. For example, the presence in the data/xsl directory of a file whose name ends in .json.xsl will cause PC² to apply XSL Transformations in that file to the standings XML and will produce a corresponding .json file. Similarly, a file whose name ends with .tsv.xsl will translate the XML standings into a .tsv file; a .csv.xsl file will produce a .csv output file; and a .php.xsl file will translate the XML into a .php file. The standard PC² distribution includes in the data/xsl folder an example of such a .php.xsl transformation file.

See Also

⚠️ **GitHub.com Fallback** ⚠️