Skip to content
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

fix sorting for grading #1155

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 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 @@ -1943,12 +1943,12 @@
left_join: asst in subquery(question_answers_query),
on: asst.assessment_id == s.assessment_id,
as: :asst,
left_join: user in User,
on: user.id == s.student_id,
as: :user,
left_join: cr in CourseRegistration,
on: user.id == cr.user_id,
on: s.student_id == cr.id,
as: :cr,
left_join: user in User,
on: user.id == cr.user_id,
as: :user,
left_join: group in Group,
on: cr.group_id == group.id,
as: :group,
Expand Down Expand Up @@ -1982,7 +1982,9 @@
query =
sort_submission(query, Map.get(params, "sortBy", ""), Map.get(params, "sortDirection", ""))

query = from([s, ans, asst, user, cr, group] in query, order_by: [desc: s.inserted_at])
query =
from([s, ans, asst, cr, user, group] in query, order_by: [desc: s.inserted_at, asc: s.id])

submissions = Repo.all(query)

count_query =
Expand Down Expand Up @@ -2027,30 +2029,30 @@
defp sort_submission_asc(query, sort_by) do
cond do
sort_by == "assessmentName" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: fragment("upper(?)", asst.title)
)

sort_by == "assessmentType" ->
from([s, ans, asst, user, cr, group, config] in query, order_by: asst.config_id)
from([s, ans, asst, cr, user, group, config] in query, order_by: asst.config_id)

sort_by == "studentName" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: fragment("upper(?)", user.name)
)

sort_by == "studentUsername" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: fragment("upper(?)", user.username)
)

sort_by == "groupName" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: fragment("upper(?)", group.name)
)

sort_by == "progressStatus" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [
asc: config.is_manually_graded,
asc: s.status,
Expand All @@ -2060,7 +2062,7 @@
)

sort_by == "xp" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: ans.xp + ans.xp_adjustment
)

Expand All @@ -2072,30 +2074,30 @@
defp sort_submission_desc(query, sort_by) do
cond do
sort_by == "assessmentName" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [desc: fragment("upper(?)", asst.title)]
)

sort_by == "assessmentType" ->
from([s, ans, asst, user, cr, group, config] in query, order_by: [desc: asst.config_id])
from([s, ans, asst, cr, user, group, config] in query, order_by: [desc: asst.config_id])

sort_by == "studentName" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [desc: fragment("upper(?)", user.name)]
)

sort_by == "studentUsername" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [desc: fragment("upper(?)", user.username)]
)

sort_by == "groupName" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [desc: fragment("upper(?)", group.name)]
)

sort_by == "progressStatus" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [
desc: config.is_manually_graded,
desc: s.status,
Expand All @@ -2105,7 +2107,7 @@
)

sort_by == "xp" ->
from([s, ans, asst, user, cr, group, config] in query,
from([s, ans, asst, cr, user, group, config] in query,
order_by: [desc: ans.xp + ans.xp_adjustment]
)

Expand Down Expand Up @@ -2681,7 +2683,7 @@

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

Check warning on line 2686 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