Skip to content

Commit

Permalink
Capitalized polygon in logging messages, comments and README; fixed d…
Browse files Browse the repository at this point in the history
…omjudge -> DOMjudge
  • Loading branch information
cip999 committed Jan 19, 2023
1 parent 1e5e0d1 commit 6365cab
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 56 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ The whole process is automated: downloading the Polygon package, converting it i
This tool offers the command `p2d`.
Its main features are:

- Download, with a caching mechanism, the most recent Polygon package of a problem through polygon APIs.
- Download, with a caching mechanism, the most recent Polygon package of a problem through Polygon APIs.
- Upload, with a caching mechanism, the converted DOMjudge package of a problem into a DOMjudge server.
- Handling many problems as a contest.
- Convert a Polygon package into a DOMjudge package without human intervention (with the possibility to tweak time and memory limit in the process).
- Generation of the statement (here is an [example of statement](tree/master/examples/statement.pdf)) in pdf with the option to add some custom features to it (e.g., the contest name, a balloon with the color of the problem, time limit and memory limit, etc..). The samples' explanations are [detected from the notes section in polygon through the use of special markers](#samples-explanation-detection).
- Generation of the statement (here is an [example of statement](tree/master/examples/statement.pdf)) in pdf with the option to add some custom features to it (e.g., the contest name, a balloon with the color of the problem, time limit and memory limit, etc..). The samples' explanations are [detected from the notes section in Polygon through the use of special markers](#samples-explanation-detection).
- Generation of a pdf with the complete problem set of a contest featuring a custom front page. Same for the pdf of the solutions of the problems.
- Checkers using testlib.h are supported transparently (by using a modified `testlib.h` which is DOMjudge compatible).
- Through the `Judging verifier` feature of DOMjudge, it enforces that the submissions present in polygon get the correct result also in DOMjudge.
- Through the `Judging verifier` feature of DOMjudge, it enforces that the submissions present in Polygon get the correct result also in DOMjudge.

This project was born as a refactoring of [polygon2domjudge](https://github.com/cubercsl/polygon2domjudge) and evolved into something more.
It was used for [SWERC 2021-2022](https://swerc.eu/2021/about/).
Expand All @@ -39,16 +39,16 @@ Running

```p2d contest_directory --polygon --convert --domjudge --pdf-contest```

downloads the packages of the problems of the contest from polygon, converts them to DOMjudge packages, and uploads them to the DOMjudge server, and generates the pdf of the whole problem set and of the solutions.
The list of the problems, as well as the credentials to access polygon and the DOMjudge server are contained in the configuration file `contest_directory/config.yaml`. The content and the format of `config.yaml` are described in [Structure of config.yaml](#structure-of-configyaml).
downloads the packages of the problems of the contest from Polygon, converts them to DOMjudge packages, and uploads them to the DOMjudge server, and generates the pdf of the whole problem set and of the solutions.
The list of the problems, as well as the credentials to access Polygon and the DOMjudge server are contained in the configuration file `contest_directory/config.yaml`. The content and the format of `config.yaml` are described in [Structure of config.yaml](#structure-of-configyaml).

Let us describe the four, almost independent, fundamental operations that can be performed by `p2d`:

- `--polygon`: For each problem, download its latest valid package from polygon. The package must be a *full* package (and the linux version will be downloaded). A caching mechanism is employed to avoid downloading a package which is already up to date locally.
For this to work, `config.yaml` must contain the credentials to access polygon APIs.
For each problem, the directory `contest_directory/polygon/problem_name/` is generated. Such directory contains the polygon package (extracted) as well as its zip (named `problem_name.zip`).
- `--convert`: For each problem (which was previously, possibly during a different execution, downloaded from polygon), convert it to a DOMjudge package, adding the information needed by DOMjudge but absent in polygon (i.e., the label, the color, the statement in pdf, possibly changing time and memory limit) as described in `config.yaml`. A caching mechanism is employed to avoid converting problems that were converted previously and whose polygon package did not change in the meanwhile.
For each problem, the directory `contest_directory/DOMjudge/problem_name` is generated. Such directory contains the DOMjudge package (extracted) as well as its zip (named `problem_name.zip`).
- `--polygon`: For each problem, download its latest valid package from Polygon. The package must be a *full* package (and the linux version will be downloaded). A caching mechanism is employed to avoid downloading a package which is already up to date locally.
For this to work, `config.yaml` must contain the credentials to access Polygon APIs.
For each problem, the directory `contest_directory/polygon/problem_name/` is generated. Such directory contains the Polygon package (extracted) as well as its zip (named `problem_name.zip`).
- `--convert`: For each problem (which was previously, possibly during a different execution, downloaded from Polygon), convert it to a DOMjudge package, adding the information needed by DOMjudge but absent in Polygon (i.e., the label, the color, the statement in pdf, possibly changing time and memory limit) as described in `config.yaml`. A caching mechanism is employed to avoid converting problems that were converted previously and whose Polygon package did not change in the meanwhile.
For each problem, the directory `contest_directory/domjudge/problem_name` is generated. Such directory contains the DOMjudge package (extracted) as well as its zip (named `problem_name.zip`).
For each problem, also `contest_directory/tex/problem_name-statement.pdf` and `contest_directory/tex/problem_name-solution.pdf` are generated.
- `--domjudge`: For each problem, upload its package to the DOMjudge server. A caching mechanism is employed to avoid uploading a package which is already up to date in the DOMjudge server.
For this to work, `config.yaml` must contain the credentials to access DOMjudge APIs.
Expand Down Expand Up @@ -92,21 +92,21 @@ It must be a valid `yaml` file containing the following top-level keys:
- `contest_name` (mandatory): The name of the contest. It appears in the statements of the problems (and in the solutions).
- `front_page_problemset`: Absolute path of the single-page pdf to use for the front page of the full problem set. This key is not mandatory, if it is not provided then the pdf with the problem set will not have a front page.
- `front_page_solutions`: Absolute path of the single-page pdf to use for the front page of the editorial containing the solutions to all the problems. This key is not mandatory, if it is not provided then the pdf with the solutions will not have a front page.
- `polygon`: A dictionary containing the credentials to use polygon's APIs. This is necessary only if you want to use `p2d` to download the problem packages from polygon. It must have the keys `key` and `secret`. The credentials can be generated in the menu `settings` in polygon.
- `polygon`: A dictionary containing the credentials to use Polygon's APIs. This is necessary only if you want to use `p2d` to download the problem packages from Polygon. It must have the keys `key` and `secret`. The credentials can be generated in the menu `settings` in Polygon.
- `domjudge`: A dictionary containing the credentials to use DOMjudge's APIs. This is necessary only if you want to use `p2d` to upload the problems in a DOMjudge instance (i.e., if you want to use the flag `--domjudge`). This subdictionary must contain the following keys:
- `server`: Address of the server hosting the DOMjudge instance.
- `username`: The username of an admin user of the DOMjudge instance.
- `password`: The password of the abovementioned user.
- `contest_id`: The external ID of the DOMjudge contest.
- `problems`: This is a list of problems. A problem is a dictionary with the following keys:
- `name` (mandatory): Short-name, in polygon, of the problem. This is used as identifier of the problem (denoted above as `problem_name`).
- `polygon_id`: The problem id in polygon. Can be found in the right-side menu after opening the problem in polygon. It is necessary to download the polygon package.
- `name` (mandatory): Short-name, in Polygon, of the problem. This is used as identifier of the problem (denoted above as `problem_name`).
- `polygon_id`: The problem id in Polygon. Can be found in the right-side menu after opening the problem in Polygon. It is necessary to download the Polygon package.
- `label`: The label -- usually an uppercase letter -- used to identify the problem in the DOMjudge scoreboard. Problems will be appear in DOMjudge sorted according to this label.
- `color`: Color of the problem in DOMjudge. It can be either the name of an HTML color (see the list https://htmlcolorcodes.com/color-names/) or the hexadecimal representation of a color (e.g., '#FF12AB'). If the hexadecimal representation is used, it must start with # and it must be enclosed in single or double quotes.
- `author`: The author of the problem. Used in the pdf of the solutions.
- `preparation`: The person who prepared the problems. Used in the pdf of the solutions.
- `override_time_limit`: Value (in seconds) of the time limit of the problem in DOMjudge. If this is present the value set in polygon is ignored.
- `override_memory_limit`: Value (in MiB) of the memory limit of the problem in DOMjudge. If this is present the value set in polygon is ignored.
- `override_time_limit`: Value (in seconds) of the time limit of the problem in DOMjudge. If this is present the value set in Polygon is ignored.
- `override_memory_limit`: Value (in MiB) of the memory limit of the problem in DOMjudge. If this is present the value set in Polygon is ignored.

Some more keys are added (and managed) by `p2d` for caching purposes. Namely each problem will also contain the additional keys: `polygon_version`, `domjudge_local_version`, `domjudge_server_version`.
These additional keys are managed by `p2d` and should not be created or modified by the user. In order to clear entirely the keys related to caching, use the flag `--clear-dir` (which will also clear the directory of the contest).
Expand All @@ -118,7 +118,7 @@ See [this example](examples/config.yaml) for a valid `config.yaml` file.

## Samples explanation detection

In polygon the explanation of samples (when present) is contained in the Notes section without a specific structure.
In Polygon the explanation of samples (when present) is contained in the Notes section without a specific structure.
Since we want to parse the explanations "sample-wise", we need to add some structure.

The explanation of the i-th sample shall be preceded by the line `%BEGIN i` and followed by the line `%END`. For example:
Expand Down Expand Up @@ -147,7 +147,7 @@ We provide a description of the process which generates the tex source of the st
The statement is generated starting from `resources/statement_template.tex` by performing the following operations:

1. Replace the strings `??LABEL??`, `??TITLE??`, `??TIMELIMIT??`, `??MEMORYLIMIT??` with the corresponding metadata.
2. Replace the string `??LEGEND??`, `??INPUT??`, `??OUTPUT??`, `??INTERACTION??` with the content of the corresponding sections in the polygon statement (if present);
2. Replace the string `??LEGEND??`, `??INPUT??`, `??OUTPUT??`, `??INTERACTION??` with the content of the corresponding sections in the Polygon statement (if present);
3. Generate an initially empty string `samples`.
For each problem sample, create two files `sample_id.in` and `sample_id.out` and append to the string `samples` the code `\sample{sample_id}`.
If the sample has an explanation (see [Samples explanation detection](#samples-explanation-detection)), append also `\sampleexplanation{Content of the sample explanation.}`.
Expand Down
6 changes: 3 additions & 3 deletions examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ contest_name: Testing pol2dom
front_page_problemset: absolute_path/problemset_frontpage.pdf # A single-page pdf
front_page_solutions: absolute_path/solutions_frontpage.pdf # A single-page pdf

polygon: # Credentials for polygon APIs. Can be generated in polygon -> settings.
polygon: # Credentials for Polygon APIs. Can be generated in Polygon -> Settings.
key: ???
secret: ???

Expand All @@ -20,8 +20,8 @@ problems:
label: A
color: CornflowerBlue # HTML color: https://htmlcolorcodes.com/color-names/
override_memory_limit: 2048 # MiB
# To find the problem id in polygon:
# 1. Open the problem in polygon
# To find the problem id in Polygon:
# 1. Open the problem in Polygon
# 2. The first row of the right-side menu contains id = ???.
polygon_id: ???
author: Federico Glaudo
Expand Down
2 changes: 1 addition & 1 deletion p2d/generate_domjudge_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'time-limit-exceeded-or-accepted': None,
'time-limit-exceeded-or-memory-limit-exceeded': None,
'memory-limit-exceeded': 'run_time_error',
'rejected': None, # = label 'Incorrect' in polygon.
'rejected': None, # = label 'Incorrect' in Polygon.
'failed': None,
'do-not-run': None
}
Expand Down
12 changes: 6 additions & 6 deletions p2d/p2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@


def prepare_argument_parser():
parser = ArgumentParser(description='Utility script to import a whole contest from polygon into DOMjudge.')
parser.add_argument('contest_directory', help='The directory containing the config.yaml file describing the contest. This directory will store also the polygon and DOMjudge packages.')
parser = ArgumentParser(description='Utility script to import a whole contest from Polygon into DOMjudge.')
parser.add_argument('contest_directory', help='The directory containing the config.yaml file describing the contest. This directory will store also the Polygon and DOMjudge packages.')
parser.add_argument('--problems', nargs='+', help='Use this flag to pass the name of one or more problems if you want to execute the script on only on those problems.')
parser.add_argument('--polygon', '--import', '--get', '--download', action='store_true', help='Whether the problem packages should be downloaded from Polygon. Otherwise only the packages already present in the system will be considered.')
parser.add_argument('--convert', action='store_true', help='Whether the polygon packages should be converted to DOMjudge packages. Otherwise only the DOMjudge packages already present in the system will be considered.')
parser.add_argument('--convert', action='store_true', help='Whether the Polygon packages should be converted to DOMjudge packages. Otherwise only the DOMjudge packages already present in the system will be considered.')
parser.add_argument('--domjudge', '--export', '--send', '--upload', action='store_true', help='Whether the DOMjudge packages shall be uploaded to the DOMjudge instance specified in config.yaml.')
parser.add_argument('--from-contest', type=int, help='Update config.yaml with the problems of the specified Polygon contest.')
parser.add_argument('--pdf-contest', action='store_true', help='Whether the pdf of the whole problemset and the pdf with all the solutions should be generated. If set, the files are created in \'contest_dir/tex/problemset.pdf\' and \'contest_dir/tex/solutions.pdf\'.')
parser.add_argument('--verbosity', choices=['debug', 'info', 'warning'],
default='info', help='Verbosity of the logs.')
parser.add_argument('--no-cache', action='store_true', help='If set, the various steps (polygon, convert, domjudge) are run even if they would not be necessary (according to the caching mechanism).')
parser.add_argument('--clear-dir', action='store_true', help='If set, problems\' data in the contest directory is deleted (as a consequence, the cache is deleted). The file \'config.yaml\' is not deleted.')
parser.add_argument('--clear-domjudge-ids', action='store_true', help='If set, the domjudge IDs saved in config.yaml (for the problems that were uploaded to the DOMjudge server) are deleted. As a consequence, next time the flag `--domjudge` is passed, the problems will be uploaded as new problems to DOMjudge. This should be used either if the DOMjudge server changed, if the DOMjudge contest changed, or if the problems were deleted in the DOMjudge server.')
parser.add_argument('--clear-domjudge-ids', action='store_true', help='If set, the DOMjudge IDs saved in config.yaml (for the problems that were uploaded to the DOMjudge server) are deleted. As a consequence, next time the flag `--domjudge` is passed, the problems will be uploaded as new problems to DOMjudge. This should be used either if the DOMjudge server changed, if the DOMjudge contest changed, or if the problems were deleted in the DOMjudge server.')
parser.add_argument('--update-testlib', action='store_true', help='Whether to update the local version of testlib (syncing it with the latest version from the official github repository and patching it for DOMjudge).')

return parser
Expand Down Expand Up @@ -108,8 +108,8 @@ def p2d(args):
# Process the problems, one at a time.
# For each problem some of the following operations are performed (depending
# on the command line flags used to run the command):
# 1. Download the polygon package (from polygon).
# 2. Convert the polygon package to a DOMjudge package.
# 1. Download the Polygon package (from Polygon).
# 2. Convert the Polygon package to a DOMjudge package.
# 3. Upload the DOMjudge package (to a running DOMjudge server).
problem_selected_exists = False
for problem in config['problems']:
Expand Down
Loading

0 comments on commit 6365cab

Please sign in to comment.