Skip to content

Commit

Permalink
Improved logic of pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dario2994 committed Jun 24, 2022
1 parent c7759a7 commit dc1e28e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ Clone the repository with `git clone https://github.com/dario2994/pol2dom` and r

Running

```p2d contest_directory --polygon --convert --domjudge```
```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.
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 three, almost independent, fundamental operations that can be performed by `p2d`:
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. 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.

Moreover, in `contest_directory/tex/` the full problem set `problemset.pdf` and the editorial of the contest `solutions.pdf` are generated (for the problems that were ever converted to a valid DOMjudge package by the command).
For each problem, also `contest_directory/tex/problem_name-statement.pdf` and `contest_directory/tex/problem_name-solution.pdf` are generated.
- `--pdf-contest`: Generate in `contest_directory/tex/` the full problem set `problemset.pdf` and the editorial of the contest `solutions.pdf`. The problems that will appear in these files are those that were ever converted to a valid DOMjudge package by the command (even in a previous execution).

Here is a schematic description of the structure of `contest_directory` after the execution of the command (the user needs only to create a properly set up `config.yaml`):

Expand Down
25 changes: 11 additions & 14 deletions p2d/p2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def prepare_argument_parser():
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('--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('--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).')
Expand All @@ -48,6 +49,12 @@ def p2d(args):

p2d_utils.validate_config_yaml(config)

if not args.polygon and not args.convert and not args.domjudge \
and not args.pdf_contest \
and not args.clear_dir and not args.clear_domjudge_ids:
logging.error('At least one of the flags --polygon, --convert, --domjudge, --contestpdf, --clear-dir, --clear-domjudge-ids is necessary.')
exit(1)

if args.clear_dir:
for problem in config['problems']:
if args.problem and args.problem != problem['name']:
Expand Down Expand Up @@ -84,11 +91,6 @@ def p2d(args):
'in config.yaml to download problems from polygon.')
exit(1)

if not args.polygon and not args.convert and not args.domjudge \
and not args.clear_dir and not args.clear_domjudge_ids:
logging.error('At least one of the flags --polygon, --convert, --domjudge, --clear-dir, --clear-domjudge-ids is necessary.')
exit(1)

pathlib.Path(os.path.join(contest_dir, 'polygon')).mkdir(exist_ok=True)
pathlib.Path(os.path.join(contest_dir, 'domjudge')).mkdir(exist_ok=True)
pathlib.Path(os.path.join(contest_dir, 'tex')).mkdir(exist_ok=True)
Expand All @@ -107,7 +109,6 @@ def p2d(args):
continue

problem_selected_exists = True
print()
print('\033[1m' + problem['name'] + '\033[0m') # Bold

if 'label' not in problem:
Expand Down Expand Up @@ -139,6 +140,8 @@ def p2d(args):
contest_dir, 'domjudge', problem['name']), problem)
p2d_utils.save_config_yaml(config, contest_dir)

print()

if args.problem and not problem_selected_exists:
logging.warning('The problem specified with --problem does not appear '
'in config.yaml.')
Expand All @@ -147,7 +150,8 @@ def p2d(args):
if args.problem:
return

p2d_utils.generate_problemset_solutions(config, contest_dir)
if args.pdf_contest:
p2d_utils.generate_problemset_solutions(config, contest_dir)

# Guidelines for error tracing and logging:
#
Expand All @@ -171,11 +175,4 @@ def main():


# TODO: Everything should be tested appropriately.
# TODO: Handle better the logic for generating the problemset and the solutions.
# Here is a proposal:
# Add a flag, like --problemset or --editorial (or a single flag for
# both) which generates the problemset and the editorial.
# The problem_name-statement-content.tex are still generated all the
# time (and the pdf of single statements and single solutions are
# still generated all the time).
# TODO: Add the support for interactive problems.
1 change: 0 additions & 1 deletion p2d/p2d_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def generate_problemset_solutions(config, contest_dir):
os.path.join(contest_dir, 'tex'),
pdf_generation_params)

print()
logging.info('Successfully generated \'%s\' and \'%s\'.' %
(os.path.join(contest_dir, 'tex', 'problemset.pdf'),
os.path.join(contest_dir, 'tex', 'solutions.pdf')))
Expand Down

0 comments on commit dc1e28e

Please sign in to comment.