Skip to content

Commit 4fb1f4a

Browse files
thortolRichDom2185
andauthored
Fix issues with bonus xp (#1172)
* removed unnecessary logic * change the submission passed into update_xp_bonus * Update bonus xp when grading is published * Add extra logic to check if xp is an integer * Remove outdated comment * Use coalesce to check if total_xp = nil --------- Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
1 parent 0572fb0 commit 4fb1f4a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lib/cadet/assessments/assessments.ex

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ defmodule Cadet.Assessments do
10551055

10561056
# Begin autograding job
10571057
GradingJob.force_grade_individual_submission(updated_submission)
1058-
update_xp_bonus(submission)
1058+
update_xp_bonus(updated_submission)
10591059

10601060
{:ok, nil}
10611061
else
@@ -1294,6 +1294,8 @@ defmodule Cadet.Assessments do
12941294
|> Submission.changeset(%{is_grading_published: true})
12951295
|> Repo.update()
12961296

1297+
update_xp_bonus(submission)
1298+
12971299
Notifications.write_notification_when_published(
12981300
submission.id,
12991301
:published_grading
@@ -1493,23 +1495,18 @@ defmodule Cadet.Assessments do
14931495
Answer
14941496
|> where(submission_id: ^submission_id)
14951497
|> order_by(:question_id)
1496-
|> group_by([a], a.id)
14971498
|> select([a], %{
1498-
# grouping by submission, so s.xp_bonus will be the same, but we need an
1499-
# aggregate function
1500-
total_xp: sum(a.xp) + sum(a.xp_adjustment)
1499+
total_xp: a.xp + a.xp_adjustment
15011500
})
15021501

15031502
total =
15041503
ans_xp
15051504
|> subquery
15061505
|> select([a], %{
1507-
total_xp: sum(a.total_xp)
1506+
total_xp: coalesce(sum(a.total_xp), 0)
15081507
})
15091508
|> Repo.one()
15101509

1511-
xp = decimal_to_integer(total.total_xp)
1512-
15131510
cur_time =
15141511
if submission.submitted_at == nil do
15151512
Timex.now()
@@ -1518,7 +1515,7 @@ defmodule Cadet.Assessments do
15181515
end
15191516

15201517
xp_bonus =
1521-
if xp <= 0 do
1518+
if total.total_xp <= 0 do
15221519
0
15231520
else
15241521
if Timex.before?(cur_time, Timex.shift(assessment.open_at, hours: early_hours)) do

0 commit comments

Comments
 (0)