-
Notifications
You must be signed in to change notification settings - Fork 8
Add feature to manage random-set contest #197
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
Open
yushiuan9499
wants to merge
40
commits into
TFcis:v2.0
Choose a base branch
from
yushiuan9499:feat/random-set
base: v2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Without pro_sets, it is hard to do many operations. Such as generate pro_set list for manage UI.
The value of param has been checked at handler. We don't need to check twice.
Because the RequestHandler instance of each request is independent, the contest is always consistent with the database. This means db is the only thing must be updated.
Because ip is default to 0.0.0.0, the ip_range of contest can't be None.
Order is a keyword in SQL.
This reverts commit 78d86f1. Because of the redis cache, the contest is also need to be update to set redis cache.
Both add_pro_set & update_ip need to append a random problem to the ip_pro_list, but only add_pro_set need to update pro_list & do some check, so I let this logic be a single function.
If there are no ip in the db, there will be no item in ip_pro_list and , as a result, get 0 pro_set count. Use sql to get count of distinct order is a more stable way.
yushiuan9499
commented
Jan 13, 2026
Comment on lines
+415
to
+440
| async def add_random_pro(self, contest: Contest, pro_set: list[int]): | ||
| ''' | ||
| Append a random problem in pro_set to each ip's problem list | ||
| ''' | ||
| pro_size = len(pro_set) | ||
| if pro_size == 1: | ||
| for pro_list in contest.ip_pro_list.values(): | ||
| pro_list.append(pro_set[0]) | ||
| elif pro_size == 2: | ||
| for pro_list in contest.ip_pro_list.values(): | ||
| pro_list.append(pro_set[random.randint(0, 1)]) | ||
| else: | ||
| idx = 0 | ||
| for pro_list in contest.ip_pro_list.values(): | ||
| idx = (idx + random.randint(1,pro_size-1)) % pro_size | ||
| pro_list.append(pro_set[idx]) | ||
|
|
||
| async with self.db.acquire() as con: | ||
| # Insert por_id into contest_ip_joints | ||
| await con.executemany( | ||
| ''' | ||
| INSERT INTO contest_ip_joints ("contest_id", "ip", "pro_id") | ||
| VALUES ($1, $2, $3) | ||
| ''', | ||
| [(contest.contest_id, str(ip), pro_list[-1]) for ip, pro_list in contest.ip_pro_list.items()] | ||
| ) |
Collaborator
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the main algorithm to assign problems to contestants.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
TOJ will be used as an online judge for exams.
To avoiding cheating, we introduced a new "Random Set" contest mode in this PR.
In this contest mode, each problem number corresponds to a problem set.
And if a problem set contains more than 2 problems, any adjacent contestants will always see different problems. Otherwise, the assignment is randomized.
Implementation
contest_ip_jointsis added to record the problems assign to the ip.start_ipandend_ipare added to tableconteststo record the contests' ip range.Note
This PR only completes the admin-side features, user-side features like scoreboard will be done later.