Skip to content

Commit

Permalink
Bugfix for no submission csv generation (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbsinha authored and prateekkumarweb committed Apr 30, 2019
1 parent de65ea4 commit c188846
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions judge/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,35 +729,36 @@ def get_csv(contest: str) -> Tuple[bool, Any]:
for problem in problems[1:]:
submissions |= models.PersonProblemFinalScore.objects.filter(problem=problem)

# Now sort all the person-problem-scores by 'person' and 'problem'
# This will create scores like:
# [('p1', 3(Say score corresponding to problem2)),
# ('p1', 2(score corresponding to problem4)),
# ('p2', 5(score corresponding to problem3)),
# ('p2', 0(score corresponding to problem1)) ... ]
# We do not need to save exactly which problem the score correspondes to
# we only need to know scores on all problems by a participant
submissions.order_by('person', 'problem')
scores = [(submission.person, submission.score)
for submission in submissions]

# Here we aggregate the previous list.
# We simply iterate over scores and for each participant,
# we sum up how much has he scored in all the problems.
# To do this we exploit the fact that list is already sorted.
# In the above case after aggregating we'll write
# 'p1', 5
# 'p2', 5 etc. in csvstring
curr_person = scores[0][0]
sum_scores = 0
for score in scores:
if curr_person == score[0]:
sum_scores += score[1]
else:
writer.writerow([curr_person, sum_scores])
curr_person = score[0]
sum_scores = score[1]
writer.writerow([curr_person, sum_scores])
if submissions.exists():
# Now sort all the person-problem-scores by 'person' and 'problem'
# This will create scores like:
# [('p1', 3(Say score corresponding to problem2)),
# ('p1', 2(score corresponding to problem4)),
# ('p2', 5(score corresponding to problem3)),
# ('p2', 0(score corresponding to problem1)) ... ]
# We do not need to save exactly which problem the score correspondes to
# we only need to know scores on all problems by a participant
submissions.order_by('person', 'problem')
scores = [(submission.person, submission.score)
for submission in submissions]

# Here we aggregate the previous list.
# We simply iterate over scores and for each participant,
# we sum up how much has he scored in all the problems.
# To do this we exploit the fact that list is already sorted.
# In the above case after aggregating we'll write
# 'p1', 5
# 'p2', 5 etc. in csvstring
curr_person = scores[0][0]
sum_scores = 0
for score in scores:
if curr_person == score[0]:
sum_scores += score[1]
else:
writer.writerow([curr_person, sum_scores])
curr_person = score[0]
sum_scores = score[1]
writer.writerow([curr_person, sum_scores])

csvstring.seek(0)
return (True, csvstring)
Expand Down

0 comments on commit c188846

Please sign in to comment.