Skip to content

Commit 277554a

Browse files
authored
Remove rank from contest voting (#823)
* Remove rank from contest voting * Rename relative_score to final_score
1 parent c7478b5 commit 277554a

File tree

10 files changed

+46
-45
lines changed

10 files changed

+46
-45
lines changed

lib/cadet/assessments/assessments.ex

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ defmodule Cadet.Assessments do
876876
SubmissionVotes
877877
|> where(question_id: ^question.id)
878878
|> where(voter_id: ^submission.student_id)
879-
|> where([sv], is_nil(sv.rank))
879+
|> where([sv], is_nil(sv.score))
880880
|> Repo.exists?()
881881

882882
unless has_nil_entries do
@@ -921,7 +921,7 @@ defmodule Cadet.Assessments do
921921
|> where([v], v.voter_id == ^voter_id and v.question_id == ^question_id)
922922
|> join(:inner, [v], s in assoc(v, :submission))
923923
|> join(:inner, [v, s], a in assoc(s, :answers))
924-
|> select([v, s, a], %{submission_id: v.submission_id, answer: a.answer, rank: v.rank})
924+
|> select([v, s, a], %{submission_id: v.submission_id, answer: a.answer, score: v.score})
925925
|> Repo.all()
926926
end
927927

@@ -1026,17 +1026,17 @@ defmodule Cadet.Assessments do
10261026
"""
10271027
def compute_relative_score(contest_voting_question_id) do
10281028
# query all records from submission votes tied to the question id ->
1029-
# map rank to user id ->
1029+
# map score to user id ->
10301030
# store as grade ->
10311031
# query grade for contest question id.
10321032
eligible_votes =
10331033
SubmissionVotes
10341034
|> where(question_id: ^contest_voting_question_id)
1035-
|> where([sv], not is_nil(sv.rank))
1035+
|> where([sv], not is_nil(sv.score))
10361036
|> join(:inner, [sv], ans in Answer, on: sv.submission_id == ans.submission_id)
10371037
|> select(
10381038
[sv, ans],
1039-
%{ans_id: ans.id, rank: sv.rank, ans: ans.answer["code"]}
1039+
%{ans_id: ans.id, score: sv.score, ans: ans.answer["code"]}
10401040
)
10411041
|> Repo.all()
10421042

@@ -1060,15 +1060,14 @@ defmodule Cadet.Assessments do
10601060
defp map_eligible_votes_to_entry_score(eligible_votes) do
10611061
# converts eligible votes to the {total cumulative score, number of votes, tokens}
10621062
entry_vote_data =
1063-
Enum.reduce(eligible_votes, %{}, fn %{ans_id: ans_id, rank: rank, ans: ans}, tracker ->
1063+
Enum.reduce(eligible_votes, %{}, fn %{ans_id: ans_id, score: score, ans: ans}, tracker ->
10641064
{prev_score, prev_count, _ans_tokens} = Map.get(tracker, ans_id, {0, 0, 0})
10651065

10661066
Map.put(
10671067
tracker,
10681068
ans_id,
10691069
# assume each voter is assigned 10 entries which will make it fair.
1070-
{prev_score + convert_vote_rank_to_score(rank, 10), prev_count + 1,
1071-
Lexer.count_tokens(ans)}
1070+
{prev_score + score, prev_count + 1, Lexer.count_tokens(ans)}
10721071
)
10731072
end)
10741073

@@ -1081,11 +1080,6 @@ defmodule Cadet.Assessments do
10811080
)
10821081
end
10831082

1084-
# implementation detail assuming to calculate scores out of 10 for rank [1, num_voted_entries]
1085-
defp convert_vote_rank_to_score(rank, num_voted_entries) do
1086-
11 - 10 * rank / num_voted_entries
1087-
end
1088-
10891083
# Calculate the score based on formula
10901084
# score(v,t) = v - 2^(t/50) where v is the normalized_voting_score
10911085
# normalized_voting_score = sum_of_scores / number_of_voters / 10 * 100
@@ -1549,13 +1543,13 @@ defmodule Cadet.Assessments do
15491543
end
15501544

15511545
def insert_or_update_voting_answer(submission_id, course_reg_id, question_id, answer_content) do
1552-
set_rank_to_nil =
1546+
set_score_to_nil =
15531547
SubmissionVotes
15541548
|> where(voter_id: ^course_reg_id, question_id: ^question_id)
15551549

15561550
voting_multi =
15571551
Multi.new()
1558-
|> Multi.update_all(:set_rank_to_nil, set_rank_to_nil, set: [rank: nil])
1552+
|> Multi.update_all(:set_score_to_nil, set_score_to_nil, set: [score: nil])
15591553

15601554
answer_content
15611555
|> Enum.with_index(1)
@@ -1567,7 +1561,7 @@ defmodule Cadet.Assessments do
15671561
voter_id: course_reg_id,
15681562
submission_id: entry.submission_id
15691563
)
1570-
|> SubmissionVotes.changeset(%{rank: entry.rank})
1564+
|> SubmissionVotes.changeset(%{score: entry.score})
15711565
|> Repo.insert_or_update()
15721566
end)
15731567
end)

lib/cadet/assessments/submission_votes.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Cadet.Assessments.SubmissionVotes do
66
alias Cadet.Assessments.{Question, Submission}
77

88
schema "submission_votes" do
9-
field(:rank, :integer)
9+
field(:score, :integer)
1010

1111
belongs_to(:voter, CourseRegistration)
1212
belongs_to(:submission, Submission)
@@ -15,7 +15,7 @@ defmodule Cadet.Assessments.SubmissionVotes do
1515
end
1616

1717
@required_fields ~w(voter_id submission_id question_id)a
18-
@optional_fields ~w(rank)a
18+
@optional_fields ~w(score)a
1919

2020
def changeset(submission_vote, params) do
2121
submission_vote

lib/cadet/jobs/autograder/grading_job.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ defmodule Cadet.Autograder.GradingJob do
141141
|> join(:inner, [s], sv in SubmissionVotes,
142142
on: sv.voter_id == s.student_id and sv.question_id == ^question.id
143143
)
144-
|> where([_, sv], is_nil(sv.rank))
144+
|> where([_, sv], is_nil(sv.score))
145145
|> Repo.exists?()
146146

147147
xp = if is_nil_entries, do: 0, else: question.max_xp

lib/cadet_web/views/assessments_helpers.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ defmodule CadetWeb.AssessmentsHelpers do
129129
transform_map_for_view(entry, %{
130130
submission_id: :submission_id,
131131
answer: :answer,
132-
rank: :rank
132+
score: :score
133133
})
134134
end
135135

@@ -140,7 +140,7 @@ defmodule CadetWeb.AssessmentsHelpers do
140140
answer: :answer,
141141
student_name: :student_name
142142
}),
143-
"score",
143+
"final_score",
144144
Float.round(leaderboard_ans.relative_score, 2)
145145
)
146146
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Cadet.Repo.Migrations.RenameRankToScore do
2+
use Ecto.Migration
3+
4+
def change do
5+
rename(table(:submission_votes), :rank, to: :score)
6+
end
7+
end

test/cadet/assessments/assessments_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ defmodule Cadet.AssessmentsTest do
301301
fn {submission, index} ->
302302
insert(
303303
:submission_vote,
304-
rank: index + 1,
304+
score: 10 - index,
305305
voter: student,
306306
submission: submission,
307307
question: voting_question
@@ -466,7 +466,7 @@ defmodule Cadet.AssessmentsTest do
466466
fn {submission, index} ->
467467
insert(
468468
:submission_vote,
469-
rank: index + 1,
469+
score: 10 - index,
470470
voter: student,
471471
submission: submission,
472472
question: current_question
@@ -485,7 +485,7 @@ defmodule Cadet.AssessmentsTest do
485485
fn {submission, index} ->
486486
insert(
487487
:submission_vote,
488-
rank: index + 1,
488+
score: 10 - index,
489489
voter: student,
490490
submission: submission,
491491
question: yesterday_question
@@ -504,7 +504,7 @@ defmodule Cadet.AssessmentsTest do
504504
fn {submission, index} ->
505505
insert(
506506
:submission_vote,
507-
rank: index + 1,
507+
score: 10 - index,
508508
voter: student,
509509
submission: submission,
510510
question: past_question

test/cadet/assessments/submission_votes_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ defmodule Cadet.Assessments.SubmissionVotesTest do
6464
test "invalid changeset unique constraint", %{
6565
valid_params: params
6666
} do
67-
params = Map.put(params, :rank, 2)
67+
params = Map.put(params, :score, 2)
6868
first_entry = SubmissionVotes.changeset(%SubmissionVotes{}, params)
6969
{:ok, _} = Repo.insert(first_entry)
7070
new_submission = insert(:submission)

test/cadet/jobs/autograder/grading_job_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ defmodule Cadet.Autograder.GradingJobTest do
586586
answers =
587587
for question <- questions do
588588
case Enum.random(0..1) do
589-
0 -> insert(:submission_vote, %{voter: student, question: question, rank: 1})
589+
0 -> insert(:submission_vote, %{voter: student, question: question, score: 1})
590590
1 -> insert(:submission_vote, %{voter: student, question: question})
591591
end
592592

@@ -614,7 +614,7 @@ defmodule Cadet.Autograder.GradingJobTest do
614614
SubmissionVotes
615615
|> where(voter_id: ^student.id)
616616
|> where(question_id: ^question.id)
617-
|> where([sv], is_nil(sv.rank))
617+
|> where([sv], is_nil(sv.score))
618618
|> Repo.exists?()
619619

620620
answer_db = Repo.get(Answer, answer.id)

test/cadet_web/controllers/answer_controller_test.exs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ defmodule CadetWeb.AnswerControllerTest do
7070
voting_conn =
7171
post(conn, build_url(course_id, voting_question.id), %{
7272
answer: [
73-
%{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 3}
73+
%{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 3}
7474
]
7575
})
7676

7777
assert response(voting_conn, 200) =~ "OK"
78-
rank = get_rank_for_submission_vote(voting_question, course_reg, contest_submission)
79-
assert rank == 3
78+
score = get_score_for_submission_vote(voting_question, course_reg, contest_submission)
79+
assert score == 3
8080
end
8181

8282
@tag authenticate: role
@@ -120,7 +120,7 @@ defmodule CadetWeb.AnswerControllerTest do
120120
voting_conn =
121121
post(conn, build_url(course_id, voting_question.id), %{
122122
answer: [
123-
%{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 3}
123+
%{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 3}
124124
]
125125
})
126126

@@ -129,14 +129,14 @@ defmodule CadetWeb.AnswerControllerTest do
129129
updated_voting_conn =
130130
post(conn, build_url(course_id, voting_question.id), %{
131131
answer: [
132-
%{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 5}
132+
%{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 5}
133133
]
134134
})
135135

136136
assert response(updated_voting_conn, 200) =~ "OK"
137137

138-
rank = get_rank_for_submission_vote(voting_question, course_reg, contest_submission)
139-
assert rank == 5
138+
score = get_score_for_submission_vote(voting_question, course_reg, contest_submission)
139+
assert score == 5
140140
end
141141

142142
@tag authenticate: role
@@ -161,7 +161,7 @@ defmodule CadetWeb.AnswerControllerTest do
161161

162162
post(conn, build_url(course_id, voting_question.id), %{
163163
answer: [
164-
%{"answer" => "hello world", "submission_id" => contest_submission.id, "rank" => 3}
164+
%{"answer" => "hello world", "submission_id" => contest_submission.id, "score" => 3}
165165
]
166166
})
167167

@@ -253,7 +253,7 @@ defmodule CadetWeb.AnswerControllerTest do
253253
%{
254254
"answer" => "hello world",
255255
"submission_id" => contest_submission.id,
256-
"rank" => "a"
256+
"score" => "a"
257257
}
258258
]
259259
})
@@ -263,7 +263,7 @@ defmodule CadetWeb.AnswerControllerTest do
263263
end
264264

265265
@tag authenticate: role
266-
test "update duplicate rank in submission_votes is unsuccessful", %{
266+
test "update duplicate score in submission_votes is unsuccessful", %{
267267
conn: conn,
268268
voting_question: voting_question
269269
} do
@@ -277,14 +277,14 @@ defmodule CadetWeb.AnswerControllerTest do
277277
voter_id: course_reg.id,
278278
question_id: voting_question.id,
279279
submission_id: first_contest_submission.id,
280-
rank: 1
280+
score: 1
281281
})
282282

283283
Repo.insert(%SubmissionVotes{
284284
voter_id: course_reg.id,
285285
question_id: voting_question.id,
286286
submission_id: second_contest_submission.id,
287-
rank: 2
287+
score: 2
288288
})
289289

290290
voting_conn =
@@ -293,12 +293,12 @@ defmodule CadetWeb.AnswerControllerTest do
293293
%{
294294
"answer" => "hello world",
295295
"submission_id" => first_contest_submission.id,
296-
"rank" => 3
296+
"score" => 3
297297
},
298298
%{
299299
"answer" => "hello world",
300300
"submission_id" => second_contest_submission.id,
301-
"rank" => 3
301+
"score" => 3
302302
}
303303
]
304304
})
@@ -393,12 +393,12 @@ defmodule CadetWeb.AnswerControllerTest do
393393
end
394394
end
395395

396-
defp get_rank_for_submission_vote(question, course_reg, submission) do
396+
defp get_score_for_submission_vote(question, course_reg, submission) do
397397
SubmissionVotes
398398
|> where(question_id: ^question.id)
399399
|> where(voter_id: ^course_reg.id)
400400
|> where(submission_id: ^submission.id)
401-
|> select([sv], sv.rank)
401+
|> select([sv], sv.score)
402402
|> Repo.one()
403403
end
404404
end

test/cadet_web/controllers/assessments_controller_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ defmodule CadetWeb.AssessmentsControllerTest do
435435
%{
436436
"submission_id" => answer.submission.id,
437437
"answer" => %{"code" => answer.answer.code},
438-
"rank" => nil
438+
"score" => nil
439439
}
440440
end)
441441
end)

0 commit comments

Comments
 (0)