Skip to content

Fix issues with bonus xp #1172

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

Merged
merged 9 commits into from
Jun 13, 2025
16 changes: 11 additions & 5 deletions lib/cadet/assessments/assessments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@
raw_answer,
force_submit
) do
with {:ok, team} <- find_team(question.assessment.id, cr_id),

Check warning on line 919 in lib/cadet/assessments/assessments.ex

View workflow job for this annotation

GitHub Actions / Run CI

variable "team" is unused (if the variable is not meant to be used, prefix it with an underscore)
{:ok, submission} <- find_or_create_submission(cr, question.assessment),
{:status, true} <- {:status, force_submit or submission.status != :submitted},
{:ok, _answer} <- insert_or_update_answer(submission, question, raw_answer, cr_id) do
Expand Down Expand Up @@ -1034,7 +1034,7 @@

# Begin autograding job
GradingJob.force_grade_individual_submission(updated_submission)
update_xp_bonus(submission)
update_xp_bonus(updated_submission)

{:ok, nil}
else
Expand Down Expand Up @@ -1257,6 +1257,8 @@
|> Submission.changeset(%{is_grading_published: true})
|> Repo.update()

update_xp_bonus(submission)

Notifications.write_notification_when_published(
submission.id,
:published_grading
Expand Down Expand Up @@ -1455,11 +1457,10 @@
Answer
|> where(submission_id: ^submission_id)
|> order_by(:question_id)
|> group_by([a], a.id)
|> select([a], %{
# grouping by submission, so s.xp_bonus will be the same, but we need an
# aggregate function
total_xp: sum(a.xp) + sum(a.xp_adjustment)
total_xp: a.xp + a.xp_adjustment
})

total =
Expand All @@ -1470,15 +1471,20 @@
})
|> Repo.one()

xp = decimal_to_integer(total.total_xp)

cur_time =
if submission.submitted_at == nil do
Timex.now()
else
submission.submitted_at
end

xp =
if is_integer(total.total_xp) do
total.total_xp
else
decimal_to_integer(total.total_xp)
end

xp_bonus =
if xp <= 0 do
0
Expand Down Expand Up @@ -2708,7 +2714,7 @@

def has_last_modified_answer?(
question = %Question{},
cr = %CourseRegistration{id: cr_id},

Check warning on line 2717 in lib/cadet/assessments/assessments.ex

View workflow job for this annotation

GitHub Actions / Run CI

variable "cr_id" is unused (if the variable is not meant to be used, prefix it with an underscore)
last_modified_at,
force_submit
) do
Expand Down
Loading