mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
refine random problems features
This commit is contained in:
parent
6c22457143
commit
d8f21bccd8
@ -107,29 +107,27 @@ class ContestProblemAPI(APIView):
|
||||
problem_data = ProblemSafeSerializer(problem).data
|
||||
return self.success(problem_data)
|
||||
|
||||
random.seed(request.user.id + request.contest.id)
|
||||
|
||||
# Random problems for every students in contest
|
||||
def random_contest_problems(self, difficulty='Low', count=3):
|
||||
contest_problem_set = Problem.objects.select_related("created_by").filter(contest=self.contest, visible=True, difficulty=difficulty).all()
|
||||
contest_problem_id = []
|
||||
for i in contest_problem_set:
|
||||
contest_problem_id.append(i._id)
|
||||
contest_problem_id = random.sample(contest_problem_id, count)
|
||||
contest_problems = Problem.objects.select_related("created_by").filter(contest=self.contest, visible=True, _id__in=contest_problem_id)
|
||||
return contest_problems
|
||||
|
||||
contest_low_problems = random_contest_problems(difficulty='Low', count=3)
|
||||
contest_mid_problems = random_contest_problems(difficulty='Mid', count=2)
|
||||
contest_high_problems = random_contest_problems(difficulty='High', count=0)
|
||||
random.seed(request.user.id + self.contest.id)
|
||||
|
||||
contest_problems = (contest_low_problems | contest_mid_problems | contest_high_problems).order_by("_id")
|
||||
query_set = Problem.objects.select_related("created_by").filter(contest=self.contest, visible=True).all()
|
||||
low_problems_query_set = query_set.filter(difficulty='Low')
|
||||
low_problems_query_set_id = list(low_problems_query_set.values_list('_id', flat=True))
|
||||
low_selected_id = random.sample(low_problems_query_set_id, 3)
|
||||
contest_low_problems = low_problems_query_set.filter(_id__in=low_selected_id)
|
||||
|
||||
# self.contest_problem_list = random.sample(contest_low_problem_set, 3)
|
||||
# self.contest_problem_list.extend(random.sample(contest_mid_problem_set, 2))
|
||||
# self.contest_problem_list.extend(random.sample(contest_high_problem_set, 0))
|
||||
mid_problems_query_set = query_set.filter(difficulty='Mid')
|
||||
mid_problems_query_set_id = list(mid_problems_query_set.values_list('_id', flat=True))
|
||||
mid_selected_id = random.sample(mid_problems_query_set_id, 2)
|
||||
contest_mid_problems = mid_problems_query_set.filter(_id__in=mid_selected_id)
|
||||
|
||||
high_problems_query_set = query_set.filter(difficulty='High')
|
||||
high_problems_query_set_id = list(high_problems_query_set.values_list('_id', flat=True))
|
||||
high_selected_id = random.sample(high_problems_query_set_id, 0)
|
||||
contest_high_problems = high_problems_query_set.filter(_id__in=high_selected_id)
|
||||
|
||||
contest_problems = contest_low_problems | contest_mid_problems | contest_high_problems
|
||||
|
||||
# # contest_problems = Problem.objects.select_related("created_by").filter(contest=self.contest, visible=True, _id__in=self.probelm_list).order_by('_id')
|
||||
if self.contest.problem_details_permission(request.user):
|
||||
data = ProblemSerializer(contest_problems, many=True).data
|
||||
self._add_problem_status(request, data)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user