diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 8f8bdd9cc..7a83d80f7 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -876,7 +876,7 @@ defmodule Cadet.Assessments do SubmissionVotes |> where(question_id: ^question.id) |> where(voter_id: ^submission.student_id) - |> where([sv], is_nil(sv.rank)) + |> where([sv], is_nil(sv.score)) |> Repo.exists?() unless has_nil_entries do @@ -921,7 +921,7 @@ defmodule Cadet.Assessments do |> where([v], v.voter_id == ^voter_id and v.question_id == ^question_id) |> join(:inner, [v], s in assoc(v, :submission)) |> join(:inner, [v, s], a in assoc(s, :answers)) - |> select([v, s, a], %{submission_id: v.submission_id, answer: a.answer, rank: v.rank}) + |> select([v, s, a], %{submission_id: v.submission_id, answer: a.answer, score: v.score}) |> Repo.all() end @@ -1026,17 +1026,17 @@ defmodule Cadet.Assessments do """ def compute_relative_score(contest_voting_question_id) do # query all records from submission votes tied to the question id -> - # map rank to user id -> + # map score to user id -> # store as grade -> # query grade for contest question id. eligible_votes = SubmissionVotes |> where(question_id: ^contest_voting_question_id) - |> where([sv], not is_nil(sv.rank)) + |> where([sv], not is_nil(sv.score)) |> join(:inner, [sv], ans in Answer, on: sv.submission_id == ans.submission_id) |> select( [sv, ans], - %{ans_id: ans.id, rank: sv.rank, ans: ans.answer["code"]} + %{ans_id: ans.id, score: sv.score, ans: ans.answer["code"]} ) |> Repo.all() @@ -1060,15 +1060,14 @@ defmodule Cadet.Assessments do defp map_eligible_votes_to_entry_score(eligible_votes) do # converts eligible votes to the {total cumulative score, number of votes, tokens} entry_vote_data = - Enum.reduce(eligible_votes, %{}, fn %{ans_id: ans_id, rank: rank, ans: ans}, tracker -> + Enum.reduce(eligible_votes, %{}, fn %{ans_id: ans_id, score: score, ans: ans}, tracker -> {prev_score, prev_count, _ans_tokens} = Map.get(tracker, ans_id, {0, 0, 0}) Map.put( tracker, ans_id, # assume each voter is assigned 10 entries which will make it fair. - {prev_score + convert_vote_rank_to_score(rank, 10), prev_count + 1, - Lexer.count_tokens(ans)} + {prev_score + score, prev_count + 1, Lexer.count_tokens(ans)} ) end) @@ -1081,11 +1080,6 @@ defmodule Cadet.Assessments do ) end - # implementation detail assuming to calculate scores out of 10 for rank [1, num_voted_entries] - defp convert_vote_rank_to_score(rank, num_voted_entries) do - 11 - 10 * rank / num_voted_entries - end - # Calculate the score based on formula # score(v,t) = v - 2^(t/50) where v is the normalized_voting_score # normalized_voting_score = sum_of_scores / number_of_voters / 10 * 100 @@ -1549,13 +1543,13 @@ defmodule Cadet.Assessments do end def insert_or_update_voting_answer(submission_id, course_reg_id, question_id, answer_content) do - set_rank_to_nil = + set_score_to_nil = SubmissionVotes |> where(voter_id: ^course_reg_id, question_id: ^question_id) voting_multi = Multi.new() - |> Multi.update_all(:set_rank_to_nil, set_rank_to_nil, set: [rank: nil]) + |> Multi.update_all(:set_score_to_nil, set_score_to_nil, set: [score: nil]) answer_content |> Enum.with_index(1) @@ -1567,7 +1561,7 @@ defmodule Cadet.Assessments do voter_id: course_reg_id, submission_id: entry.submission_id ) - |> SubmissionVotes.changeset(%{rank: entry.rank}) + |> SubmissionVotes.changeset(%{score: entry.score}) |> Repo.insert_or_update() end) end) diff --git a/lib/cadet/assessments/submission_votes.ex b/lib/cadet/assessments/submission_votes.ex index 1a010264c..addd8b824 100644 --- a/lib/cadet/assessments/submission_votes.ex +++ b/lib/cadet/assessments/submission_votes.ex @@ -6,7 +6,7 @@ defmodule Cadet.Assessments.SubmissionVotes do alias Cadet.Assessments.{Question, Submission} schema "submission_votes" do - field(:rank, :integer) + field(:score, :integer) belongs_to(:voter, CourseRegistration) belongs_to(:submission, Submission) @@ -15,7 +15,7 @@ defmodule Cadet.Assessments.SubmissionVotes do end @required_fields ~w(voter_id submission_id question_id)a - @optional_fields ~w(rank)a + @optional_fields ~w(score)a def changeset(submission_vote, params) do submission_vote diff --git a/lib/cadet/jobs/autograder/grading_job.ex b/lib/cadet/jobs/autograder/grading_job.ex index 7083a9b0b..89afb69ba 100644 --- a/lib/cadet/jobs/autograder/grading_job.ex +++ b/lib/cadet/jobs/autograder/grading_job.ex @@ -141,7 +141,7 @@ defmodule Cadet.Autograder.GradingJob do |> join(:inner, [s], sv in SubmissionVotes, on: sv.voter_id == s.student_id and sv.question_id == ^question.id ) - |> where([_, sv], is_nil(sv.rank)) + |> where([_, sv], is_nil(sv.score)) |> Repo.exists?() xp = if is_nil_entries, do: 0, else: question.max_xp diff --git a/lib/cadet_web/views/assessments_helpers.ex b/lib/cadet_web/views/assessments_helpers.ex index f534a9f3b..bbe4c0cee 100644 --- a/lib/cadet_web/views/assessments_helpers.ex +++ b/lib/cadet_web/views/assessments_helpers.ex @@ -129,7 +129,7 @@ defmodule CadetWeb.AssessmentsHelpers do transform_map_for_view(entry, %{ submission_id: :submission_id, answer: :answer, - rank: :rank + score: :score }) end @@ -140,7 +140,7 @@ defmodule CadetWeb.AssessmentsHelpers do answer: :answer, student_name: :student_name }), - "score", + "final_score", Float.round(leaderboard_ans.relative_score, 2) ) end diff --git a/priv/repo/migrations/20210908024720_rename_rank_to_score.exs b/priv/repo/migrations/20210908024720_rename_rank_to_score.exs new file mode 100644 index 000000000..5c5cd8292 --- /dev/null +++ b/priv/repo/migrations/20210908024720_rename_rank_to_score.exs @@ -0,0 +1,7 @@ +defmodule Cadet.Repo.Migrations.RenameRankToScore do + use Ecto.Migration + + def change do + rename(table(:submission_votes), :rank, to: :score) + end +end diff --git a/test/cadet/assessments/assessments_test.exs b/test/cadet/assessments/assessments_test.exs index da2c77a5e..acfe5e738 100644 --- a/test/cadet/assessments/assessments_test.exs +++ b/test/cadet/assessments/assessments_test.exs @@ -301,7 +301,7 @@ defmodule Cadet.AssessmentsTest do fn {submission, index} -> insert( :submission_vote, - rank: index + 1, + score: 10 - index, voter: student, submission: submission, question: voting_question @@ -466,7 +466,7 @@ defmodule Cadet.AssessmentsTest do fn {submission, index} -> insert( :submission_vote, - rank: index + 1, + score: 10 - index, voter: student, submission: submission, question: current_question @@ -485,7 +485,7 @@ defmodule Cadet.AssessmentsTest do fn {submission, index} -> insert( :submission_vote, - rank: index + 1, + score: 10 - index, voter: student, submission: submission, question: yesterday_question @@ -504,7 +504,7 @@ defmodule Cadet.AssessmentsTest do fn {submission, index} -> insert( :submission_vote, - rank: index + 1, + score: 10 - index, voter: student, submission: submission, question: past_question diff --git a/test/cadet/assessments/submission_votes_test.exs b/test/cadet/assessments/submission_votes_test.exs index 3840436c2..c91465dfb 100644 --- a/test/cadet/assessments/submission_votes_test.exs +++ b/test/cadet/assessments/submission_votes_test.exs @@ -64,7 +64,7 @@ defmodule Cadet.Assessments.SubmissionVotesTest do test "invalid changeset unique constraint", %{ valid_params: params } do - params = Map.put(params, :rank, 2) + params = Map.put(params, :score, 2) first_entry = SubmissionVotes.changeset(%SubmissionVotes{}, params) {:ok, _} = Repo.insert(first_entry) new_submission = insert(:submission) diff --git a/test/cadet/jobs/autograder/grading_job_test.exs b/test/cadet/jobs/autograder/grading_job_test.exs index 27ca0b66d..eaac9903e 100644 --- a/test/cadet/jobs/autograder/grading_job_test.exs +++ b/test/cadet/jobs/autograder/grading_job_test.exs @@ -586,7 +586,7 @@ defmodule Cadet.Autograder.GradingJobTest do answers = for question <- questions do case Enum.random(0..1) do - 0 -> insert(:submission_vote, %{voter: student, question: question, rank: 1}) + 0 -> insert(:submission_vote, %{voter: student, question: question, score: 1}) 1 -> insert(:submission_vote, %{voter: student, question: question}) end @@ -614,7 +614,7 @@ defmodule Cadet.Autograder.GradingJobTest do SubmissionVotes |> where(voter_id: ^student.id) |> where(question_id: ^question.id) - |> where([sv], is_nil(sv.rank)) + |> where([sv], is_nil(sv.score)) |> Repo.exists?() answer_db = Repo.get(Answer, answer.id) diff --git a/test/cadet_web/controllers/answer_controller_test.exs b/test/cadet_web/controllers/answer_controller_test.exs index 4bd8c8162..9a9f199d9 100644 --- a/test/cadet_web/controllers/answer_controller_test.exs +++ b/test/cadet_web/controllers/answer_controller_test.exs @@ -70,13 +70,13 @@ defmodule CadetWeb.AnswerControllerTest do voting_conn = post(conn, build_url(course_id, voting_question.id), %{ answer: [ - %{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 3} + %{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 3} ] }) assert response(voting_conn, 200) =~ "OK" - rank = get_rank_for_submission_vote(voting_question, course_reg, contest_submission) - assert rank == 3 + score = get_score_for_submission_vote(voting_question, course_reg, contest_submission) + assert score == 3 end @tag authenticate: role @@ -120,7 +120,7 @@ defmodule CadetWeb.AnswerControllerTest do voting_conn = post(conn, build_url(course_id, voting_question.id), %{ answer: [ - %{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 3} + %{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 3} ] }) @@ -129,14 +129,14 @@ defmodule CadetWeb.AnswerControllerTest do updated_voting_conn = post(conn, build_url(course_id, voting_question.id), %{ answer: [ - %{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 5} + %{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 5} ] }) assert response(updated_voting_conn, 200) =~ "OK" - rank = get_rank_for_submission_vote(voting_question, course_reg, contest_submission) - assert rank == 5 + score = get_score_for_submission_vote(voting_question, course_reg, contest_submission) + assert score == 5 end @tag authenticate: role @@ -161,7 +161,7 @@ defmodule CadetWeb.AnswerControllerTest do post(conn, build_url(course_id, voting_question.id), %{ answer: [ - %{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 3} + %{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 3} ] }) @@ -253,7 +253,7 @@ defmodule CadetWeb.AnswerControllerTest do %{ "answer" => "hello world", "submission_id" => contest_submission.id, - "rank" => "a" + "score" => "a" } ] }) @@ -263,7 +263,7 @@ defmodule CadetWeb.AnswerControllerTest do end @tag authenticate: role - test "update duplicate rank in submission_votes is unsuccessful", %{ + test "update duplicate score in submission_votes is unsuccessful", %{ conn: conn, voting_question: voting_question } do @@ -277,14 +277,14 @@ defmodule CadetWeb.AnswerControllerTest do voter_id: course_reg.id, question_id: voting_question.id, submission_id: first_contest_submission.id, - rank: 1 + score: 1 }) Repo.insert(%SubmissionVotes{ voter_id: course_reg.id, question_id: voting_question.id, submission_id: second_contest_submission.id, - rank: 2 + score: 2 }) voting_conn = @@ -293,12 +293,12 @@ defmodule CadetWeb.AnswerControllerTest do %{ "answer" => "hello world", "submission_id" => first_contest_submission.id, - "rank" => 3 + "score" => 3 }, %{ "answer" => "hello world", "submission_id" => second_contest_submission.id, - "rank" => 3 + "score" => 3 } ] }) @@ -393,12 +393,12 @@ defmodule CadetWeb.AnswerControllerTest do end end - defp get_rank_for_submission_vote(question, course_reg, submission) do + defp get_score_for_submission_vote(question, course_reg, submission) do SubmissionVotes |> where(question_id: ^question.id) |> where(voter_id: ^course_reg.id) |> where(submission_id: ^submission.id) - |> select([sv], sv.rank) + |> select([sv], sv.score) |> Repo.one() end end diff --git a/test/cadet_web/controllers/assessments_controller_test.exs b/test/cadet_web/controllers/assessments_controller_test.exs index c19f154f3..403e88ebd 100644 --- a/test/cadet_web/controllers/assessments_controller_test.exs +++ b/test/cadet_web/controllers/assessments_controller_test.exs @@ -435,7 +435,7 @@ defmodule CadetWeb.AssessmentsControllerTest do %{ "submission_id" => answer.submission.id, "answer" => %{"code" => answer.answer.code}, - "rank" => nil + "score" => nil } end) end)