Skip to content

Commit 3c1d314

Browse files
authored
Add files via upload
1 parent bc05fa9 commit 3c1d314

File tree

1 file changed

+67
-64
lines changed

1 file changed

+67
-64
lines changed
Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
1-
defmodule Cadet.Autograder.Utilities do
2-
@moduledoc """
1+
defmodule Cadet.Autograder.Utilities do
2+
@moduledoc """
33
This module defines functions that support the autograder functionality.
4-
"""
5-
use Cadet, :context
6-
7-
require Logger
8-
9-
import Ecto.Query
10-
11-
alias Cadet.Accounts.CourseRegistration
12-
alias Cadet.Assessments.{Answer, Assessment, Question, Submission}
13-
14-
def dispatch_programming_answer(answer = %Answer{}, question = %Question{}, overwrite \\ false) do
15-
# This should never fail
16-
answer =
17-
answer
18-
|> Answer.autograding_changeset(%{autograding_status: :processing})
19-
|> Repo.update!()
20-
21-
Que.add(Cadet.Autograder.LambdaWorker, %{
22-
question: question,
23-
answer: answer,
24-
overwrite: overwrite
25-
})
26-
end
27-
28-
def fetch_submissions(assessment_id, course_id) when is_ecto_id(assessment_id) do
29-
CourseRegistration
30-
|> where(role: "student", course_id: ^course_id)
31-
|> join(
32-
:left,
33-
[cr],
34-
s in Submission,
35-
on: cr.id == s.student_id and s.assessment_id == ^assessment_id
36-
)
37-
|> select([cr, s], %{student_id: cr.id, submission: s})
38-
|> Repo.all()
39-
end
40-
41-
def fetch_assessments_due_yesterday do
42-
Assessment
43-
|> where(is_published: true)
44-
|> where([a], a.close_at < ^Timex.now() and a.close_at >= ^Timex.shift(Timex.now(), days: -1))
45-
|> join(:inner, [a, c], q in assoc(a, :questions))
46-
|> preload([_, q], questions: q)
47-
|> Repo.all()
48-
|> Enum.map(&sort_assessment_questions(&1))
49-
end
50-
51-
# fetch voting questions that are about to open the next day
52-
def fetch_voting_questions do
53-
Question
54-
|> where(type: :voting)
55-
|> join(:inner, [q], asst in assoc(q, :assessment))
56-
|> where([q, asst], asst.open_at > ^Timex.now() and asst.open_at <= ^Timex.shift(Timex.now(), days: 1))
57-
|> select([q, asst], %{course_id: asst.course_id, question: q.question, question_id: q.id})
58-
|> Repo.all()
59-
end
60-
61-
def sort_assessment_questions(assessment = %Assessment{}) do
62-
sorted_questions = Enum.sort_by(assessment.questions, & &1.id)
63-
Map.put(assessment, :questions, sorted_questions)
64-
end
65-
end
4+
"""
5+
use Cadet, :context
6+
7+
require Logger
8+
9+
import Ecto.Query
10+
11+
alias Cadet.Accounts.CourseRegistration
12+
alias Cadet.Assessments.{Answer, Assessment, Question, Submission}
13+
14+
def dispatch_programming_answer(answer = %Answer{}, question = %Question{}, overwrite \\ false) do
15+
# This should never fail
16+
answer =
17+
answer
18+
|> Answer.autograding_changeset(%{autograding_status: :processing})
19+
|> Repo.update!()
20+
21+
Que.add(Cadet.Autograder.LambdaWorker, %{
22+
question: question,
23+
answer: answer,
24+
overwrite: overwrite
25+
})
26+
end
27+
28+
def fetch_submissions(assessment_id, course_id) when is_ecto_id(assessment_id) do
29+
CourseRegistration
30+
|> where(role: "student", course_id: ^course_id)
31+
|> join(
32+
:left,
33+
[cr],
34+
s in Submission,
35+
on: cr.id == s.student_id and s.assessment_id == ^assessment_id
36+
)
37+
|> select([cr, s], %{student_id: cr.id, submission: s})
38+
|> Repo.all()
39+
end
40+
41+
def fetch_assessments_due_yesterday do
42+
Assessment
43+
|> where(is_published: true)
44+
|> where([a], a.close_at < ^Timex.now() and a.close_at >= ^Timex.shift(Timex.now(), days: -1))
45+
|> join(:inner, [a, c], q in assoc(a, :questions))
46+
|> preload([_, q], questions: q)
47+
|> Repo.all()
48+
|> Enum.map(&sort_assessment_questions(&1))
49+
end
50+
51+
# fetch voting questions that are about to open the next day
52+
def fetch_voting_questions do
53+
Question
54+
|> where(type: :voting)
55+
|> join(:inner, [q], asst in assoc(q, :assessment))
56+
|> where(
57+
[q, asst],
58+
asst.open_at > ^Timex.now() and asst.open_at <= ^Timex.shift(Timex.now(), days: 1)
59+
)
60+
|> select([q, asst], %{course_id: asst.course_id, question: q.question, question_id: q.id})
61+
|> Repo.all()
62+
end
63+
64+
def sort_assessment_questions(assessment = %Assessment{}) do
65+
sorted_questions = Enum.sort_by(assessment.questions, & &1.id)
66+
Map.put(assessment, :questions, sorted_questions)
67+
end
68+
end

0 commit comments

Comments
 (0)