Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: head comments #39

Merged
merged 5 commits into from
Jul 25, 2023
Merged

feat: head comments #39

merged 5 commits into from
Jul 25, 2023

Conversation

D4NZ-jpg
Copy link
Contributor

@D4NZ-jpg D4NZ-jpg commented Jul 6, 2023

I've added this new feature that I personally find really neat to keep track of my solutions, and I think it could benefit others too.

The idea behind this feature is to provide users with the ability to add a header comment at the start of each file automatically. This feature is useful for adding metadata about the problem such as the problem name, group, URL, memory limit, time limit and the starting time.

If you decide to add a comment, you can use specific modifiers to insert dynamic information. For example, you can set the head_comment variable to "//This file was generated at $(TIME)", and it will automatically insert the current time in your preferred format, which can be specified with the time_format option, which allows you to specify how you'd like to display the time in your header comment.

This feature is not mandatory; if you don't want a comment in your files, just set the head_comment variable to false.

The way I like to use it is something like this:

head_comment = "//Problem: $(NAME)\n//Contest: $(GROUP)\n//URL: $(URL)\n//Memory Limit: $(MEMLIM) MB\n//Time Limit: $(TIMELIM) ms\n//Start: $(TIME)",
time_format = "%d-%m-%Y %H:%M:%S"

which produces something like this on the top of every file:

//Problem: A. Forbidden Integer
//Contest: Codeforces - Educational Codeforces Round 151 (Rated for Div. 2)
//URL: https://codeforces.com/contest/1845/problem/A
//Memory Limit: 256 MB
//Time Limit: 2000 ms
//Start: 06-07-2023 13:00:17
...

@xeluxee
Copy link
Owner

xeluxee commented Jul 8, 2023

CompetiTest can be configured to create source files from templates for received problems and contests, see template_file.
I think it'd be more straightforward to integrate head comments into templates, not only because a single string would make configuration long and unreadable, but also because different filetypes have different comments, e.g. double slash won't work with python.
So the option head_comment should be substituted by a boolean evaluate_templates, to let users decide whether to enable this feature or not.

Regarding new modifiers, they should be kept separated from file format modifiers. We already discussed about $(CONTEST) and $(JUDGE) modifers in #28 and #29. See also competitive companion format: https://github.com/jmerle/competitive-companion#the-format

I suggest the following receive-modifers, that will be used to evaluate contests_directory, problems_directory (from #29) and header comments in template files.

modifier meaning
$(PROBLEM) Problem name, name field
$(GROUP) judge and contest name, group field
$(JUDGE) first part of group, before hyphen
$(CONTEST) second part of group, after hyphen
$(URL) problem url, url field
$(MEMLIM) available memory, memoryLimit field
$(TIMELIM) time limit, timeLimit field
$(HOME) home directory
$(DATE) current time, following date_format

@D4NZ-jpg wait before proceeding with commits until we reach an agreement about what to do

@xeluxee
Copy link
Owner

xeluxee commented Jul 19, 2023

Now that #40 is closed and receive modifiers (previously called comment modifiers) are implemented, you should rebase this PR or make it from scratch (don't worry, it'll be easier). Here are some suggestions:

  1. Add date_format (string) and evaluate_template_modifiers (boolean) options
  2. Take a look at lua/competitest/receive.lua: use eval_receive_modifiers() to substitute modifiers from loaded file
  3. Add $(DATE) modifier among the others, get date_format as function argument in eval_receive_modifiers()
  4. Templates creation should be managed by store_problem_config and store_problem functions
  5. To do that the third argument of store_problem_config, tclist, should be replaced by task, a table with all task details

@D4NZ-jpg
Copy link
Contributor Author

Got it. Will make the changes soon.

@D4NZ-jpg
Copy link
Contributor Author

@xeluxee done, does everything seems okay?

@xeluxee
Copy link
Owner

xeluxee commented Jul 24, 2023

This PR looks ready to be merged

@D4NZ-jpg
Copy link
Contributor Author

Great, thanks!

@xeluxee xeluxee merged commit ab49400 into xeluxee:master Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants