11import dramatiq
22
3- from account .models import User
3+ from account .models import User , UserProfile
44from submission .models import Submission
5+ from problem .models import Problem
56from utils .shortcuts import DRAMATIQ_WORKER_ARGS
67
78from .dispatcher import JudgeDispatcher
@@ -17,8 +18,34 @@ def judge_task(submission_id, problem_id):
1718
1819
1920@dramatiq .actor (** DRAMATIQ_WORKER_ARGS ())
20- def local_judge_task (submission_id , problem_id ):
21- uid = Submission .objects .get (id = submission_id ).user_id
22- if User .objects .get (id = uid ).is_disabled :
23- return
24- SubmissionTester (submission_id , problem_id ).judge ()
21+ def local_judge_task (submission_id , problem_id , user_id ):
22+ submission = Submission .objects .get (id = submission_id )
23+
24+ problem = Problem .objects .get (_id = problem_id )
25+ problem .submission_number += 1
26+ try :
27+ if SubmissionTester (submission ).judge ():
28+ problem .accepted_number += 1
29+ except Exception as e :
30+ raise
31+ problem .save ()
32+
33+ score = submission .grade
34+ user = User .objects .get (id = user_id )
35+ assert user
36+ profile = UserProfile .objects .get (user = user )
37+ assert profile
38+ profile .total_submissions += 1
39+ if problem ._id not in profile .problems_status :
40+ profile .problems_status [problem ._id ] = score
41+ profile .total_score += score
42+ if score == 100 :
43+ profile .accepted_number += 1
44+ else :
45+ prev_score = profile .problems_status [problem ._id ]
46+ if score > prev_score :
47+ profile .problems_status [problem ._id ] = score
48+ profile .total_score += (score - prev_score )
49+ if score == 100 :
50+ profile .accepted_number += 1
51+ profile .save ()
0 commit comments