Skip to content

Comments feature for grading #461

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 3 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions lib/cadet/assessments/answer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Cadet.Assessments.Answer do
field(:adjustment, :integer, default: 0)
field(:xp, :integer, default: 0)
field(:xp_adjustment, :integer, default: 0)
field(:comments, :string)
field(:autograding_status, AutogradingStatus, default: :none)
field(:autograding_results, {:array, :map}, default: [])
field(:answer, :map)
Expand All @@ -30,7 +31,7 @@ defmodule Cadet.Assessments.Answer do
end

@required_fields ~w(answer submission_id question_id type)a
@optional_fields ~w(xp xp_adjustment grade adjustment grader_id)a
@optional_fields ~w(xp xp_adjustment grade adjustment grader_id comments)a

def changeset(answer, params) do
answer
Expand All @@ -49,7 +50,16 @@ defmodule Cadet.Assessments.Answer do
answer
|> cast(
params,
~w(grader_id xp xp_adjustment grade adjustment autograding_results autograding_status)a
~w(
grader_id
xp
xp_adjustment
grade
adjustment
autograding_results
autograding_status
comments
)a
)
|> add_belongs_to_id_from_model(:grader, params)
|> foreign_key_constraint(:grader_id)
Expand Down
3 changes: 2 additions & 1 deletion lib/cadet/assessments/assessments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ defmodule Cadet.Assessments do
xp_adjustment: 0,
autograding_status: :none,
autograding_results: [],
grader_id: nil
grader_id: nil,
comments: nil
})
|> Repo.update()}
end
Expand Down
1 change: 1 addition & 0 deletions lib/cadet_web/controllers/assessments_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ defmodule CadetWeb.AssessmentsController do

xp(:integer, "Final XP given to this question. Only provided for students.")
grade(:integer, "Final grade given to this question. Only provided for students.")
comments(:string, "String of comments given for a student's answer", required: false)

maxGrade(
:integer,
Expand Down
1 change: 1 addition & 0 deletions lib/cadet_web/controllers/grading_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ defmodule CadetWeb.GradingController do
xpAdjustment(:integer, "xp adjustment given")
grader(Schema.ref(:GraderInfo))
gradedAt(:string, "Last graded at", format: "date-time", required: false)
comments(:string, "Comments given by grader")
end
end,
Grading:
Expand Down
3 changes: 2 additions & 1 deletion lib/cadet_web/views/assessments_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ defmodule CadetWeb.AssessmentsHelpers do
xp: &((&1.xp || 0) + (&1.xp_adjustment || 0)),
grade: &((&1.grade || 0) + (&1.adjustment || 0)),
autogradingStatus: :autograding_status,
autogradingResults: build_results(%{results: answer.autograding_results})
autogradingResults: build_results(%{results: answer.autograding_results}),
comments: :comments
})
end

Expand Down
3 changes: 2 additions & 1 deletion lib/cadet_web/views/grading_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ defmodule CadetWeb.GradingView do
adjustment: :adjustment,
roomId: :room_id,
xp: :xp,
xpAdjustment: :xp_adjustment
xpAdjustment: :xp_adjustment,
comments: :comments
})
end
end
9 changes: 9 additions & 0 deletions priv/repo/migrations/20190729154942_restore_comments.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Cadet.Repo.Migrations.RestoreComments do
use Ecto.Migration

def change do
alter table(:answers) do
add(:comments, :text, null: true)
end
end
end
1 change: 1 addition & 0 deletions test/cadet_web/controllers/assessments_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ defmodule CadetWeb.AssessmentsControllerTest do
|> Enum.map(&Map.delete(&1, "gradedAt"))
|> Enum.map(&Map.delete(&1, "autogradingResults"))
|> Enum.map(&Map.delete(&1, "autogradingStatus"))
|> Enum.map(&Map.delete(&1, "comments"))

assert expected_questions == resp_questions
end
Expand Down
19 changes: 13 additions & 6 deletions test/cadet_web/controllers/grading_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ defmodule CadetWeb.GradingControllerTest do
"name" => grader.name,
"id" => grader.id
},
"gradedAt" => format_datetime(&1.updated_at)
"gradedAt" => format_datetime(&1.updated_at),
"comments" => &1.comments
},
"student" => %{
"name" => &1.submission.student.name,
Expand Down Expand Up @@ -342,7 +343,8 @@ defmodule CadetWeb.GradingControllerTest do
"name" => grader.name,
"id" => grader.id
},
"gradedAt" => format_datetime(&1.updated_at)
"gradedAt" => format_datetime(&1.updated_at),
"comments" => &1.comments
},
"student" => %{
"name" => &1.submission.student.name,
Expand Down Expand Up @@ -414,7 +416,8 @@ defmodule CadetWeb.GradingControllerTest do
"name" => grader.name,
"id" => grader.id
},
"gradedAt" => format_datetime(&1.updated_at)
"gradedAt" => format_datetime(&1.updated_at),
"comments" => &1.comments
},
"student" => %{
"name" => &1.submission.student.name,
Expand Down Expand Up @@ -461,7 +464,8 @@ defmodule CadetWeb.GradingControllerTest do
"name" => grader.name,
"id" => grader.id
},
"gradedAt" => format_datetime(&1.updated_at)
"gradedAt" => format_datetime(&1.updated_at),
"comments" => &1.comments
},
"student" => %{
"name" => &1.submission.student.name,
Expand Down Expand Up @@ -614,6 +618,7 @@ defmodule CadetWeb.GradingControllerTest do
assert answer_db.xp_adjustment == 0
assert answer_db.grade == 0
assert answer_db.adjustment == 0
assert answer_db.comments == nil
end

@tag authenticate: :staff
Expand Down Expand Up @@ -931,7 +936,8 @@ defmodule CadetWeb.GradingControllerTest do
"name" => grader.name,
"id" => grader.id
},
"gradedAt" => format_datetime(&1.updated_at)
"gradedAt" => format_datetime(&1.updated_at),
"comments" => &1.comments
},
"student" => %{
"name" => &1.submission.student.name,
Expand Down Expand Up @@ -978,7 +984,8 @@ defmodule CadetWeb.GradingControllerTest do
"name" => grader.name,
"id" => grader.id
},
"gradedAt" => format_datetime(&1.updated_at)
"gradedAt" => format_datetime(&1.updated_at),
"comments" => &1.comments
},
"student" => %{
"name" => &1.submission.student.name,
Expand Down
3 changes: 2 additions & 1 deletion test/factories/assessments/answer_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ defmodule Cadet.Assessments.AnswerFactory do
%Answer{
answer: %{},
autograding_status: :none,
room_id: Faker.Code.issn()
room_id: Faker.Code.issn(),
comments: Faker.Food.dish()
}
end

Expand Down